Programming/Oracle2015. 11. 3. 10:24


PL/SQL에서 EXECUTE IMMEDIATE를 사용하여 동적으로 쿼리를 생성하여 수행할수 있다.


DECLARE


v_date DATE;

v_query VARCHAR2(100);

v_tmp VARCHAR2(100);


BEGIN


v_query := 'SELECT SYSDATE' || 

           ' FROM DUAL' ;


EXECUTE IMMEDIATE v_query INTO v_date ;


DBMS_OUTPUT.PUT_LINE('1:' || v_date);


v_tmp := 'DUAL';

v_query := 'SELECT SYSDATE' || 

           ' FROM ' || v_tmp ;


EXECUTE IMMEDIATE v_query INTO v_date ;


DBMS_OUTPUT.PUT_LINE('2:' ||v_date);



END;

Posted by jvvj