Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sql to generate yearly report

KODSJan 22 2014 — edited Jan 23 2014

Hi All,


I prepared a SQL to find out number of objects created by each user in the database in each month.

select * from (
  select owner,to_char(created,'MON') dt from dba_objects)
pivot(  count(1) for (dt) in ('JAN' as JAN,'FEB' as FEB,'MAR' as MAR,'APR' as APR,'MAY' as MAY,'JUN' as JUN,'JUL' as JUL,'AUG' as AUG,'SEP' as SEP,'OCT' as OCT,'NOV' as NOV,'DEC' as DEC))
order by owner;

SQL> r
  1  select * from (
  2    select owner,to_char(created,'MON') dt from dba_objects)
  3  pivot(  count(1) for (dt) in ('JAN' as JAN,'FEB' as FEB,'MAR' as MAR,'APR' as APR,'MAY' as MAY,'JUN' as JUN,'JUL' as JUL,'AUG' as AUG,'SEP' as SEP,'OCT' as OCT,'NOV' as NOV,'DEC' as DEC))
  4* order by owner

OWNER                            JAN   FEB   MAR   APR   MAY   JUN   JUL   AUG   SEP   OCT   NOV   DEC
------------------------------ ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
SCOTT                           1047   185     2     0     0    14     0  9869    55  1054     0   778
Praveen                          2434     0     0     0     0     1     0     0     0     0     0     0
JOHN                                 0     0     0     0     0     0     0     0     0     1     0     0


Now, I am trying to generate a report for yearly wise. I prepared the below queryb but it is not working. Please let me know where I am doing wrong.

select * from (
  select owner,to_char(created,'YYYY') dt from dba_objects)
pivot(  count(1) for (dt) <= to_char(sysdate,'YYYY'))
order by owner;


Thanks,
Kods

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 20 2014
Added on Jan 22 2014
13 comments
5,003 views