- execute immediate:动态解析sql语句
CREATE OR REPLACE PROCEDURE PRO_test() IS V_sql VARCHAR2(2000) := ''; V_NUM NUMBER; BEGIN --EXECUTE IMMEDIATE用法1:立刻执行 V_sql := 'create or replace view mytest as select employee_id, first_name from employees'; EXECUTE IMMEDIATE V_sql; --EXECUTE IMMEDIATE用法2:立刻执行,并赋值给某变量 V_sql := 'select count(1) from employees'; EXECUTE IMMEDIATE V_sql; INTO V_NUM; --EXECUTE IMMEDIATE用法3:带参数的sql V_sql := 'select * from employees e where e.employee_id = :1 and first_name = :2'; EXECUTE IMMEDIATE V_sql; USING 200, 'Jennifer'; END PRO_TEST;