oracle動態sql執行table表中儲存的sql

wisdomone1發表於2013-01-28
SQL> desc t_sql;
Name Type           Nullable Default Comments
---- -------------- -------- ------- --------
A    INTEGER        Y                        
B    VARCHAR2(4000) Y  
SQL> select * from t_sql;
 
                                      A B
--------------------------------------- --------------------------------------------------------------------------------
                                      1 select 1 from dual
                                      2 select 2 from dual
 
SQL> insert into t_sql values(3,'select sysdate from dual');
 
1 row inserted
 
SQL> commit;
 
Commit complete
 ed
SQL> ed  proc_t_sql;
SQL>
SQL> create or replace procedure proc_t_sql(in_a int)
  2  as
  3  v_b varchar2(4000);
  4  v_s varchar2(4000);
  5  begin
  6  select b into v_b from t_sql where a=in_a;
  7  execute immediate v_b into v_s;
  8  dbms_output.put_line(v_s);
  9  end;
 10  /
 
Procedure created
 
SQL> exec proc_t_sql(3);
 
2013-01-28
 
PL/SQL procedure successfully completed
 
SQL>

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-753421/,如需轉載,請註明出處,否則將追究法律責任。

相關文章