Oracle generation random date and time, oracle generation date
1. Generate a random date
For example, to generate an arbitrary date within January 1, 2015:
/*
* Analysis: any date within, that is, the date range is (2015)
* Can be converted to + (0,365 ),
* In this example, is the 'specified date'; (0,365) is the 'specified range'
*/
1. First, determine the date integer of January 1, January 1, 2015:
Select to_char (to_date ('1970-01-01 ', 'yyyy-MM-dd'), 'J') from dual; -- the result given by the system is: 2015
2. Generate a random date in the specified range [min_value, max_value:
select to_date(2457024 + trunc(DBMS_RANDOM.VALUE(0, 365)), 'J') from dual;
Ii. generate random date + time
SELECT to_date(TRUNC(DBMS_RANDOM.VALUE( to_number(to_char(to_date('20150101','yyyymmdd'),'J')), to_number(to_char(to_date('20150501','yyyymmdd')+1,'J')))),'J')+ DBMS_RANDOM.VALUE(1,3600)/3600 prize_timeFROM dual;
Generate the date and time from 00:00:00 to 23:59:59
Author: itmyhome