我创建了一个 test.sql 文件,并在其中放入:
begin
alter table table1 enable row movement;
alter table table1 shrink space;
end;
/
这是不允许的吗?因为我收到错误:
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 block 中将 DDL 作为静态 SQL 发出。如果您想将这些命令放入 PL/SQL block 中,则需要使用动态 SQL,即
BEGIN
EXECUTE IMMEDIATE 'alter table table1 enable row movement';
EXECUTE IMMEDIATE 'alter table table1 shrink space cascade';
END;
/
但是,仅发出连续的 SQL 语句可能比发出单个 PL/SQL block 更容易。
关于oracle - 尝试更改 sql block 中的表时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7575887/