Getting error while trying to alter table in an sql block

梦想的初衷 提交于 2019-12-21 06:48:54

问题


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

回答1:


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;
/

It may be easier, however, to just issue consecutive SQL statements rather than issuing a single PL/SQL block.



来源:https://stackoverflow.com/questions/7575887/getting-error-while-trying-to-alter-table-in-an-sql-block

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!