If you want declare a variable and it’s data type is same as one column’s data type in one some table then you use scalar attribute.
The above data type in PL/SQL provides a scalar attribute %type.
Example – 4 attr.sql
SET VERIFY OFF
SET SERVEROUTPUT ON
CL SCR
DECLARE
VEMPNO EMP.EMPNO%TYPE;
VENAME EMP.ENAME%TYPE;
VSAL EMP.SAL%TYPE;
BEGIN
SELECT EMPNO, ENAME,SAL
INTO VEMPNO,VENAME, VSAL
FROM EMP WHERE ENAME = '&ENAME';
DBMS_OUTPUT.PUT_LINE('Employee Number : '||vempno);
DBMS_OUTPUT.PUT_LINE('Employee Name : '||vename);
DBMS_OUTPUT.PUT_LINE('Employee Salary : '||vsal);
END;
/
SQL>@ attr.sql
Enter value for ename: KING
Employee Number : 7839
Employee Name : KING
Employee Salary : 5000
PL/SQL procedure successfully completed
The above data type in PL/SQL provides a scalar attribute %type.
Example – 4 attr.sql
SET VERIFY OFF
SET SERVEROUTPUT ON
CL SCR
DECLARE
VEMPNO EMP.EMPNO%TYPE;
VENAME EMP.ENAME%TYPE;
VSAL EMP.SAL%TYPE;
BEGIN
SELECT EMPNO, ENAME,SAL
INTO VEMPNO,VENAME, VSAL
FROM EMP WHERE ENAME = '&ENAME';
DBMS_OUTPUT.PUT_LINE('Employee Number : '||vempno);
DBMS_OUTPUT.PUT_LINE('Employee Name : '||vename);
DBMS_OUTPUT.PUT_LINE('Employee Salary : '||vsal);
END;
/
SQL>@ attr.sql
Enter value for ename: KING
Employee Number : 7839
Employee Name : KING
Employee Salary : 5000
PL/SQL procedure successfully completed