Translate

Difference Between %TYPE and %ROWTYPE

%TYPE Vs. %RowType
  • %TYPE  provides  the data type of a variable or a database column to that variable. 
  • %ROWTYPE  provides the record type that represents a entire row of a table or view or columns selected in the cursor. 

The Advantages are:
  • I Need not to know about variable's data type. 
  • If the database definition of a column in a table changes, the data type of a variable changes accordingly.

%TYPE is used to declare a field with the same type as that of a specified table's column:
o   DECLARE
o   v_EmpName  emp.ename%TYPE;
o   BEGIN
o      SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1;
o      DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName);
o   END;
o   /

%ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor:
o   DECLARE
o    v_emp emp%ROWTYPE;
o   BEGIN
o     v_emp.empno := 10;
o     v_emp.ename := 'XXXXXXX';
o   END;

o   /





1 comment: