본문 바로가기

전체 글

(607)
072 - [Oracle PL/SQL] RESULT_CACHE hint --1 Cache and parallel are only in oracle enterprise editions --also the DBA make changes in these values --parameter shared_pool_size --parameter result_cache_max_size --parameter result_cache_mode create or replace function get_sum_sal_dept ( dept_id number ) return number result_cache is v_sal number; begin select sum(salary) into v_sal from employees where department_id =dept_id; return v_sa..
070 - [Oracle PL/SQL] NOCOPY - 성능차이. 값 전달과 레퍼런스 전달의 속도 차이를 테스트해보자. create or replace package nocopy_test is type number_t is table of varchar2(20) index by binary_integer; procedure pass_by_vale(nums in out number_t); procedure pass_by_refernce(nums in out nocopy number_t); procedure init; end; / ------------ create or replace package body nocopy_test is l_numbers number_t; c_array_size number:=1000000; c_it number:=20; procedure p..
069 - [Oracle PL/SQL] NOCOPY 예외상황 # nocopy will have no effects # case 1 create or replace procedure pass_by_value3 ( P_id IN out nocopy number) is begin P_id:=P_id*10; if P_id>100 then raise VALUE_ERROR; end if; end; / # 값에 사이즈를 지정하면 nocopy 옵션이 동작하지 않는다 declare --if the actual has size(FOR NUMBER ONLY ),nocopy not working v number(10):=20; begin pass_by_value3(V); dbms_output.put_line('NO ISSUE '||v); EXCEPTION WHEN VALUE_ERROR..
068 - [Oracle PL/SQL] NOCOPY We use NOCOPY in complexe data types (LOBs, XMLTYPEs, collections etc.) 여기서 레퍼런스에 의한 전달과 값에 의한 전달의 차이를 알아보자 IN parameter always passed by reference, IN 파라미터는 항상 레퍼런스에 의한 전달이다 OUT/IN OUT parameters can be passed 1-Pass By Value ( default), 파라미터의 사이즈가 작다면 문제가 없지만 크다면 복사하는 과정에서 많은 부하가 발생한다. 값의 전달은, 오류가 발생할때, 프로시져에 전달한 값이 무엇인지 알고 롤백을 할때도 값을 유지한다. 2-Pass By Reference using no copy, 복사 과정이 일어나지 않아서 실행..
067 - [Oracle PL/SQL] AUTONOMOUS TRANSACTION 블록간 구분이 없어서 subprogram 에서 실행한 commit 이 main procedure 에 영향을 미치는 샘플 코드 #case one without using PRAGMA AUTONOMOUS_TRANSACTION drop table t; # hr 사용자 세션에서 실행 CREATE TABLE t (test_value VARCHAR2(25)); / CREATE OR REPLACE PROCEDURE child_block IS BEGIN INSERT INTO t(test_value) VALUES ('Child block insert'); COMMIT; END child_block; / CREATE OR REPLACE PROCEDURE parent_block IS BEGIN INSERT INTO t(te..
066 - [Oracle PL/SQL] Design - Definer's right, Invoker's rights Definer's rights 무슨 의미인지 샘플 코드를 통해서 확인 # 테스트를 위한 준비과정 # hr 사용자로 디비 접속해서 테이블 생성. create table hr_table ( id number, name varchar2(100) ); /* Table HR_TABLE created. */ create or replace procedure add_hr_table ( p_id number, p_name varchar2 ) is begin insert into hr_table values (p_id,p_name); end; /* Procedure ADD_HR_TABLE compiled */ # 여기부터는 sys 사용자로 접속하여 실행 --now conn as sys as sysdba and creat..
065 - [Oracle PL/SQL] Design - Standardizing 에러처리를 고급스럽게 처리하는 방법, 샘플코드, 사용자 정의 오류와 오라클 표준 에러를 동시에 처리하는 방법 delete from DEPARTMENTS /* Error report - ORA-02292: integrity constraint (HR.EMP_DEPT_FK) violated - child record found */ declare e_fk_err exception; pragma EXCEPTION_INIT (e_fk_err, -02292); begin delete from DEPARTMENTS; exception when e_fk_err then RAISE_APPLICATION_ERROR (-20001, 'error'); end; /* Error report - ORA-20001: error ..
064 - [Oracle PL/SQL] Dynamic SQL - DBMS_SQL Package VS Execute immediate 다이나믹 SQL을 구현하는 방법은 다양하다, 아래 방법중에 편한 방법을 사용하면 된다. 테스트용 테이블을 아래와 같이 준비 drop table emp1; create table emp1 ( emp_id number ); drop table emp2; create table emp2 ( emp_id number ); begin insert into emp1 values (1); insert into emp1 values (2); insert into emp1 values (3); insert into emp2 values (1); insert into emp2 values (2); insert into emp2 values (3); commit; end; select * from emp1; select *..