Errors and Messages
Error Statement
An ERROR
statement declares that the procedure has entered an error state and should abort. This statement will also roll back the current transaction if one exists. Any valid expression can be specified after the ERROR
keyword.
Usage
|
Example
BEGIN
...
ERROR 'Invalid input value: ' || nvl(Acct.GetBalance.AcctID, 'null');
END
An ERROR
statement is equivalent to the following statement:
RAISE SQLEXCEPTION message;
Raise Statement
A RAISE
statement is used to raise an exception or warning. When raising an exception, this statement will also roll back the current transaction, if one exists.
Usage
RAISE [SQLWARNING] exception;
Where exception
may be a variable reference to an exception or an exception expression.
Syntax
- If
SQLWARNING
is specified, the exception will be sent to the client as a warning, and the procedure will continue to execute; - A null warning will be ignored. A null non-warning exception will still cause an exception to be raised.
Example
BEGIN
RAISE SQLWARNING SQLEXCEPTION 'invalid' SQLSTATE '05000';
END
Exception Expression
An exception expression creates an exception that can be raised or used as a warning.
Usage
SQLEXCEPTION message [SQLSTATE state [, code]] CHAIN exception
Syntax
- Any of the values may be
null
; - Message and state are string expressions specifying the exception message and SQL state, respectively. The Data Virtuality Server does not yet fully comply with the ANSI SQL specification on SQL state usage, but you are allowed to set any SQL state you choose;
- Code is an integer expression specifying the vendor code;
- Exception must be a variable reference to an exception or an exception expression and will be chained to the resulting exception as its parent.