If Statement within Update Trigger (merged 2) 10g [message #407578] |
Wed, 10 June 2009 10:52  |
phobia42
Messages: 4 Registered: February 2008
|
Junior Member |
|
|
I would have thought this would be easy, but I'm having a heck of a time. I will be updating my Oracle database through an ASP.NET application, and I need to handle null values. I am having difficulty getting ASP.NET to insert null values (ie. it wants to put 0 for a null decimal, and 01/01/0001 for null dates). I have decided to handle it at the database level using a Before Update trigger to check the incoming value, and overwrite it if it should be null. Below is the code I am using, but it is choking on the "END IF" statement. Any suggestions? Thanks.
CREATE OR REPLACE TRIGGER U_Tbl_Control_Track_Risk
BEFORE UPDATE
ON Tbl_Control_Track_Risk
FOR EACH ROW
DECLARE
BEGIN
IF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN NEW.IBP_CONTROL_OWNER_ID := NULL END IF;
IF :NEW.BUSINESS_CONTROL_OWNER_ID = 0 THEN :NEW.BUSINESS_CONTROL_OWNER_ID := NULL END IF;
IF :NEW.CONTROL_DEADLINE < '01-JAN-1900' THEN :NEW.CONTROL_DEADLINE := NULL END IF;
IF :NEW.DATE_CONTROL_IMPLEMENTED < '01-JAN-1900' THEN :NEW.DATE_CONTROL_IMPLEMENTED := NULL END IF;
END;
|
|
|
|
Re: If Statement within Update Trigger [message #407582 is a reply to message #407578] |
Wed, 10 June 2009 11:01   |
ThomasG
Messages: 3212 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
"I am choking" is not an Oracle error message.
Post the actual error message you get, otherwise nobody will be able to help you.
'01-JAN-1900' is a string, not a date. Use an explicit to_date with a format mask, or there will definitely be problems.
But read the forum guide first, on how to format code in your post.
|
|
|
Re: If Statement within Update Trigger [message #407583 is a reply to message #407581] |
Wed, 10 June 2009 11:03   |
phobia42
Messages: 4 Registered: February 2008
|
Junior Member |
|
|
Didn't work, I got the following error:
ERROR line 38, col 76, ending_line 38, ending_col 80, Found 'ENDIF', Expecting: -or- (+) AT DAY MULTISET YEAR -or- ** -or- * / MOD REM -or- + - || -or- -or- ! != < <= <> = > >= ^ ^= IS NOT -or- BETWEEN IN LIKE LIKE2 LIKE4 LIKEC MEMBER SUBMULTISET -or- AND -or- OR -or- ;
|
|
|
|
|
Re: If Statement within Update Trigger (merged 2) 10g [message #407588 is a reply to message #407578] |
Wed, 10 June 2009 11:10   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
You're missing a semi-colon on several lines. EgIF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN NEW.IBP_CONTROL_OWNER_ID := NULL END IF; should beIF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN NEW.IBP_CONTROL_OWNER_ID := NULL; END IF;
Plus, as Thomas says - '01-Jan-1900' is a string.
to_date('01-Jan-1900','dd-mon-yyyy') is a date
[Too slow by seconds.... drat]
[Updated on: Wed, 10 June 2009 11:12] Report message to a moderator
|
|
|
Re: If Statement within Update Trigger [message #407589 is a reply to message #407584] |
Wed, 10 June 2009 11:10   |
phobia42
Messages: 4 Registered: February 2008
|
Junior Member |
|
|
the original had the same error, except instead of saying it found "ENDIF", it says it found "END".
Original Error Message:
ERROR line 38, col 72, ending_line 38, ending_col 74, Found 'END', Expecting: -or- (+) AT DAY MULTISET YEAR -or- ** -or- * / MOD REM -or- + - || -or- -or- ! != < <= <> = > >= ^ ^= IS NOT -or- BETWEEN IN LIKE LIKE2 LIKE4 LIKEC MEMBER SUBMULTISET -or- AND -or- OR -or- ;
|
|
|
|
|
Re: If Statement within Update Trigger (merged 2) 10g [message #407593 is a reply to message #407588] |
Wed, 10 June 2009 11:20  |
phobia42
Messages: 4 Registered: February 2008
|
Junior Member |
|
|
JRowbottom wrote on Wed, 10 June 2009 11:10 | You're missing a semi-colon on several lines. EgIF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN NEW.IBP_CONTROL_OWNER_ID := NULL END IF; should beIF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN NEW.IBP_CONTROL_OWNER_ID := NULL; END IF;
Plus, as Thomas says - '01-Jan-1900' is a string.
to_date('01-Jan-1900','dd-mon-yyyy') is a date
[Too slow by seconds.... drat]
|
That seemed to work. Thanks JRow. Guess my PL/SQL was rustier than I though, lol. The new code that seems to work:
CREATE OR REPLACE TRIGGER U_Tbl_Control_Track_Risk
BEFORE UPDATE
ON Tbl_Control_Track_Risk
FOR EACH ROW
DECLARE
BEGIN
IF :NEW.IBP_CONTROL_OWNER_ID = 0 THEN :NEW.IBP_CONTROL_OWNER_ID := NULL; END IF;
IF :NEW.BUSINESS_CONTROL_OWNER_ID = 0 THEN :NEW.BUSINESS_CONTROL_OWNER_ID := NULL; END IF;
IF :NEW.CONTROL_DEADLINE < TO_DATE('01-Jan-1900','dd-mon-yyyy') THEN :NEW.CONTROL_DEADLINE := NULL; END IF;
IF :NEW.DATE_CONTROL_IMPLEMENTED < TO_DATE('01-Jan-1900','dd-mon-yyyy') THEN :NEW.DATE_CONTROL_IMPLEMENTED := NULL; END IF;
END;
|
|
|