gpt4 book ai didi

oracle - 删除表(如果存在)

转载 作者:行者123 更新时间:2023-12-04 22:49:31 24 4
gpt4 key购买 nike

我有以下 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; -- <--- error this line
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 <an identifier>
<a double-quoted delimited-identifier> <a bind variable> <<
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;

关于oracle - 删除表(如果存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10838558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com