Home » SQL & PL/SQL » SQL & PL/SQL » i want basic query
i want basic query [message #221247] Sun, 25 February 2007 23:41 Go to next message
akkumar81
Messages: 144
Registered: February 2007
Location: india
Senior Member

I have one doubt in sql,

In my application ,

I have sort data multiple wayes at one time,

Shall I use order by stmt muliple time in single query,

Send me some sample Query

Regards,

Kiss07. Cool
Re: i want basic query [message #221312 is a reply to message #221247] Mon, 26 February 2007 04:15 Go to previous message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Here's one way (note that the datatype of the columns should be the same in order to get the decode to work):

SQL> with yourtable as
  2       ( select 'w' col1, 'r' col2 from dual union
  3         select 'a' col1, 'c' col2 from dual union
  4         select 'b' col1, 'x' col2 from dual union
  5         select 'c' col1, 'v' col2 from dual union
  6         select 'd' col1, 'a' col2 from dual
  7       )
  8  select col1
  9       , col2
 10  from  yourtable
 11  order by decode(&sortcol, 1, col1, 2, col2 )
 12  /
Enter value for sortcol: 1
old  11: order by decode(&sortcol, 1, col1, 2, col2 )
new  11: order by decode(1, 1, col1, 2, col2 )

C C
- -
a c
b x
c v
d a
w r

SQL> /
Enter value for sortcol: 2
old  11: order by decode(&sortcol, 1, col1, 2, col2 )
new  11: order by decode(2, 1, col1, 2, col2 )

C C
- -
d a
a c
w r
c v
b x

SQL>


MHE
Previous Topic: On Date Change Trigger
Next Topic: sql help
Goto Forum:
  


Current Time: Sat Dec 03 03:51:31 CST 2016

Total time taken to generate the page: 0.05773 seconds