Dave Jarvis
Dave Jarvis

Reputation: 31171

Randomize Time Portion of Date Field

What is the best way to randomize the time part for a DATE column, using Oracle 10g?

For example, the date portion for the data was set as follows:

UPDATE table_name SET column_ts = SYSDATE - 120 + MOD(ROWNUM, 35)

I would like the time portion to have a different value for each row.

Upvotes: 1

Views: 221

Answers (2)

cagcowboy
cagcowboy

Reputation: 30848

Choose a random number between 0 and 86400 (number of seconds in a day)

Add random / 86400 to your date.

SELECT TRUNC(SYSDATE)+DBMS_RANDOM.value(0, 86400-1)/86400 FROM DUAL

ADDITION:

UPDATE table_name
SET    column_ts = SYSDATE - 120 + MOD(ROWNUM, 35) + DBMS_RANDOM.value(0, 86400-1)/86400;

Upvotes: 3

Chi
Chi

Reputation: 23174

select trunc(sysdate)+dbms_random.value from dual;

Upvotes: 2

Related Questions