在sqlplus中执行立即截断表

Vis*_*ena 2 truncate sqlplus execute-immediate

为什么execute immediate 'truncate table trade_economics';在 sqlplus 脚本中会出现以下错误?

 BEGIN immediate 'truncate table trade_economics'; END;
                    *
    ERROR at line 1:
    ORA-06550: line 1, column 17:
    PLS-00103: Encountered the symbol "truncate table trade_economics" when
    expecting one of the following:
    := . ( @ % ;
    The symbol ":=" was substituted for "truncate table trade_economics" to
    continue.`
Run Code Online (Sandbox Code Playgroud)

Pab*_*ruz 5

您需要先添加execute才能immediate使其正常工作。

就像是:

begin
    execute immediate 'truncate table foo';
end;
/
Run Code Online (Sandbox Code Playgroud)