Home » SQL & PL/SQL » SQL & PL/SQL » Re: Need Complex Query
Re: Need Complex Query [message #22856] Fri, 01 November 2002 09:53
andrew again
Messages: 2577
Registered: March 2000
Senior Member
In sqlplus you can do some tricks to change column headings - else you'd need to dynamically create a view with the column names you want and then select from that. I don't think that's a good option...

SQL> --Grab string into a variable
SQL> column days7ago new_val days7ago noprint
SQL> select '<= '||to_char(sysdate-7, 'mm/dd/rr') days7ago from dual;

SQL> -- Set new heading for col1 to variable
SQL> column col1 heading '&days7ago'
SQL> SELECT   object_type, 
  2     SUM (CASE
  3                   WHEN created <= SYSDATE - 7 THEN 1
  4                   --WHEN ... THEN ...
  5                END) col1,
  6           SUM (CASE
  7                   WHEN created BETWEEN SYSDATE - 7 AND SYSDATE - 0 THEN 1
  8                END) col2
  9      FROM user_objects
 10  GROUP BY object_type;

OBJECT_TYPE        <= 08/19/02       COL2
------------------ ----------- ----------
DATABASE LINK                2          2
FUNCTION                     1
INDEX                        2
PACKAGE                      5          1
PACKAGE BODY                 4          1
PROCEDURE                    1          2
SEQUENCE                     1
SYNONYM                      3          2
TABLE                        4
VIEW                                    1

10 rows selected.

If you have an old version of Oracle, then use a combination of DECODE and SIGN rather than CASE. Search this site for an example.
Previous Topic: urgent regarding updating and comparision of records
Next Topic: sorting siblings in connect by in 8i
Goto Forum:
  


Current Time: Mon Apr 29 00:27:30 CDT 2024