%ROWTYPE-cursors

 %ROWTYPE evaluates to the type attribute of cursors and database table rows. The following covers database table row.
A declared record structure can contain a component for each column in a database table. The syntax is:

structure_name  [schema.]table_name%ROWTYPE;

Example
A cursor that selects columns from a single table can select into a record declared like:

type rec_type is record
     ( emp_id emp.emp_id%TYPE,
       ...    emp...%TYPE,
       name   emp.emp_name%TYPE );
rec rec_type;  -- record declaration
CURSOR c1 is SELECT * FROM EMP WHERE ...
LOOP
      ...
   FETCH INTO rec;  -- fetch into the record
      ...
END LOOP;
As an alternative we can remove the record type definition and declare a record whose type is derived from EMP:

   type rec_type is record (         THIS DEFINITION IS NO        
        emp_id emp.emp_id%TYPE,      LONGER NEEDED FOR THIS       
        ...    emp...%TYPE,          PROGRAM.                     
        name   emp.emp_name%TYPE );                               
CURSOR c1 is * FROM EMP WHERE ...
rec EMP%ROWTYPE;  -- record declaration that uses EMP.
                  -- There is no change to any other code.
 -- We just changed record declarations.
LOOP
      ...
   FETCH INTO rec;  -- fetch into the record
      ...
END LOOP;
There three ways to declare a composite record type structure in PL/SQL:

Records
%ROWTYPE of a cursor
%ROWTYPE of a table
The following questions will help you decide which way to declare a composite record type structure in PL/SQL.

Questions to ask:

Does the SELECT query return columns from more than one table?

If YES - more than one table:

RECORD     cursor%TYPE     table%ROWTYPE
can do          can do                  won't do


If NO - just one table:

RECORD        cursor%TYPE       table%ROWTYPE
can do             can do                    can do
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值