当然没有主从关系 SQL> declare 2 num integer; 3 begin 4 select count(name) into num from tt; 5 if num >0 then 6 begin 7 drop table test; 8 end ; 9 end if ; 10 end; 11 / drop table test; * ERROR 位于第 7 行: ORA-06550: 第 7 行, 第 5 列: PLS-00103: 出现符号 "DROP"在需要下列之一时: begincasedeclareexitfor gotoifloopmodnullpragmaraisereturnselectupdatewhilewith <an identifier><a double-quoted delimited-identifier> <a bind variable><<closecurrentdeletefetchlockinsertopen rollbacksavepointsetsqlexecutecommitforallmerge <a single-quoted SQL string>pipeSQL> Create procedure proc_tt 2 as 3 begin 4 drop table tt; 5 end ; 6 /警告: 创建的过程带有编译错误。
declare 2 num integer; v_sql string(100); 3 begin 4 select count(name) into num from tt; 5 if num >0 then 6 begin v_sql:='drop table test'; 7 execute immediate v_sql; 8 end ; 9 end if ; 10 end; 11 / drop table test;
SQL> declare
2 num integer;
3 begin
4 select count(name) into num from tt;
5 if num >0 then
6 begin
7 drop table test;
8 end ;
9 end if ;
10 end;
11 /
drop table test;
*
ERROR 位于第 7 行:
ORA-06550: 第 7 行, 第 5 列:
PLS-00103: 出现符号 "DROP"在需要下列之一时:
begincasedeclareexitfor
gotoifloopmodnullpragmaraisereturnselectupdatewhilewith
<an identifier><a double-quoted delimited-identifier>
<a bind variable><<closecurrentdeletefetchlockinsertopen
rollbacksavepointsetsqlexecutecommitforallmerge
<a single-quoted SQL string>pipeSQL> Create procedure proc_tt
2 as
3 begin
4 drop table tt;
5 end ;
6 /警告: 创建的过程带有编译错误。
2 num integer;
v_sql string(100);
3 begin
4 select count(name) into num from tt;
5 if num >0 then
6 begin
v_sql:='drop table test';
7 execute immediate v_sql;
8 end ;
9 end if ;
10 end;
11 /
drop table test;
2.需执行动态sql语句删除表或创建表像“相逢何必曾相识“所说的