views:

114

answers:

4
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

+3  A: 

try

TO_DATE('01/01/2009', 'dd/mm/yyyy')
michele
+4  A: 

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.

Dirk
A: 

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%5Ferror%5Fcodes.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

Terence Honles
A: 

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
Jeffrey Kemp