[20171106]DBMS_UTILITY.GET_TIME().txt

[20171106]DBMS_UTILITY.GET_TIME().txt

--//有时候测试某个脚本运行时间,经常在这之前之后调用这个函数.今天奇怪的发现显示竟然是负数,感觉很奇怪做一个探究.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

$ cat x1.sql
set numw 38
select dbms_utility.get_time() from dual ;
host sleep 5
select dbms_utility.get_time() from dual ;

SCOTT@book> @ x1.sql

               DBMS_UTILITY.GET_TIME()
--------------------------------------
                           -2136560314

               DBMS_UTILITY.GET_TIME()
--------------------------------------
                           -2136559814

 

SCOTT@book> select -2136559814 - (-2136560314) from dual ;
             -2136559814-(-2136560314)
--------------------------------------
                                   500

--//很明显两者相减是500,可以猜测这个单位是厘秒.
SCOTT@book> @ &r/desc_proc sys dbms_utility get_time
INPUT OWNER PACKAGE_NAME OBJECT_NAME
sample : @desc_proc sys dbms_stats gather_%_stats

OWNER      PACKAGE_NAME         OBJECT_NAME                    SEQUENCE ARGUMENT_NAME        DATA_TYPE            IN_OUT    DATA_TYPE            DEFAULTED
---------- -------------------- ------------------------------ -------- -------------------- -------------------- --------- -------------------- ----------
SYS        DBMS_UTILITY         GET_TIME                              1                      NUMBER               OUT       NUMBER               N

https://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_util.htm#i1002765
GET_TIME Function

This function determines the current time in 100th's of a second. This subprogram is primarily used for determining
elapsed time. The subprogram is called twice – at the beginning and end of some process – and then the first (earlier)
number is subtracted from the second (later) number to determine the time elapsed.

Syntax

DBMS_UTILITY.GET_TIME
  RETURN NUMBER;

Return Values

Time is the number of 100th's of a second from the point in time at which the subprogram is invoked.

Usage Notes

Numbers are returned in the range -2147483648 to 2147483647 depending on platform and machine, and your application must
take the sign of the number into account in determining the interval. For instance, in the case of two negative numbers,
application logic must allow that the first (earlier) number will be larger than the second (later) number which is
closer to zero. By the same token, your application should also allow that the first (earlier) number be negative and
the second (later) number be positive.

--//文档实际上已经讲的很清楚,范围-2147483648 to 2147483647, 相当于 -2^31 to 2^31-1. 这样存在一种可能就是越界.
--//你可以想像假设现在是2147483647,在下一秒就越界了,显示应该是负数.这样两者相减就是负数,而且可能大的离谱.当然遇到这种情
--//况概率还是很低的.^_^

--//我看了另外的机器:
SYS@XXXX> select dbms_utility.get_time() from dual ;
DBMS_UTILITY.GET_TIME()
-----------------------
             1010237048

--//(2147483647-1010237048)/100/86400 = 131.62576377314814814814,这样这套系统再过132天显示的就是负数.

SCOTT@book> select power(2,32)/86400/100 from dual ;
                 POWER(2,32)/86400/100
--------------------------------------
497.1026962962962962962962962962962963

--//过497天就回头.

--//继续测试关闭数据库,修改x1.sql,前面加入startup.脚本如下:
$ cat x2.sql
startup
set numw 38
select dbms_utility.get_time(),sysdate  from dual ;

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2130748812 2017-11-07 08:33:39

--//再次重启看看.
               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2130658039 2017-11-07 08:48:47

--//再次重启看看.
               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2130493922 2017-11-07 09:16:08

--//两者日期,以及DBMS_UTILITY.GET_TIME()相减,非常接近.

SYS@book> select (to_date('2017-11-07 08:48:47','yyyy-mm-dd hh24:mi:ss')- to_date('2017-11-07 08:33:39','yyyy-mm-dd hh24:mi:ss'))*8640000 from dual ;
(TO_DATE('2017-11-0708:48:47','YYYY-MM-DDHH24:MI:SS')-TO_DATE('2017-11-0708:33:39','YYYY-MM-DDHH24:MI:SS'))*8640000
-------------------------------------------------------------------------------------------------------------------
                                                                                                              90800

SYS@book> select 2130748812 - 2130658039 from dual ;
                 2130748812-2130658039
--------------------------------------
                                 90773

SYS@book> select (to_date('2017-11-07 09:16:08','yyyy-mm-dd hh24:mi:ss')- to_date('2017-11-07 08:48:47','yyyy-mm-dd hh24:mi:ss'))*8640000 from dual ;
(TO_DATE('2017-11-0709:16:08','YYYY-MM-DDHH24:MI:SS')-TO_DATE('2017-11-0708:48:47','YYYY-MM-DDHH24:MI:SS'))*8640000
-------------------------------------------------------------------------------------------------------------------
                                                                                                             164100

SYS@book> select 2130658039 -2130493922 from dual ;
                 2130658039-2130493922
--------------------------------------
                                164117

--//修改x2.sql继续测试:

$ cat x2.sql
startup
set numw 38
select sysdate-(dbms_utility.get_time()+2147483648)/86400/100 from dual ;
select dbms_utility.get_time(),sysdate  from dual ;

--//再次重启看看.
SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:04:32

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2130296105 2017-11-07 09:49:07

--//你可以反复测试,时间都是按照2017-11-05 10:04:32作为起点.不知道为什么?做多相差+-2秒.下午在看看,先放一放....^_^.
SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:04:34

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2128493292 2017-11-07 14:49:38

--//在一台10g的环境测试:
SYS@test> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- ----------------------------------------------------------------
x86_64/Linux 2.4.xx            10.2.0.4.0     Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:43:06

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2128324889 2017-11-07 15:56:14

SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:43:07

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2128315466 2017-11-07 15:57:49

===========================

--//明天继续看看,重启数据库执行x2.sql,11g的测试环境:
SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:04:44

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2121864761 2017-11-08 09:14:33

--//今天的起点是"2017-11-05 10:04:44",与前面有40分钟差异.

--//在一台10g的环境测试:
SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:43:17

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2122079933 2017-11-08 09:17:14

SYSDATE-(DBMS_UTILI
-------------------
2017-11-05 10:43:17

               DBMS_UTILITY.GET_TIME() SYSDATE
-------------------------------------- -------------------
                           -2122075037 2017-11-08 09:18:03

--//10g有10秒差距.

--//放弃,这些细节知道没意思,仅仅知道以一个起点取时间.单位是厘秒就ok了.越界发生的概率很小的.

时间: 2024-09-23 00:59:07

[20171106]DBMS_UTILITY.GET_TIME().txt的相关文章

[20131128]12c的dbms_utility.expand_sql_text.txt

[20131128]12c的dbms_utility.expand_sql_text.txt SCOTT@ztest> @verBANNER                                                                              CON_ID-------------------------------------------------------------------------------- ----------Oracl

[20130607]PL/SQL存储过程的commit提交问题.txt

[20130607]PL/SQL存储过程的commit提交问题.txt 昨天在看别人写的存储过程的时候,发现程序代码里面不好的写法,就是把commit写在循环体内,这样写按照以前应该会产生很大的redo日志,主要是redo waste也会增加,但是我在11G下测试,情况好像不一样. 1.建立测试环境: SQL> @ver BANNER --------------------------------------------------------------------------------

ORACLE之常用FAQ V1.0 (1)

oracle 第一部分.SQL&PL/SQL [Q]怎么样查询特殊字符,如通配符%与_[A]select * from table where name like 'A\_%' escape '\'[Q]如何插入单引号到数据库表中[A]可以用ASCII码处理,其它特殊字符如&也一样,如 insert into t values('i'||chr(39)||'m'); -- chr(39)代表字符'或者用两个单引号表示一个or insert into t values('I''m'); --

Oracle RAC环境单独节点插入数据也会导致全局等待(下)

在RAC环境中,登陆到一个实例,在处理的数据完全与另外实例内存中数据无关的情况下,也会导致gc全局等待产生. 这一篇描述性能影响. 上一篇文章描述gc等待产生的现象,这篇文章验证一下产生的全局等待是否会对性能产生不利影响: SQL> truncate table t; 表被截断. SQL> set timing on SQL> insert into t 2  select * 3  from t_big; 已创建6430135行. 已用时间:  00: 01: 05.05 SQL>

Oracle中如何创建自治事务

CREATE OR REPLACE PACKAGE BODY EBS_TRADE IS -- 获取数据库中的错误信息 PROCEDURE MakeErrorMessage(Head IN EbsHeadObject, ErrorCode IN VARCHAR2, ResBuffer OUT VARCHAR2) AS PRAGMA AUTONOMOUS_TRANSACTION;        time_end NUMBER; BEGIN time_end:=DBMS_UTILITY.GET_TIM

Sql与oracle中null值

  1 null值的介绍 NULL 是数据库中特有的数据类型,当一条记录的某个列为 NULL ,则表示这个列的值是未知的.是不确定的.既然是未知的,就有无数种的可能性.因此, NULL 并不是一个确定的值. 这是 NULL 的由来.也是 NULL 的基础,所有和 NULL 相关的操作的结果都可以从 NULL 的概念推导出来. 2 oracle中的null值介绍 在不知道具体有什么数据的时候,即未知,可以用NULL, 称它为空,ORACLE中,含有空值的表列长度为零.允许任何一种数据类型的字段为空

oracle常用函数汇总

以下是对oracle中的常用函数进行了汇总介绍,需要的朋友可以过来参考下   一.运算符算术运算符:+ - * / 可以在select 语句中使用 连接运算符:|| select deptno|| dname from dept; 比较运算符:> >= = != < <= like between is null in 逻辑运算符:not and or 集合运算符: intersect ,union, union all, minus 要求:对应集合的列数和数据类型相同     

ORACLE告警日志文件

告警日志介绍   告警日志文件是一类特殊的跟踪文件(trace file).告警日志文件命名一般为alert_<SID>.log,其中SID为ORACLE数据库实例名称.数据库告警日志是按时间顺序记录message和错误信息.   告警日志位置 在ORACLE 10g中,BACKGROUND_DUMP_DEST参数确定了告警日志的位置,但是告警日志的文件名无法修改,告警日志的名称 为:alert_<SID>.log ,其中<SID>是实例的名称.BACKGROUND_D

oracle数据库常用日期函数讲解

调用日期函数时,首先要明确两个概念,时间戳和日期是不同的,日期中包括年月日但不包括小时分钟秒,时间戳包括年月日小时分钟秒.在oracle中,一般情况下,函数中包含date字符的和日期有关,包含timestamp的函数和时间戳有关(时间戳可以理解为时间).oracle中,日期一般以天为基本单位,时间相减时结果单位为天,时间与数字相加时,默认加对应数字的天数. 一.调用时无参无括号时间函数 1.返回系统当前日期sysdate --该函数返回值没有时间戳 select sysdate from dua