PL/SQL NUMBER

The Oracle PL/SQL NUMBER data type is used to store numeric values. It can be either an integer or a decimal number.

Syntax

The syntax for the NUMBER data type is as follows:

number
number(38)
number(10,2)

The first form, “number”, stores up to 38 digits. The second form, “number(38)”, stores up to 38 digits with a precision of 38. The third form, “number(10,2)”, stores up to 10 digits with a precision of 2.

Examples

The following is an example of how to declare and initialize a PL/SQL NUMBER variable in Oracle database:

declare
v_num number:=10;
begin
DBMS_OUTPUT.PUT_LINE('v_num = '||v_num);
end;

You can also perform arithmetic operations on PL/SQL NUMBER variables. The following is an example of how to add two NUMBER variables in Oracle database:

declare
v_num1 number:=10;
v_num2 number(10,2):=20.22;
v_result number;
begin
v_result := v_num1 + v_num2;
DBMS_OUTPUT.PUT_LINE('v_result = '||v_result);
end;

The output of the above code would be: 30,22.