【问题标题】:execute immediate truncate table in sqlplus在 sqlplus 中执行立即截断表
【发布时间】:2012-11-05 11:14:20
【问题描述】:

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

 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.`

【问题讨论】:

  • 我认为您有充分的理由使用动态 SQL。

标签: sqlplus truncate execute-immediate


【解决方案1】:

您需要在immediate 之前添加execute 才能使其工作。

类似:

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

【讨论】:

    【解决方案2】:

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

    所以

    使用这个: 删除

    【讨论】:

      【解决方案3】:

      这个执行可以包含在一个过程中

      EXECUTE IMMEDIATE ('truncate table name');
      --next--
      INSERT
          / * + append * /
          INTO table ..
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-11-13
        • 1970-01-01
        • 2018-01-30
        • 2011-06-15
        • 2023-04-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多