Oracle中truncate表不更新last_ddl_time列

问题描述

最近发现数据库中定时job的某张表,每天都有truncate动作,由于调整了job的interval时间,想查看last_ddl_time辅助验证job的运行情况,结果发现last_ddl_time是几天前的时间。

单单从这点上看我还以为这个job没运行过,但是从last_date字段又可以看出最近的时间是执行过的,怎么回事呢?

测试分析

由于表示临时用的表,而且是一张空表,征得相关人员许可后,测试环境中(存在同样的问题)对表手工做truncate,再次查看last_ddl_time,果然没变化。

开始mos找资料,有这样一篇文章“LAST_DDL_TIME Not Changing (Doc ID 1448241.1)”,里边这样描述:

10g and subsequent do not invalidate dependent objects unnecessarily. Therefore, since the PACKAGE BODY is not changing, the LAST_DDL_TIME does not change.

If you would change something in the package body (a line of code, not simply a comment), you will find that LAST_DDL_TIME changes.

LAST_DDL_TIME changes for CREATE OR REPLACE ...

1. When the source of the procedure changes.
... OR ...
2. The settings of following parameters change from original creation time:
plsql_optimize_level, plsql_code_type, plsql_debug, nls_length_semantics, plsql_warnings, plsql_ccflags, plsql_compiler_flags.

So, this is not a bug, but expected behavior. Last_ddl_time is only updated if the object actually changes.

虽然DOC上描述的场景和我遇到的情况不一样,不过里边有句话提醒了我。

If you would change something in the package body (a line of code, not simply a comment), you will find that LAST_DDL_TIME changes.

(如果您要更改程序包主体中的某些内容(一行代码,而不仅仅是注释),则会发现LAST_DDL_TIME发生了更改。)

So, this is not a bug, but expected behavior. Last_ddl_time is only updated if the object actually changes.

(因此,这不是错误,而是预期的行为。仅当对象实际更改时,Last_ddl_time才会更新。)

所以有可能是原表就是空表,你做truncate操作的时候,实际上就不会更新last_ddl_time这个列。

测试模拟

[oracle@oracle ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 28 08:34:31 2020

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SYS@zkm> startup;
ORACLE instance started. Total System Global Area 784998400 bytes
Fixed Size 2257352 bytes
Variable Size 465571384 bytes
Database Buffers 314572800 bytes
Redo Buffers 2596864 bytes
Database mounted.
Database opened. SYS@zkm> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'; Session altered. SYS@zkm> select last_ddl_time from dba_objects where object_name='TEST'; LAST_DDL_TIME
-------------------
2020-04-26 10:37:05 SYS@zkm> !date
Tue Apr 28 08:35:27 CST 2020 SYS@zkm> desc zkm.test
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER SYS@zkm> delete from zkm.test; 13107200 rows deleted. SYS@zkm> commit; Commit complete. SYS@zkm> truncate table zkm.test; Table truncated. SYS@zkm> select last_ddl_time from dba_objects where object_name='TEST'; LAST_DDL_TIME
-------------------
2020-04-28 08:43:24

从这里看,我将表的数据全部delete并且commit后,truncate表竟然last_ddl_time更新了。

随后我想到truncate表实际上是换了个段,data_object_id会变,那再次truncate的话应该不会再更新last_ddl_time了。

SYS@zkm> select object_id,data_object_id from dba_objects where owner='ZKM' and object_name='TEST';

 OBJECT_ID DATA_OBJECT_ID
---------- --------------
18815 18832 SYS@zkm> truncate table zkm.test; Table truncated. SYS@zkm> select last_ddl_time from dba_objects where object_name='TEST'; LAST_DDL_TIME
-------------------
2020-04-28 08:43:24 SYS@zkm> select object_id,data_object_id from dba_objects where owner='ZKM' and object_name='TEST'; OBJECT_ID DATA_OBJECT_ID
---------- --------------
18815 18832

果然是这样,而且data_object_id也没变了。

Oracle中truncate表不更新last_ddl_time列的更多相关文章

  1. oracle 中删除表 drop delete truncate

    oracle 中删除表 drop delete truncate   相同点,使用drop delete truncate 都会删除表中的内容 drop table 表名 delete from 表名 ...

  2. 【转】Oracle中dual表的用途介绍

    原文:Oracle中dual表的用途介绍 [导读]dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情. dual是一个虚拟表, ...

  3. Oracle 两个表之间更新的实现

    Oracle 两个表之间更新的实现   来源:互联网 作者:佚名 时间:2014-04-23 21:39 Oracle中,如果跨两个表进行更新,Sql语句写成这样,Oracle 不会通过.查了资料,S ...

  4. 如何在Oracle中建立表和表空间?

    1.建表空间 ORACLE中,表空间是数据管理的基本方法,所有用户的对象要存放在表空间中,也就是用户有空间的使用权,才能创建用户对象.否则是不充许创建对象,因为就是想创建对象,如表,索引等,也没有地方 ...

  5. 向oracle中的表插入数据的方法

    向oracle中的表插入数据的方法有以下几种: 假设表名为User 第一种方法:select t.*,rowid from User t;-->点击钥匙那个标记就可向表中添加数据 第二种方法:s ...

  6. oracle中给表和列起别名

    SELECT xxmc,sname as xsxm,sex,phone,address jzdz FROM student s LEFT JOIN xxjbxx x ON x.sid = s.sid ...

  7. Oracle中dual表的用途介绍

    导读]dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情.     dual是一个虚拟表,用来构成select的语法规则,or ...

  8. Oracle中dual表的用途介绍-转

    读]dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情. dual是一个虚拟表,用来构成select的语法规则,oracle保 ...

  9. Oracle中dual表的用途

    dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情,如下: 1.查看当前用户,可以在 SQL Plus中执行下面语句 sele ...

随机推荐

  1. lambda表达式操作DataTable番外篇

    using System;using System.Collections.Generic;using System.Data;using System.Linq;using System.Text; ...

  2. npm run dev启动项目,electron提示throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')

    npm run dev 项目,提示 throw new Error('Electron failed to install correctly, please delete node_modules/ ...

  3. Flask 的请求与响应

    flask的请求与响应 from flask import Flask,request,make_response,render_template,redirect app = Flask(__nam ...

  4. go 语言中windows Linux 交叉编译

    记录一下. 在windows系统编译,然后再Linux系统运行. 在项目目录下运行: 命令: set GOARM=5 set GOARCH=arm set GOOS=linux go build xx ...

  5. JAVA多线程实现的三种方法

    JAVA多线程实现方式主要有三种:继承Thread类.实现Runnable接口.使用ExecutorService.Callable.Future实现有返回结果的多线程.其中前两种方式线程执行完后都没 ...

  6. git status –s

    状态简览 git status 命令的输出十分详细,但其用语有些繁琐. 如果你使用 git status -s 命令或 git status --short 命令,你将得到一种更为紧凑的格式输出. 运 ...

  7. 线上排查Class、Jar加载问题的一般方法

    问题背景 本问题源于<ojdbc6中OraclePreparedStatement的ArrayIndexOutOfBoundsException异常BUG-6396242>这篇博文中最后思 ...

  8. Android SDK 安装与配置

    1.下载sdk包 链接:https://pan.baidu.com/s/1Og8F02YBJn59LPWsJwkjUA 提取码:byu1 复制这段内容后打开百度网盘手机App,操作更方便哦 2.解压 ...

  9. 电脑中找不到.ssh文件的解决办法

    打开GIT bash写上命令:1.git config --global user.name “XXX”xxx代表你的用户名 2.git config --global user.email &quo ...

  10. Springboot打包后,获取不到resource目录下资源文件的报错

    1.问题: java.io.FileNotFoundException ****目录下找不到模板文件 在使用Springboot启动类启动没有错,但是打包放到tomcat.东方通这些外部容器上报错,在 ...