All days in a year - Query

Here is the query to find all dates and the days in a current year:

select mydate,to_char(mydate,'Day') from(
select (level-1)+to_date('01-01-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy') mydate from dual
connect by level <=to_date('31-12-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy')-to_date('01-01-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy') +1)


Note: You must be running 10g to get the desired output. For a non 10g version see below the query:

select mydate,to_char(mydate,'Day') from(
select (rownum-1)+to_date('01-01-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy') mydate from all_objects
where
rownum <=to_date('31-12-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy') - to_date('01-01-'||to_char(sysdate,'yyyy'),'dd-mm-yyyy') +1)


The above query assumes that all_objects returns at least 365 records.

Comments

Popular posts from this blog

Reports Builder wont open in Windows 10 64bit - [SOLVED]

csv Data to Rows - SQL

Your session has expired - For Custom Apps after Oracle Apex Upgrade from 5 to 20