Oracle PL/SQL Data Types: Boolean, Number, Date [Example]
โก Smart Summary
PL/SQL Data Types define how Oracle stores, handles, and constrains each value in a block. They group into character, number, Boolean, date, and large object (LOB) families, each with its own storage format, size limits, and assignment rules.

What are PL/SQL Data Types?
Data types in PL/SQL define how data will be stored, handled, and treated by Oracle during storage and processing. Data types are associated with a specific storage format and range constraints. In Oracle, each value or constant is assigned a data type.
The main difference between PL/SQL and SQL data types is that SQL data types are limited to table columns, while PL/SQL data types are used in the PL/SQL blocks. More on this later in the tutorial.
Following is a diagram of the different Oracle PL/SQL data types:

PL/SQL CHARACTER Data Type
This data type stores alphanumeric characters in string format. The literal values should always be enclosed in single quotes when assigning them to a CHARACTER data type.
This character data type is further classified as follows:
- CHAR data type (fixed string size)
- VARCHAR2 data type (variable string size)
- VARCHAR data type
- NCHAR (native fixed string size)
- NVARCHAR2 (native variable string size)
- LONG and LONG RAW
| Data Type | Description | Syntax |
|---|---|---|
| CHAR | This data type stores a string value, and the size of the string is fixed at the time of declaring the variable.
|
grade CHAR; manager CHAR (10):= 'guru99'; Syntax Explanation:
|
| VARCHAR2 | This data type stores a string, but the length is not fixed.
|
manager VARCHAR2(10) := 'guru99'; Syntax Explanation:
|
| VARCHAR | This is synonymous with the VARCHAR2 data type.
|
manager VARCHAR(10) := 'guru99'; Syntax Explanation:
|
| NCHAR | This data type is the same as CHAR, but the character set is the national character set.
|
native NCHAR(10);
Syntax Explanation:
|
| NVARCHAR2 | This data type is the same as VARCHAR2, but the character set is the national character set.
|
Native_var NVARCHAR2(10):= 'guru99'; Syntax Explanation:
|
| LONG and LONG RAW | This data type stores large text or raw data up to a maximum size of 2 GB.
|
Large_text LONG; Large_raw LONG RAW; Syntax Explanation:
Note: Using the LONG data type is not recommended by Oracle. The LOB data type should be preferred instead. |
PL/SQL NUMBER Data Type
This data type stores fixed or floating point numbers up to 38 digits of precision. It is used to work with fields that contain only number data. The variable can be declared either with precision and decimal digit details or without them. Values need not be enclosed in quotes when assigned.
A NUMBER(8,2); B NUMBER(8); C NUMBER;
Syntax Explanation:
- The first declaration declares the variable ‘A’ of number data type with total precision 8 and 2 decimal digits.
- The second declares ‘B’ of number data type with total precision 8 and no decimal digits.
- The third is the most generic, declaring ‘C’ of number data type with no restriction on precision or decimals. It can take up to 38 digits.
PL/SQL BOOLEAN Data Type
This data type stores logical values. The Oracle Boolean data type represents either TRUE or FALSE and is used mainly in conditional statements. Values need not be enclosed in quotes when assigned.
Var1 BOOLEAN;
Syntax Explanation:
- The variable ‘Var1’ is declared as BOOLEAN data type. The output will be either true or false based on the condition set.
PL/SQL DATE Data Type
This data type stores values in date format, as date, month, and year. Whenever a variable is defined with DATE data type, it can hold time information; by default the time is set to 12:00:00 if not specified. Values need to be enclosed in quotes when assigned.
The standard Oracle time format for input and output is ‘DD-MON-YY’, which is set at NLS_PARAMETERS (NLS_DATE_FORMAT) at the session level.
newyear DATE:= '01-JAN-2015'; current_date DATE:= SYSDATE;
Syntax Explanation:
- The variable ‘newyear’ is declared as DATE data type and assigned the value of 1 January 2015.
- The second declaration declares ‘current_date’ as DATE data type and assigns the current system date.
- Both variables hold time information.
PL/SQL LOB Data Type
This data type is mainly used to store and manipulate large blocks of unstructured data such as images and multimedia files. Oracle prefers LOB over the LONG data type because it is more flexible. The main advantages of LOB over LONG are:
- A table is limited to one LONG column, whereas there is no restriction on the number of LOB columns.
- Data interface tools accept LOB during replication but omit LONG columns, which must be replicated manually.
- A LONG column stores up to 2 GB, whereas a LOB can store up to 128 TB.
- Oracle keeps improving the LOB data type with each release, whereas LONG is largely unchanged.
So it is always good to use the LOB data type instead of LONG. The different LOB data types below can store up to 128 terabytes:
- BLOB
- CLOB and NCLOB
- BFILE
| Data Type | Description | Syntax |
|---|---|---|
| BLOB | This data type stores LOB data in binary file format up to a maximum of 128 TB. It does not store data based on character set details, so it can store unstructured data such as multimedia objects and images. |
Binary_data BLOB;
Syntax Explanation:
|
| CLOB and NCLOB | CLOB stores LOB data in the character set, whereas NCLOB stores data in the native character set. Because these use character set based storage, they cannot store data like multimedia or images. The maximum size is 128 TB. |
Charac_data CLOB;
Syntax Explanation:
|
| BFILE |
|
