oracle 尝试更改 sql 块中的表时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7575887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error while trying to alter table in an sql block
提问by Victor
I create a test.sql file and inside I put:
我创建了一个 test.sql 文件,然后在里面放了:
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
回答by Justin Cave
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.
您不能在 PL/SQL 块中将 DDL 作为静态 SQL 发出。如果要将这些命令放在 PL/SQL 块中,则需要使用动态 SQL,即
BEGIN
EXECUTE IMMEDIATE 'alter table table1 enable row movement';
EXECUTE IMMEDIATE 'alter table table1 shrink space cascade';
END;
/
It may be easier, however, to just issue consecutive SQL statements rather than issuing a single PL/SQL block.
然而,仅发出连续的 SQL 语句而不是发出单个 PL/SQL 块可能更容易。