Total Pageviews

December 27, 2017

12/27/2017 11:45:00 AM
Data Type :NATURAL

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_NO NATURAL;

  BEGIN
  L_NO := -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_NO1 NATURAL;
L_NO2 NATURAL;

BEGIN
L_NO1 := 10;
L_NO2 := NULL;

END;

/

PL/SQL procedure successfully completed.
x
 
Related Posts Plugin for WordPress, Blogger...