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 only error number
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 parameters).
DBMS_SYS_ERROR.RAISE_SYSTEM_ERROR(
num BINARY_INTEGER,
arg1 VARCHAR2,
arg2 VARCHAR2,
...
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:TRUEWhen appending errors, retain the current error stack and add the new error. Default isFALSE. |
Usage instructions
- The
PRAGMA RESTRICT_REFERENCESconstraint for theRAISE_SYSTEM_ERRORprocedure isWNDS,RNDS,WNPS, orRNPS, 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
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);
END IF;
END;
/
