I am doing this simple select command against my table EMP...
select count(*) from EMP where
to_date(birthdate,'mmddyyyy')>='01-JAN-90';
to_date(birthdate,'mmddyyyy')>='01-JAN-90'
*
ERROR at line 2:
ORA-01843: not a valid month
***birthdate column is varchar2(8) of format 'mmddyyyy' (to allow conversion errors loaded from
foxpro database)
To bypass erroneous dates, I created this function:
=====================
CREATE OR REPLACE FUNCTION is_date (p_string VARCHAR2)
RETURN INTEGER
AS
v_dummy DATE;
BEGIN
v_dummy := TO_DATE(p_string, 'MMDDYYYY');
RETURN 0;
EXCEPTION
WHEN OTHERS THEN RETURN 1;
END;
/
======================
Then I run my second program.....
select count(*) from EMP where
to_date(birthdate,'mmddyyyy')>='01-JAN-90' AND IS_DATE(BIRTHDATE)=0;
to_date(birthdate,'mmddyyyy')>='01-JAN-90' AND IS_DATE(BIRTHDATE)=0
*
ERROR at line 2:
ORA-01843: not a valid month
....WHY IS IT THAT MY FUNCTION "IS_DATE" NOT WORKING?
THANKS A LOT
Last edited by yxez; 06-20-2007 at 12:40 AM.
Behind The Success And Failure Of A Man Is A Woman
Sanjay G. ,sorry but what u posted is definitely wrong.
The format in the TO_DATE has nothing to deal with the format of the string at the right side of the greater operator.
yxez, pls post here the results of
show parameter nls
also try
....
where to_date(birthdate,'mmddyyyy')>=to_date('01.01.1990','dd.mm.yyyy')
and let us know if it works
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
nls_calendar string
nls_comp string
nls_currency string
nls_date_format string
nls_date_language string
nls_dual_currency string
nls_iso_currency string
nls_language string AMERICAN
nls_length_semantics string BYTE
nls_nchar_conv_excp string FALSE
nls_numeric_characters string
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
nls_sort string
nls_territory string AMERICA
nls_time_format string
nls_time_tz_format string
nls_timestamp_format string
nls_timestamp_tz_format string
SQL>
Hmnnnn .....my error which is "invalid month" means that my
birthdate data contains erroneous data like for example '13012007' in which
13 is out of range for month.
I am just wondering my the function I used to filter the data in the
where clause (is_date) was not working?
Thanks....
Jenn
Behind The Success And Failure Of A Man Is A Woman
I see now. Sorry for not reading careful the question.
Well seems it depends if the to_date will get evaluated first or is_date will be evaluated first. Obviously to_date gets evaluated first :-(
Maybe u can try
select count(*) from (select * from emp where IS_DATE(BIRTHDATE)=0)
where
to_date(birthdate,'mmddyyyy')>='01-JAN-90'
Bookmarks