What is the %TYPE attribute?
What is the %TYPE attribute?
Rating:
When a PL/SQL variable is declared to hold column values, it must be ensured that the variable is of the correct datatype and precision. If not, a PL/SQL error occurs during execution. Rather than explicitly specifying the datatype and precision of a variable, the %TYPE attribute can be used to declare a variable according to another previously declared variable or database column.
The %TYPE attribute is generally used when the value stored in the variable will be derived from a table in the database. In order to use the %TYPE attribute in place of the datatype that is required in the variable declaration, the attribute is prefixed with the table name and column name. If referring to a previously declared variable, the attribute is prefixed with the name of the variable.
When a PL/SQL block consisting of such variables is compiled, the PL/SQL determines the datatype and size of the variables in order to ensure that such variables are always compatible with the column that is used to populate it. This is a definite advantage for writing and maintaining code because there is no need to be concerned about column datatype changes made at the database level.
Rating:
Other articles
- How to minimize dependency failures occurring during the recompilation of a dependent subprogram?
- What is a row trigger?
- What is an INSTEAD OF trigger?
- What is the REMOTE_DEPENDENCIES_MODE parameter?
- What is a one-time-only procedure?