please let me know the issue with following sql query

272 views Asked by At
SELECT pd_end_dt,nrx_cnt
FROM wkly_lnd.lnd_wkly_plan_rx_summary
WHERE pd_end_dt >TO_DATE('01/01/2009')

It is giving error ORA-01843: not a valid month


i ran the following it did fine

SELECT pd_end_dt,nrx_cnt FROM wkly_lnd.lnd_wkly_plan_rx_summary WHERE pd_end_dt > '01-Jan-09'

but if i want to have week wise data how to do dat

4

There are 4 answers

0
Jeffrey Kemp On

There are two possibilities:

  1. The TO_DATE function is failing due to the default date format (as per other answers already given here).

  2. The column pd_end_dt is not a date column. The query is trying to convert the values in pd_end_dt to dates prior to the comparison, and failing on one of the rows.

To demonstrate:

SQL> create table t1 (datestrings varchar2(10));
SQL> insert into t1 values ('01/01/2009');
SQL> insert into t1 values ('02/01/2009');
SQL> insert into t1 values ('01/XX/2009');
SQL> select * from t1 where datestrings > '01/01/2009';

DATESTRINGS 
-----------
02/01/2009
01/XX/2009  

2 rows selected

SQL> select * from t1 where datestrings > TO_DATE('01/01/2009');

ORA-01843: not a valid month

SQL> select * from t1 where datestrings > TO_DATE('01/01/2009','DD/MM/YYY');

ORA-01843: not a valid month
0
michele On

try

TO_DATE('01/01/2009', 'dd/mm/yyyy')
0
Dirk On

You are not giving a format string to TO_DATE. This might cause Oracle to handle your date wrong. Try

to_date('01/01/2009', 'DD/MM/YYYY')

instead (depending on where you are from, you might want to change the order of DD and MM). See this description of the TO_DATE format string argument for details.

0
Terence Honles On

Ok not to sound harsh, but do a google search first. The previous answers work, but for a more comlete explaination see

http://www.dbmotive.com/oracle_error_codes.php?errcode=01843

If you are going to use the default format like you are doing then you should find out what that is first