Skip to content
Advertisement

I have date function to create for entering date and to create random time i want to combine both of them

hi dear i have a query which create dates for specic lenght which is mentioned and a query which is create random time want to join both for date generating is this It create dates for specific lenght and insert into table query is

what it will do is enter CALENDER_DATE2 all dates mentioned on connect by level

2nd query is to genrate random time

I want to write both query work together what i wrote which is not working for me that is

i write this but it not worked for me please help struck here from past many hours

Advertisement

Answer

You can use:

Which for the table:

Gives you 15 rows for each day of 2020 each with random offset between 1 and 15 minutes from midnight.

Note:

  • The number of days in the year is calculated so you do not need to account for leap years.
  • Use FLOOR( DBMS_RANDOM.VALUE( 1, 16 ) ) rather than ROUND( DBMS_RANDOM.VALUE( 1, 15 ) ) as the first will give you an even spread of values whereas the second will only give a value 1 when the random value is between 1 and 1.5 and a value of 15 between 14.5 and 15 which will both occur with only half the frequency as the rest of the numbers and would give you an unbalanced distribution.
  • You can calculate the day of the week by comparing the start of the day TRUNC( dt ) to the start of the ISO week TRUNC( dt, 'IW' ). This has the benefit that it is independent of the NLS settings and will work in all languages rather than just being limited to English speaking territories.

db<>fiddle here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement