To achieve our task we use connect by level in our SQL to generate the followings:
SQL for Generating Dates in Sequence:
Select To_Date(Sysdate-30, 'dd-mm-rrrr') + (Level - 1) DatesFrom Dual
Connect By Level <= ((To_Date(Sysdate, 'dd-mm-rrrr') -
To_Date(Sysdate-30, 'dd-mm-rrrr')) + 1);
Result:
SQL for Generating Time in Sequence:
To_Char(Trunc(Sysdate) + (Level - 1) / 24, 'YYYY-MM-DD HH24:MI') As Date_Hour,
To_Char(Trunc(Sysdate) + (Level - 1) / 24, 'HH24:MI') As Hours
From Dual
Connect By Level <= 24;
Result:
No comments:
Post a Comment