0% found this document useful (0 votes)
16 views3 pages

PL - SQL Record Type

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

PL - SQL Record Type

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

What is Record Type?

A Record type is a complex data type that allows the programmer to


create a new data type with the desired column structure.
● It groups one or more columns to form a new data type
● These columns will have its own name and data type
● A Record type can accept the data
● As a single record that consists of many columns OR
● It can accept the value for one particular column of a record
● Record type simply means a new data type. Once the record
type is created, it will be stored as a new data type in the
database and the same shall be used to declare a variable in
programs.
● It will use the keyword ‘TYPE’ to instruct the compiler that it is
creating the new data type.
● It can be created at the “database level” which can be stored as
database objects, and used all over the database or it can be
created at the “subprogram levels”, which is visible only inside
the subprograms.
● The database-level record type can also be declared for the
table columns so that a single column can hold the complex
data.
● The data in these data types can be accessed by referring to
their variable_name followed by the period operator (.) followed
by column_name i.e.
‘<record_type_variable_name>.<column_name>’
Syntax for declaration at the database level:

CREATE TYPE <type_name_db> IS RECORD


(
<column 1> <datatype>,
);

In the first syntax, we can see the keyword ‘CREATE TYPE’ this
instructs the compiler to create the record type named
“type_name_db” with the specified column as a database object.
This is given as an individual statement and not inside any block.

Example: RECORD Type as Database Object

In this program, we are going to see how to create “Record type” as a


database object. We are going to create record type ’emp_det’ with
four columns. The columns and their data type are as follows:
● EMP_NO (NUMBER)
● EMP_NAME (VARCHAR2 (150))
● MANAGER (NUMBER)
● SALARY (NUMBER)

CREATE TYPE emp_det IS OBJECT


(
EMP_NO NUMBER,
EMP_NAME VARCHAR2(150),
MANAGER NUMBER,
SALARY NUMBER
);
/
Output:
Type created

You might also like