【问题标题】:Procedure is throwing compile time error oracle [duplicate]程序抛出编译时错误oracle [重复]
【发布时间】:2018-01-15 13:22:50
【问题描述】:

oracle 的新功能,在制作过程时遇到编译时错误,所以任何人都可以帮助我纠正这个错误。

代码片段:

Create or replace Procedure prc_DropUselessTables(userID number:=0)
as
ncount number:=0;
Begin

Select count(*) from User_Tables where table_name='DummyTable';

if(ncount>0) then

Drop table DummyTable;----Error Line

end if;

end prc_DropUselessTables;

谢谢

【问题讨论】:

  • 我没有错误,您的错误是什么以及您是如何执行的?
  • 您需要使用EXECUTE IMMEDIATE 在过程中运行 DDL。当问一个问题时,总是显示你得到了什么错误。我相信你有错误PLS-00103: Encountered the symbol "DROP" when expecting....

标签: oracle oracle11g oracle-sqldeveloper


【解决方案1】:

您不能直接在过程中运行 DDL。您需要使用EXECUTE IMMEDIATE

CREATE OR REPLACE PROCEDURE prc_DropUselessTables (userID NUMBER := 0)
AS
   ncount   NUMBER := 0;
BEGIN
   SELECT COUNT (*)
     INTO NCOUNT
     FROM User_Tables
    WHERE table_name = 'DummyTable';

   IF (ncount > 0)
   THEN
      EXECUTE IMMEDIATE 'Drop table DummyTable';
   END IF;
END prc_DropUselessTables;

【讨论】:

  • 感谢 Nitish 的回复,Execute 语句有 30 个字符的限制,那么如何满足呢?
  • EXECUTE IMMEDIATE 没有 30 个字符的限制。看看这个documentation
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 1970-01-01
相关资源
最近更新 更多