Home > database > MySql how to get the message of the exception (such as oracle sqlerrm or essentially ERROR_MESSAGE (
MySql how to get the message of the exception (such as oracle sqlerrm or essentially ERROR_MESSAGE (
Time:10-31
- 1. In oracle, write a stored procedure (for the exception message)
Create procedure (XXX) As The begin
.
The exception The when others then Dbms_output (' exception code: '| | SQLCODE | |' abnormal information: '| | SQLERRM);
The END;
- 2. Essentially, write a stored procedure (for the exception message)
Create procedure (XXX) As The begin
. The BEGIN CATCH SELECT @ Msg=error message: '+ ERROR_MESSAGE (); END the CATCH END
- get complete information example:
BEGIN the TRY - Generate a divide - by - zero error. The SELECT 1/0; END the TRY The BEGIN CATCH SELECT ERROR_NUMBER () AS ErrorNumber ERROR_SEVERITY () AS ErrorSeverity ERROR_STATE () AS ErrorState AS ErrorProcedure, ERROR_PROCEDURE () ERROR_LINE () AS ErrorLine ERROR_MESSAGE () AS ErrorMessage; END the CATCH;
-- -- -- -- -- -- -- -- -- -- -- --
But in mysql, as if no such method direct access to system's own code and the anomaly information; If not,
- in the case of mysql for abnormal
Create procedure XXX (p_json varchar2 (2000), the out p_msg varchar (200)) The begin
. DECLARE Invalid_JSON CONDITION FOR 3141; - 314 is the json format is wrong;
DECLARE the EXIT HANDLER FOR Invalid_JSON The BEGIN Set @ errorMsg='parse json error - only handwritten error message and can not use like oracle MESSAGE_TEXT or essentially ERROR_MESSAGE ();
The END; The SET @ CNT=JSON_LENGTH (p_Json); - get a json array number, if the json format is wrong, will trigger 3141 this exception; . The END;
CodePudding user response:
Condition_value: SQLSTATE VALUE] [sqlstate_value | condition_name | SQLWARNING | NOT FOUND | SQLEXCEPTION | mysql_error_code
CodePudding user response:
Thanks brother's help, upstairs also have I seen such a specification, but seems to be short of oracle or used to that kind of effect;