본문 바로가기

오라클 86기

2024.12.27 7일차 복습)declare type id_type is table of number; v_id id_type := id_type(); -- 배열의 뼈대만 있는 것begin v_id.extend(10); for i in 1..10 loop v_id(i) := i * 10; dbms_output.put_line(v_id(i)); end loop;end;/ declare type id_type is table of number; v_id id_type; --v_id id_type := id_type(); -- 배열의 뼈대만 있는 것begin for i in 1..10 loop v_id.extend; v_id(i) := i * .. 더보기
2024.12.26 6일차 복습)declare type rec_type is record(a varchar2(30), b date, c varchar2(30), d varchar2(30)); type tab_type is table of rec_type index by pls_integer; v_tab tab_type; type id_type is table of number index by pls_integer; v_id id_type;begin v_id(1):= 100; v_id(2) := 155; v_id(3) := 201; for i in v_id.first..v_id.last loop select e.first_name, e.hire_date, d.. 더보기
2024.12.24 PL/SQL 5일차 ■ 연관배열 (associative array, index by table)   - 2개의 열을 포함하는 collection 이다.   - key-value 집합으로 구성되어 있다.   - key : 정수(pls_integer(-2g ~ 2g)) 또는 문자열(varchar(65536)) 데이터 유형의 primary key(unique, not null)   - values : 스칼라, 레코드 데이터 유형 ex)declare type tab_char_type is table of varchar2(10) index by pls_integer; v_city tab_char_type; -- 바로 위에 타입으로 구성하겠다는 뜻begin v_city(1) := '서울'; -- 키값을 1번으로 설.. 더보기
2024.12.23 PL/SQL 4일차 복습)desc hr.employees;declare    v_name varchar2(30); -- hard coding (변화되지 않은(크기) 케이스로 코딩)    v_sal number;begin    select last_name, salary    into v_name, v_sal    from hr.employees    where employee_id = 100;    dbms_output.put_line(v_name||' '||v_sal);end;/▶ 변수를 선언할 때 꼭 타입을 맞추는 습관을 가지자.▶ 변수 설정하기 전에 desc hr.employees;로 테이블 변수 어떤 타입인지 확인해 보기 ex)desc hr.employees;declare    v_name hr.employees.l.. 더보기
2024.12.20 PL/SQL 3일차 문제 1) 화면과 같이 출력해 주세요.10987654321# 내 답declare v_num number := 10;begin Loop dbms_output.put_line(v_num); if v_num = 1 then exit; end if; v_num := v_num - 1; end loop;end;/# 강사님 답declare v_num number := 10;begin Loop dbms_output.put_line(v_num); V_num := v_num - 1; exit when v_num = 0; end loop;end;/문제 2)  2단을 출력.. 더보기
2024.12.19 PL/SQL 2일차 복습)>DECLARE v_sal number(8,2) := 60000; v_comm number(8,2) := v_sal * 0.2; v_message varchar2(60) := 'eligible for commission';BEGIN DECLARE v_sal number(8,2) := 50000; v_comm number(8,2) := 0; v_total number(8,2) := v_sal + v_comm; BEGIN v_message := 'Clerk not '||v_message; outer.v_comm := v_sal * 0.3; dbms_output.put_line('****sub block.. 더보기
2024.12.18 PL/SQL 시작 ※ SQL : 데이터를 유일하게 엑세스 할 수 있는 것 ex) 문장 튜닝 맛보기select * from hr.employees where employee_id = 100;select * from hr.employees where employee_id = 101;select * from hr.employees where employee_id = 102;select * from hr.employees where employee_id = 103;▶ 코드에 찾는 값은 다르지만 실행계획은 다 같은 걸 볼 수 있다. 왜냐하면 코드는 같고 출력 결과를 보면 전체 중에 하나를 출력하는 거기 때문이다. select * from v$sql where sql_text like '%hr.employees%'and sql_te.. 더보기
2024.12.17 14일차 수업 ex) 어제 이어서 함create table hr.dept(            dept_id number constraint dept_pk primary key,            dept_name varchar2(30) constraint dept_name_uk unique)tablespace users;create table hr.emp(            id number,            name varchar2(30) constraint emp_name_nn not null,            sal number,            dept_id number,            constraint emp_id_pk primary key(id),            constrain.. 더보기