【问题标题】:Why truncate table does not change the Last DDL Date?为什么 truncate table 不会更改 Last DDL Date?
【发布时间】:2020-03-08 21:41:00
【问题描述】:

当我运行以下代码时,我注意到Last DDL Date 没有改变。

 execute immediate 'truncate table my_table';

有什么问题?

提前致谢

【问题讨论】:

    标签: oracle plsql oracle11g toad


    【解决方案1】:

    truncate 表仅在表不为空时截断该表。

    如果表为空,则执行truncate table 命令时不会截断。

    在此处查看演示:

    SQL> select OBJECT_NAME, LAST_DDL_TIME from user_objects where OBJECT_NAME = 'CONTR';
    
    OBJECT_NAME  LAST_DDL_TIME
    ------------ --------------------
    CONTR        13-nov-2019 11:45:53
    
    SQL> truncate table CONTR; -- empty table
    
    Table truncated.
    
    SQL> select OBJECT_NAME, LAST_DDL_TIME from user_objects where OBJECT_NAME = 'CONTR';
    
    OBJECT_NAME  LAST_DDL_TIME
    ------------ --------------------
    CONTR        13-nov-2019 11:45:53
    
    SQL> INSERT INTO CONTR VALUES (1,1,1,1); -- filling values in the table
    
    1 row created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> truncate table CONTR;
    
    Table truncated.
    
    SQL> select OBJECT_NAME, LAST_DDL_TIME from user_objects where OBJECT_NAME = 'CONTR';
    
    OBJECT_NAME  LAST_DDL_TIME
    ------------ --------------------
    CONTR        13-nov-2019 11:47:46
    
    SQL> -- time is changed now
    

    干杯!!

    【讨论】:

      【解决方案2】:

      我找到了答案。

      事情是这样的:

      表格为空。

      当表为空时,您的 truncate ddl 不会 更改最后 DDL 日期。

      【讨论】:

        猜你喜欢
        • 2020-01-24
        • 2012-11-22
        • 1970-01-01
        • 1970-01-01
        • 2022-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-06
        相关资源
        最近更新 更多