Definition:
In Oracle PL/SQL, NATURAL is a 32 bit sub datatype derived from BINARY_INTEGER. It allows positive integers or NULL values. (To prevent the assigning of nulls to an integer variable, use NATURALN or POSITIVEN.)
Note that NATURAL is a PL/SQL number type and cannot be used in SQL.
Example Usage:
The PL/SQL block below shows that the NATURAL variable cannot contain negative values.
SQL> DECLARE
L_NUM NATURAL;
BEGIN
L_NUM := -1;
END;
/
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 4
The PL/SQL block below shows how NATURAL can be assigned with NULL and positive numbers only.
DECLARE
L_NUM1 NATURAL;
L_NUM2 NATURAL;
BEGIN
L_NUM1 := 10;
L_NUM2 := NULL;
END;
/
PL/SQL procedure successfully completed.
Related Links:
Related Code Snippets: