Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date format manipulation error

Status
Not open for further replies.
Sep 22, 2004
27
US
HI,

I want to extarct a date field from the table and transform into a different date format("yyddd")..say if the input date is 20010201..outut date format should be 01032.
i have tried with following queries but have encountered the following errors..


sql>describe tabledate

DATA_DATE NOT NULL DATE


SQL> select data_date from tabledate where rownum<20;

DATA_DATE
---------
03-JAN-03
31-DEC-02
31-DEC-02
31-DEC-02
31-DEC-02
03-JAN-03
31-DEC-02
31-DEC-02
03-JAN-03
31-DEC-02
03-JAN-03

DATA_DT
---------
03-JAN-03
03-JAN-03
31-DEC-02
03-JAN-03
03-JAN-03
03-JAN-03
03-JAN-03
31-DEC-02

19 rows selected.

SQL> select to_date(data_date,'yyyymmdd') data_dt from tabledate;
select to_date(data_date,'yyyymmdd') data_date from tabledate
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected


SQL> select to_number(to_date(data_date,'yyyymmdd')) data_dt from tabledate;
select to_number(to_date(data_date,'yyyymmdd')) data_dt from tabledate
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected


SQL> select to_date(to_char(data_date,'yyyymmdd'),'yyddd') data_new from tabledate where rownum<25;
select to_date(to_char(data_date,'yyyymmdd'),'yyddd') data_new from tabledate where rownum<25
*
ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string

please advice me on how to go about getting the required format..and also the reason for the above encountered errors!

Thanks in advance for your time nad help!!

regards,
suzzan'e
 
Youre nearly there with to_char.

Code:
SELECT To_Char(data_date,'yyddd') data_new
FROM   tabledate
WHERE  rownum < 25;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top