sysdate [message #272030] |
Wed, 03 October 2007 13:04 |
lamnguyen14
Messages: 119 Registered: March 2007 Location: Virginia
|
Senior Member |
|
|
Hello All.
I have to insert into table dr_emp some different values based on the date.
I wrote a code like below and when I compiled it I got an error message:
ORA-01843: not a valid month
Please help. I would appreciate that.
BEGIN
IF sysdate = '10/06/2007' THEN
INSERT INTO dr_emp (dr_id, emp_id, dr_ckin , emp_ckin
,dr_file , emp_file )
VALUES ('0000', '0000', '0000', '0000', '0', '0' );
ELSE
INSERT INTO dr_emp (dr_id, emp_id, dr_ckin , emp_ckin
,dr_file , emp_file )
VALUES ('0000', '0000', '0000', '0000', '1', '1' );
END IF;
END;
|
|
|
Re: sysdate [message #272031 is a reply to message #272030] |
Wed, 03 October 2007 13:06 |
Ronald Beck
Messages: 121 Registered: February 2003
|
Senior Member |
|
|
You're comparing a DATE type to a STRING type. Change the date string in your IF statement into a date with the TO_DATE function.
|
|
|
|
|
Re: sysdate [message #272094 is a reply to message #272034] |
Thu, 04 October 2007 00:42 |
Frank
Messages: 7901 Registered: March 2000
|
Senior Member |
|
|
In addition to what was said in previous posts: sysdate also contains a time-part, so sysdate is never (well, hardly ever) equal to just the date part of a date.
Do a trunc(sysdate) = to_date('01-01-2007', 'dd-mm-yyyy') to compare just the date-parts
|
|
|