Use of %TYPE Attribute

What is use of %TYPE Attribute


  • Is used to declare a variable according to:
  • A database column definition
  • Another declared variable
  • Is prefixed with:
    –The database table and column
    –The name of the declared variable

Example:Using database table column type

emp_lname employees.last_name%TYPE;

Example: Using another variable

balance NUMBER(7,2);
min_balance balance%TYPE := 1000;

Example:

DECLARE
v_lname employees.last_name%type;
BEGIN
SELECT last_name INTO v_lname
FROM employees
WHERE employee_id='100';
DBMS_OUTPUT.PUT_LINE ('Last_name :'||v_lname);
END;

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *