how to convert string to date [message #291152] |
Thu, 03 January 2008 03:21  |
annu-agi
Messages: 239 Registered: July 2005 Location: Karachi
|
Senior Member |
 
|
|
hi experts
Data stored in distributed form e.g day , month and year and i want to store in one field for that i test the query below .. and at the end i stuck in how to convert whole string in date type data. see the query below and help me out
1* select to_Date(substr(last_day(to_date(&mmon,'MM')),1,2)||'-'||to_char(to_date(&mmon,'MM'),'Mon')||'-'||to_number(&myear),'DD-MM-YYYY') from dual
SQL> /
Enter value for mmon: 02
Enter value for mmon: 02
Enter value for myear: 2007
old 1: select to_Date(substr(last_day(to_date(&mmon,'MM')),1,2)||'-'||to_char(to_date(&mmon,'MM'),'Mon')||'-'||to_number(&myear),'DD-MM-YYYY') from dual
new 1: select to_Date(substr(last_day(to_date(02,'MM')),1,2)||'-'||to_char(to_date(02,'MM'),'Mon')||'-'||to_number(2007),'DD-MM-YYYY') from dual
select to_Date(substr(last_day(to_date(02,'MM')),1,2)||'-'||to_char(to_date(02,'MM'),'Mon')||'-'||to_number(2007),'DD-MM-YYYY') from dual
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
SQL>
regards
anwer
|
|
|
|
|
|
Re: how to convert string to date [message #291160 is a reply to message #291152] |
Thu, 03 January 2008 03:37   |
 |
rajavu1
Messages: 1574 Registered: May 2005 Location: Bangalore , India
|
Senior Member |

|
|
And Error is Because ....
SQL> select substr(last_day(to_date(02,'MM')),1,2) from dual;
SU
--
29
SQL> select to_char(to_date(02,'MM'),'Mon') from dual;
TO_
---
Feb
SQL> select to_number(2007) from dual;
TO_NUMBER(2007)
---------------
2007
SQL> select to_Date('29'||'-'||'FEB'||'-'||2007,'DD-MM-YYYY') from dual;
select to_Date('29'||'-'||'FEB'||'-'||2007,'DD-MM-YYYY') from dual
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
SQL> select to_Date('29'||'-'||'FEB'||'-'||'2007','DD-MM-YYYY') from dual;
select to_Date('29'||'-'||'FEB'||'-'||'2007','DD-MM-YYYY') from dual
*
ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
SQL> SELECT LAST_DAY(TO_DATE('01-FEB-2007','DD-MON-YYYY')) LASTDAY FROM DUAL;
LASTDAY
---------
28-FEB-07
SQL>

Rajuvan.
[Updated on: Thu, 03 January 2008 03:40] Report message to a moderator
|
|
|
|
|
|