Home » SQL & PL/SQL » SQL & PL/SQL » Date (oracle10g)
Date [message #420120] Thu, 27 August 2009 02:48 Go to next message
convey05
Messages: 43
Registered: December 2007
Location: CHENNAI
Member
Is it possible to sort 3 date column in desc order.
I Tried with below example but it is not working.
Even the first column is not sorted
If anyone has idea please update.

create table dd(a date,b date,c date);

insert into dd values('01-jan-09','01-aug-09','01-sep-09');
insert into dd values('01-jan-09','03-aug-09','04-sep-09');
insert into dd values('04-jan-09','03-aug-09','04-sep-09');


select a,b,c
 from dd
order by a,b,c desc 

Thanks in advance

Re: Date [message #420124 is a reply to message #420120] Thu, 27 August 2009 03:01 Go to previous messageGo to next message
c_stenersen
Messages: 255
Registered: August 2007
Senior Member
You're now using the descending sort on column c only.

create table dd(a date,b date,c date);

insert into dd values(
  to_date('01-jan-09', 'DD-MON-RR'),
  to_date('01-aug-09', 'DD-MON-RR'),
  to_date('01-sep-09', 'DD-MON-RR')); 

--Note that I used to_date here..

insert into dd values(
  to_date('01-jan-09', 'DD-MON-RR'),
  to_date('03-aug-09', 'DD-MON-RR'),
  to_date('04-sep-09', 'DD-MON-RR'));
insert into dd values(
  to_date('04-jan-09', 'DD-MON-RR'),
  to_date('03-aug-09', 'DD-MON-RR'),
  to_date('04-sep-09', 'DD-MON-RR'));

select a,b,c
 from dd
order by a desc,b desc,c desc

a               b               c
04-JAN-09	03-AUG-09	04-SEP-09
01-JAN-09	03-AUG-09	04-SEP-09
01-JAN-09	01-AUG-09	01-SEP-09
Re: Date [message #420125 is a reply to message #420120] Thu, 27 August 2009 03:14 Go to previous message
wakula
Messages: 150
Registered: February 2008
Location: Poland
Senior Member
select *
from dd
order by a desc, b desc, c desc;

Note: that is a mistake to specify the date as '99-XYZ-00'.... What does it mean?
Always use "TO_DATE('DD-MON-YY','99-XYZ-00')". And you should always use 4-digit year... and then keep in mind that "JAN" (January) is "STY" (Styczeń) in polish... and it is something different in different locale. I would recommend using ISO-8601 wherever possible.
Previous Topic: Using online option during index rebuild.
Next Topic: Stored procedure date type compare ORA-01839
Goto Forum:
  


Current Time: Tue Aug 22 19:51:19 CDT 2017

Total time taken to generate the page: 0.05528 seconds