ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 用dbms_random包获取随机时间

用dbms_random包获取随机时间

原创 Linux操作系统 作者:lsq_008 时间:2011-07-31 10:08:13 0 删除 编辑

100天内的随机时间精确到秒:

 

SQL> SELECT TO_DATE (TRUNC (DBMS_RANDOM.VALUE (TO_NUMBER (TO_CHAR (SYSDATE - 100,

  2                                                                'J'

  3                                                               )

  4                                                      ),

  5                                            TO_NUMBER (TO_CHAR (SYSDATE, 'J'))

  6                                           )

  7                        ),

  8                  'J'

  9                 )  + DBMS_RANDOM.VALUE (0, 1)

 10    FROM DUAL;

 

TO_DATE(TRUNC(DBM

-----------------

20110617 02:34:56

 

SQL> /

 

TO_DATE(TRUNC(DBM

-----------------

20110703 04:33:09

 

SQL> /

 

TO_DATE(TRUNC(DBM

-----------------

20110508 13:23:17

 

SQL> /

 

TO_DATE(TRUNC(DBM

-----------------

20110523 04:36:26

 

100天内的随机时间,精确到天:

 

SQL> SELECT TO_DATE (TRUNC (DBMS_RANDOM.VALUE (TO_NUMBER (TO_CHAR (SYSDATE - 100,

  2                                                                'J'

  3                                                               )

  4                                                      ),

  5                                            TO_NUMBER (TO_CHAR (SYSDATE, 'J'))

  6                                           )

  7                        ),

  8                  'J'

  9                 )

 10    FROM DUAL;

 

TO_DATE(TRUNC(DBM

-----------------

20110616 00:00:00

 

SQL> /

 

TO_DATE(TRUNC(DBM

-----------------

20110606 00:00:00

 

SQL> /

 

TO_DATE(TRUNC(DBM

-----------------

20110514 00:00:00

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10972173/viewspace-703612/,如需转载,请注明出处,否则将追究法律责任。

下一篇: “我”的概念
请登录后发表评论 登录
全部评论
十余年大型金融及电信系统数据库管理经验,曾服务于中国建设银行、中国移动。对oracle,mysql数据库有深入了解。 擅长python开发,独立开发了开源数据库自动化监控运维平台Power Monitor。

注册时间:2008-02-29

  • 博文量
    325
  • 访问量
    1281664