%TYPE and %ROWTYPE in Oracle?
Both are Oracle key words, used to
inherit the data types of, variables defined earlier in
PL/SQL program, or from a column of table or
view.
% TYPE acquire the data type
of a variable or a database column.
Example :
declare
Sal employee.salary%TYPE;
Example :
declare
Sal employee.salary%TYPE;
begin
NULL;
end;
/
Here in the above example we have defined a variable sal which acquired data type from column salary of table employee.
NULL;
end;
/
Here in the above example we have defined a variable sal which acquired data type from column salary of table employee.
% ROWTYPE acquire the record
type that represents a entire row of a table or view or columns
selected in the cursor. Below is the syntax for this :
rowtype_attribute
:= {cursor_name | cursor_variable_name | table_name}%ROWTYPE
Example :
declare
rec_emp employee%RowType;
begin
end;
/
Example :
declare
rec_emp employee%RowType;
begin
end;
/
Here in the above example we have created a record type just similar to the record of employee table.
Advantage :
Advantage :
The major advantage using this approach
to define variables in PL/SQL programs is in case any modification in
definition of a column in a table, the data type of a variable
changes accordingly.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home