The RAISE_SYSTEM_ERROR procedure is used to raise a user-defined system error in a PL program.
Applicability
This content applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition does not support it.
Syntax
The RAISE_SYSTEM_ERROR procedure supports the following overloads:
-- Specify Error Code Only
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(
num BINARY_INTEGER,
keeperrorstack BOOLEAN DEFAULT FALSE);
-- Specify the error number and one parameter.
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(
num BINARY_INTEGER,
arg1 VARCHAR2,
keeperrorstack BOOLEAN DEFAULT FALSE);
-- Specify the error number and two parameters.
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(
num BINARY_INTEGER,
arg1 VARCHAR2,
arg2 VARCHAR2,
keeperrorstack BOOLEAN DEFAULT FALSE);
-- Specify the error number and up to N parameters (a maximum of 8).
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(
num BINARY_INTEGER,
arg1 VARCHAR2,
arg2 VARCHAR2,
...
argN VARCHAR2,
keeperrorstack BOOLEAN DEFAULT FALSE);
...
argN VARCHAR2, keeperrorstack BOOLEAN DEFAULT FALSE);
## Parameters
| Parameter | Description |
| ------ | ------ |
| num | Error number. |
| arg1 ... argN | The error message can contain up to eight parameters (`arg1` ~ `arg8`). |
| keeperrorstack | Whether to retain the error stack. Valid values:`TRUE`When appending errors, retain the current error stack and add the new error. Default is`FALSE`. |
## Usage instructions
* The `PRAGMA RESTRICT_REFERENCES` constraint for the `RAISE_SYSTEM_ERROR` procedure is `WNDS`, `RNDS`, `WNPS`, or `RNPS`, indicating that this procedure does not read from or write to the database state, nor does it modify package states.
* Suitable for scenarios where specific error codes need to be thrown in custom logic.
## Examples
```sql
DECLARE
v_emp_id NUMBER := -1;
BEGIN
IF v_emp_id < 0 THEN
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(-20001, 'Invalid employee ID: ' || v_emp_id);