Datatypes:
Each constant and variable has a datatype which specifies a storage format and valid range of values. Apart from the datatypes which are available in SQL the PL/SQL has its own collection of datatypes that can be used in PL/SQL blocks.
NUMBER Datatypes:
Numeric Datatypes are used to store represent quantities and numeric data, calculations can be performed on this datatype.
Binary_Integer:
A Binary_Integer datatype is used to store signed integers. 2147483647...2147483647 is a magnitude ranges of Binary_integer datatype. They are used to store array type of data. This type required less storage compared to Number values.
Subtypes:
A base type is the datatype from that a datatype is derived. A subtype related a base type with a constraint and so defines a subset of values. The subsequent are the list of subtypes available:
- NATURAL
- NATURALN
- POSITIVE
- POSITIVEN
- SIGNTYPE
Of these NATURAL and POSITIVE datatypes contain all positive numeric values. To avoid NULLS from being entered, POSITIVEN and NATURALN are used. The SIGNTYPE restricts an integer variables to the value 1,-1 or 0 depending on the kinds of the value entered.
Writing a Simple Program
The subsequent example is used to display a message known as 'WELCOME TO THE WORLD OF PL/SQL'.
BEGIN
DBMS_OUTPUT.PUT_LINE('WELCOME TO THE WORLD OF PL/SQL'); END;
Note In the program there is no DECLARE part because the program does not use any variable declaration. A Declarative section is needed only when variables are to be used like the subsequent example:
Example
DECLARE
x NUMBER;
BEGIN
x:=56;
DBMS_OUTPUT.PUT_LINE (x);
END;
The given above example displays the value 56 that is stored in the variable x. In sequence to accept the value at run-time the assignment operator has to be used.
Note: While DBMS_OUTPUT.PUT_LINE is used to display messages and the messages will not be displayed unless the environment setting known as SET SERVEROUTPUT is turned on. That is a SQL Plus statement.
Example
DECLARE
x NUMBER;
BEGIN
x:=&numb;
DBMS_OUTPUT.PUT_LINE (x);
END;
The & operator (assignment) is used to accept the value in the numb variable and this value assigned to x.