PL-SQL
Top 65 PL/SQL Interview Questions & Answers
Download PDF 1) What is PL SQL ? PL SQL is a procedural language which has interactive SQL, as well as...
A data type is associated with the specific storage format and range constraints. In Oracle, each value or constant is assigned with a data type.
Basically, it defines how the data is stored, handled and treated by Oracle during the data storage and processing.
The main difference between PL/SQL and SQL data types is, SQL data type are limited to table column while the PL/SQL data types are used in the PL/SQL blocks. More on this later in the tutorial.
Following is the diagram of different Data Types in PL/SQL
In this tutorial, you will learn-
This data type basically stores alphanumeric characters in string format.
The literal values should always be enclosed in single quotes while assigning them to CHARACTER data type.
This character data type is further classified as follows:
| Data Type | Description | Syntax |
|---|---|---|
| CHAR | This data type stores the string value, and the size of the string is fixed at the time of declaring the variable.
| grade CHAR; manager CHAR (10):= 'gtupapers';Syntax Explanation:
|
| VARCHAR2 | This data type stores the string, but the length of the string is not fixed.
| manager VARCHAR2(10) := ‘gtupapers';Syntax Explanation:
|
| VARCHAR | This is synonymous with the VARCHAR2 data type.
| manager VARCHAR(10) := ‘gtupapers';Syntax Explanation:
|
| NCHAR | This data type is same as CHAR data type, but the character set will of the national character set.
| native NCHAR(10);Syntax Explanation:
|
| NVARCHAR2 | This data type is same as VARCHAR2 data type, but the character set will be of the national character set.
| Native var NVARCHAR2(10):='gtupapers';Syntax Explanation:
|
| LONG and LONGRAW | This data type is used to store large text or raw data up to the maximum size of 2GB.
| Large_text LONG; Large_raw LONG RAW;Syntax Explanation:
|
This data type stores fixed or floating point numbers up to 38 digits of precision. This data type is used to work with fields which will contain only number data. The variable can be declared either with precision and decimal digit details or without this information. Values need not enclose within quotes while assigning for this data type.
A NUMBER(8,2); B NUMBER(8); C NUMBER;
Syntax Explanation:
This data type stores the logical values. It represents either TRUE or FALSE and mainly used in conditional statements. Values need not enclose within quotes while assigning for this data type.
Var1 BOOLEAN;
Syntax Explanation:
This data type stores the values in date format, as date, month, and year. Whenever a variable is defined with DATE data type along with the date it can hold time information and by default time information is set to 12:00:00 if not specified. Values need to enclose within quotes while assigning for this data type.
The standard Oracle time format for input and output is 'DD-MON-YY' and it is again set at NLS_PARAMETERS (NLS_DATE_FORMAT) at the session level.
newyear DATE:='01-JAN-2015'; current_date DATE:=SYSDATE;
Syntax Explanation:
This data type is mainly used to store and manipulate large blocks of unstructured data's like images, multimedia files, etc. Oracle prefers LOB instead of the a LONG data type as it is more flexible than the LONG data type. The below are the few main advantage of LOB over LONG data type.
So, it is always good to use LOB data type instead of the LONG data type. Following are the different LOB data types. They can store up to the size of 128 terabytes.
| Data Type | Description | Syntax |
|---|---|---|
| BLOB | This data type stores the LOB data in the binary file format up to the maximum size of 128 TB. This doesn't store data based on the character set details, so that it can store the unstructured data such as multimedia objects, images, etc. | Binary_data BLOB; Syntax Explanation:
|
| CLOB and NCLOB | CLOB data type stores the LOB data into the character set, whereas NCLOB stores the data in the native character set. Since these data types use character set based storage, these cannot store the data like multimedia, images, etc. that cannot be put into a character string. The maximum size of these data types is 128 TB. | Charac_data CLOB; Syntax Explanation:
|
| BFILE |
| |
We have covered the different simple data types that are available in PL/SQL along with their syntax. We will learn about complex data types in further topics.
Download PDF 1) What is PL SQL ? PL SQL is a procedural language which has interactive SQL, as well as...
What is Package in Oracle? PL/SQL package is a logical grouping of a related subprogram...
What is Object Type in PL/SQL? Object-Oriented Programming is especially suited for building...
In this tutorial, you are going to see the detailed description on how to create and execute the...
What is Exception Handling in PL/SQL? An exception occurs when the PL/SQL engine encounters an...
What is CURSOR in PL/SQL? A Cursor is a pointer to this context area. Oracle creates context area...