由于PL/SQL中不可以直接嵌入DDL。如果要嵌的话。则可以是用动态SQL 如下:
[@more@]declare
v_name varchar2(30);
begin
for rec in (select TNAME from tab)
loop
IF rec.tname like 'BB%' THEN
dbms_output.put_line(rec.tname);
v_name := 'drop table ' || rec.tname;
execute immediate v_name;
END IF;
END LOOP;
end;
/
create or replace procedure proc_tmp is
dynamic_sql varchar2(100);
begin
dynamic_sql := 'CREATE TABLE t_tmp(a VARCHAR2(24),b VARCHAR2(24))';
EXECUTE IMMEDIATE dynamic_sql;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/118026/viewspace-807751/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/118026/viewspace-807751/