RAISE_ERROR Function
Description
The RAISE_ERROR function throws a runtime error during query execution and aborts the query. This function accepts an error message string as a parameter. When the function is executed, it throws an exception and displays the specified error message. It is often used in combination with the IF function to terminate query execution when specific conditions are met.
Parameters
message:STRINGtype, the error message content. If the parameter isNULL, "null message" is displayed.
Return Type
- This function does not return a normal value.
- Throws an exception and aborts the query upon execution.
- The error message includes the provided
messageparameter.
Notes
- This function aborts query execution and should be used with caution.
- When used in production environments, ensure it is only triggered in necessary validation scenarios.
- Error messages should be clear and explicit for easier troubleshooting.
- A
NULLparameter will display "null message"; avoid passingNULL.
Examples
- Combined with IF: conditional error checking
- Using in CASE WHEN
