DBA 썸네일형 리스트형 2025.01.07 PL/SQL 13일차 ■ 패키지 변수 초기화, one time only (에누리 없이 한 번만 사용) - Package Body 끝에 있는 블록(BEGIN)은 한 번 실행되며 public, private 패키지 변수를 초기화하는 데 사용된다. - 변수에 초기화된 값은 세션이 열려있는 동안에 지속적으로 사용한다. - 중간에 변경되더라도 변경된 값은 사용하지 않는다. - 커서의 지속상태와 같은 개념이라 생각하면 된다. ex) - 샘플 테이블 생성create table hr.tax_rates(rate_name varchar2(30), rate_value number, rate_date date); - 값 넣기insert into hr.tax_rates(rate_name, rate_value, rate_date)value.. 더보기 2025.01.06 PL/SQL 12일차 복습)# DML 문장 트리거 - DML 문장 트리거는 영향을 받는 행이 전혀 없더라도 문장 트리거는 한 번 실행된다. - 특정 요일과 시간을 제한을 주고 싶을 땐 문장 트리거를 많이 쓴다. # DML 행 트리거 - DML 행 트리거는 영향을 받는 행이 없을 경우에는 트리거가 수행되지 않는다. - 영향을 받은 각 행에 대해서 트리거는 수행된다. - FOR EACH ROW 절을 사용해야 한다. - CHECK 제약조건으로 안 되는 CHECK 제약조건을 만들고 싶을 때 행 트리거로 많이 구현한다. ex) DML 행 트리거 - 간단 테이블 생성create table hr.empasselect employee_id id, salary sal, job_id job, department_id dept_i.. 더보기 2025.01.03 PL/SQL 11일차 ■ 상수 표준화 (값이 변하지 않고 정해져 있는 값) ex) 1 mile = 1.6093 km 1 kilo = 0.6214 mile 1 yard = 0.9144 meter 1 meter = 1.0936 yard ※ body없는 spec은 존재하지만 spec없는 body는 존재하지 않는다. ex) create or replace package hr.global_contsis c_mile_2_kilo constant number := 1.6093; c_kilo_2_mile constant number := 0.6214; c_yard_2_meter constant number := 0.9144; c_meter_2_yard constant number := .. 더보기 2025.01.02 PL/SQL 10일차 create or replace package body hr.comm_pkgis procedure reset_comm(p_comm in number) is begin if validate_comm(p_comm) then dbms_output.put_line('old : '||g_comm); g_comm := p_comm; dbms_output.put_line('New : '||g_comm); else raise_application_error(-20000, '기존 최고값을 넘을 수 없습니다.'); end if; end reset_comm; function .. 더보기 2024.12.31 PL/SQL 9일차 # 신규 부서정보를 입력하는 프로시저select max(department_id)into 마지막부서 코드 변수from hr.dept;insert into hr.dept(department_id, department_name, manager_id, location_id)values(마지막 부서코드 + 10, 입력변수, 입력변수, 입력변수);create or replace procedure hr.add_dept(p_name in varchar2, p_mgr in number, p_loc in number)is v_max number;begin select max(department_id) into v_max from hr.dept; insert into hr.dept(departm.. 더보기 2024.12.30 PL/SQL 8일차 복습) 사원번호를 입력값으로 받아서 그 사원의 정보를 출력하는 프로그램var b_id numberdeclare v_rec hr.employees%rowtype;begin select * into v_rec from hr.employees where employee_id = :b_id; dbms_output.put_line(v_rec.employee_id||'번 사원 '||v_rec.first_name);exception when no_data_found then dbms_output.put_line(:b_id||'번 사원은 존재하지 않습니다.'); when others then dbms_output.put_line(sqlerrm);end;/▶ .. 더보기 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.. 더보기 이전 1 2 3 4 5 6 7 다음