我有以下PL / SQL:

declare

i_cnt number;

begin

select count(1) into i_cnt

from dba_tables

where table_name = upper('foo')

and owner = upper('bar');

if i_cnt > 0 then

drop table foo; --

end if;

end;

从中我得到这个错误.

ORA-06550: line 6,column 5:

PLS-00103: Encountered the symbol "DROP" when expecting one of the following:

( begin case declare exit for goto if loop mod null pragma

raise return select update while with

<<

continue close current delete fetch lock insert open rollback

savepoint set sql execute commit forall merge pipe purge

如何在程序中删除表格?

解决方法

您不能直接从PL / SQL块执行DDL语句 – 您必须使用EXECUTE IMMEDIATE:

declare

i_cnt number;

begin

select count(1) into i_cnt

from dba_tables where table_name=upper('foo') and owner=upper('bar');

if i_cnt > 0 then

execute immediate 'drop table foo';

end if;

end;

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐