![]() |
VOOZH | about |
PL/SQL provides data types to define the kind of data that can be stored in table columns efficiently and accurately.
Scalar data types are basic types that store only one value at a time, like numbers, characters or even logical values each representing an individual value. The scalar data types are categorized into:
| Data Type | Description |
|---|---|
| Numeric Types | Stores numbers and decimal values. |
| Character Types | Stores text and strings. |
| Boolean Types | Stores TRUE or FALSE. |
| Datetime Types | Stores date and time values. |
Subtypes are defined based on the base scalar types and are formed by placing additional constraints upon values that can be assigned.
Numeric data types store numbers, both integers and real numbers and allow developers to perform arithmetic operations. The main numeric types include:
| Data Type | Description |
|---|---|
| NUMBER | Stores fixed-point and floating-point numbers with precision and scale. |
| BINARY_INTEGER | Stores signed integer values efficiently. |
| FLOAT | Stores floating-point numbers with optional precision. |
For Example:
DECLARE
num1 NUMBER(5,2) := 123.45;
num2 PLS_INTEGER := 100;
num3 FLOAT(10) := 45.67;
BEGIN
DBMS_OUTPUT.PUT_LINE(num1);
DBMS_OUTPUT.PUT_LINE(num2);
DBMS_OUTPUT.PUT_LINE(num3);
END;
/Character data types are used to store text, numbers and symbols in alphanumeric form. They are mainly used for storing and manipulating strings in PL/SQL.
| Data Type | Description |
|---|---|
| CHAR | Stores fixed-length character strings. |
| VARCHAR2 | Stores variable-length character strings. |
| LONG | Stores very large character strings (deprecated). |
For Example:
DECLARE
str1 CHAR(10) := 'Hello';
str2 VARCHAR2(20) := 'Welcome';
str3 LONG := 'This is a long text';
BEGIN
DBMS_OUTPUT.PUT_LINE(str1);
DBMS_OUTPUT.PUT_LINE(str2);
DBMS_OUTPUT.PUT_LINE(str3);
END;
/A PL/SQL-only data type used to store logical values. It can have three values: TRUE, FALSE or NULL and is mainly used in conditions and comparisons. It helps in controlling program flow using conditional statements like IF and WHILE.
For Example:
DECLARE
a BOOLEAN := TRUE;
BEGIN
IF a THEN
DBMS_OUTPUT.PUT_LINE('TRUE');
END IF;
END;Datetime data types store date and time values, while interval data types store the difference between two date and time values. PL/SQL provides different datetime and interval data types:
| Data Type | Description |
|---|---|
DATE | Stores date and time values. |
TIMESTAMP | Stores date and time with fractional seconds. |
TIMESTAMP WITH TIME ZONE | Stores timestamp with time zone. |
TIMESTAMP WITH LOCAL TIME ZONE | Stores timestamp based on local session time zone. |
INTERVAL YEAR TO MONTH | Stores time in years and months. |
INTERVAL DAY TO SECOND | Stores time in days, hours, minutes and seconds. |
LOB data types store large amounts of unstructured data, such as text, images, videos and audio. PL/SQL provides several LOB types:
| Data Type | Description |
|---|---|
BLOB | Stores binary files like images and videos. |
CLOB | Stores large text data. |
NCLOB | Stores large text data in national character set. |
| BFILE | Stores reference to a binary file outside the database. |