2012-11-05 79 views
2

为什么execute immediate 'truncate table trade_economics';在sqlplus脚本中出现以下错误?在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.` 
+0

我想你有一个很好的理由使用动态SQL。 –

回答

4

你需要以使其工作immediate之前添加execute

是这样的:

begin 
    execute immediate 'truncate table foo'; 
end; 
/
0

TRUNCATE是DDL(数据定义语言)。你不能在PL/SQL中执行DDL。也就是说,你不能直接通过动态SQL。

所以

使用此: DELETE FROM