What is the difference between %type and %rowtype?

Questions by neelamanu

Showing Answers 1 - 10 of 10 Answers

Anurag Puranik

  • Jul 22nd, 2006
 

The % type variable is used as a datatype of a pl/sql variable which show that  the datatype of pl/sql variable is same as the datatype of sql varaible. 

while the %rowtype is used as the variable which is the same as the row of that table means contain all the columns of the table.

  Was this answer useful?  Yes

BinduJoseph

  • Jan 22nd, 2007
 

 

%TYPE is used to declare a field with the same type as that of a specified table's column. Example:

DECLARE   v_EmpName  emp.ename%TYPE;BEGIN   SELECT ename INTO v_EmpName FROM emp WHERE ROWNUM = 1;   DBMS_OUTPUT.PUT_LINE('Name = ' || v_EmpName);END;/

 

%ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor. Examples:

DECLARE  v_emp emp%ROWTYPE;BEGIN  v_emp.empno := 10;  v_emp.ename := 'XXXXXXX';END;/

  Was this answer useful?  Yes

BASVARAJ KOLUR

  • Mar 8th, 2007
 

the %type will return datatyp attached to refernced column or item
ex: v_a emp.empid%type;

it will return datatype attched to empid of emp table.
 
the %rowtype will return all datatype attached every columns of table. its like record type.

ex: emp_rec emp%rowtype;

it will returns all datatypes attached to emp table.

  Was this answer useful?  Yes

%tye and %rowtype provide data independence and allows programs to adapt to database changes due to new business requirement.

%type is used to declare a variable with same datatype as that of a column in a table.
%rowtype is used to declare a record variable with the same type as that of a row in a database table.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions