The below portion is the relevant part of my trigger
BEGIN SELECT rec_date
INTO lv_rec_date
FROM receipts_table
WHERE receipts_number = new.receipts_number
EXCEPTION WHEN NO_DATA_FOUND THEN
lv_partial := FALSE;
END;
The problem is that when it executes this portion, instead of capturing it nicely, I get the following error
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "APP.BEF_ROW_TRIGGER", line 66
ORA-04088: error during execution of trigger 'APP.BEF_ROW_TRIGGER'
This worked fine in Oracle 10 and below. I checked and line 66 in the USER_SOURCE for this trigger is exactly the EXCEPTION WHEN NO_DATA_FOUND THEN line. It seems to be hitting the NO_DATA_FOUND error, but the error catching doesn't seem to be working.
Are there any changes in Oracle 11g that I should be aware of?
Never mind, false alarm ^_^. The error was on line 66 of a procedure being called AFTER this section, but the error message was showing it was from the trigger. Ouch.....
Sorry for the trouble
Related
suppose in my procedure, error occurred and it went to exception block.
while entering the logs for error occurred another error takes placein exception block itself.
What happens then ...
The easiest way to find out is surely to try it?
declare
dummy integer;
begin
select 99 into dummy from all_objects; -- Will raise TOO_MANY_ROWS
exception
when too_many_rows then
select 77 into dummy from dual where 2=3; -- Will raise NO_DATA_FOUND
end;
/
When you run that you will get:
ORA-01403: no data found
ORA-06512: at line 8
I am trying to write an after insert trigger in mariadb that displays an error but doesn't undo the insert.
I read here mySQL documentation that
"If pval is anything else, p() first signals a warning and sets the message text and error number condition information items. This warning does not terminate the procedure, so execution continues and p() then signals an error. The error does terminate the procedure. The message text and error number set by the warning are replaced by the values set by the error, which are returned with the error information."
This is exactly what I'm trying to do. The trigger is just suppose to display essentially a warning, something along the lines of "insert successful... but hours > allowed_hours" but for my purpose it has to be returned as an error. Does anyone know what the documentation means by "If pval is anything else..."?
Thanks!
I am using Mysql 5.7.14. The get diagnostics statement showing error though i am using 5.7. Sample lines what i am using are something like below where i need to extract error information but unfortunately it couldn't. please help me.
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;#I HAVE TO ROOL BACK A TRASACTION WHEN EVER AN EXCEPTION OCCURS.
GET DIAGNOSTICS CONDITION 1 ERRORSTATE=RETURNED_SQLSTATE,
ERRORNUMBER=MYSQL_ERRNO, ERRORTEXT=MESSAGE_TEXT;
END;
I use this code in my stored procedure to get info on a SQLEXCEPTION:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
GET DIAGNOSTICS condition 1
#SQLState = RETURNED_SQLSTATE, #SQLMessage = MESSAGE_TEXT;
SELECT CONCAT('Database error occurred, state - ',#SQLState, '; error msg - ', #SQLMessage) INTO #errorString;
CALL Collectors_Errors
(#errorString,
'Collectors_UpdateGame',
barcodeApp,
usernameApp);
END;
The problem with this code is even though I know what the error is, it doesn't tell me at which line it occurred. And some of my sprocs are very long.
Is there a way to determine which line number, or what the line was, that caused the exception?
You can try the rdebug tool for debugging your stored procedures. I have not used it, but I find the rest of the tools in common_schema to be super helpful.
There may be an easier quick fix for finding exactly where this one error comes from, but in you are working with long stored procedures you may find rdebug to be helpful beyond this one error.
I have a procedure which accepts a parameter UserID Varchar(10). If I enter a userID which is longer than 10 characters I get the following message:
call procedure1x('Thisismorethanten'); ERROR 1406 (22001): Data too long for column 'UserID' at Row 1.
How do i create an error handler for this error so that when it happens, instead of displaying the sentence above, it says something else like "Try again. The UserID is too long."?
Error handling is typically done using TRY...CATCH block. MySQL uses DECLARE ... HANDLER to handle errors. The documentation has some sample blocks that should help you.