尝试更改SQL块中的表时出现错误 [英] Getting error while trying to alter table in an sql block
本文介绍了尝试更改SQL块中的表时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个test.sql文件,并放入其中:
I create a test.sql file and inside I put:
begin
alter table table1 enable row movement;
alter table table1 shrink space;
end;
/
这是不允许的吗?因为出现错误:
Is this not allowed? Because I get error:
Encountered the symbol "ALTER" 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> <<
close current delete fetch lock insert open rollback
savepoint set sql execute commit forall merge pipe
推荐答案
您不能在PL/SQL块中将DDL作为静态SQL发布.如果要将这些命令放在PL/SQL块中,则需要使用动态SQL,即
You cannot issue DDL as static SQL in a PL/SQL block. If you want to put those commands in a PL/SQL block, you'd need to use dynamic SQL, i.e.
BEGIN
EXECUTE IMMEDIATE 'alter table table1 enable row movement';
EXECUTE IMMEDIATE 'alter table table1 shrink space cascade';
END;
/
但是,仅发出连续的SQL语句而不是发出单个PL/SQL块可能更容易.
It may be easier, however, to just issue consecutive SQL statements rather than issuing a single PL/SQL block.
这篇关于尝试更改SQL块中的表时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文