日期:2014-05-17  浏览次数:20893 次

hurry up:oracle 游标变量与record之间的匹配
我创建了一个如下的存储过程:
create or replace procedure myProcedure(std_id in varchar2)
is
/*type mark_record is RECORD

  mark_sno SC.SNO%TYPE,
  mark_cno SC.CNO%TYPE,
  mark_score SC.SCORE%TYPE
);*/
mark_record SC%ROWTYPE;
type sc_cursor is ref cursor;
my_cursor sc_cursor;
total_mark number;
avg_mark number;
max_mark number;
min_mark number;
begin
open my_cursor for select sno,cno,score from SC where sno=std_id;
fetch my_cursor into mark_record;
close my_cursor;
end;
这样是正确的,但如果把mark_record换成/*..*/的内容发生错误。错误如下:
Warning: 执行完毕, 但带有警告
17/22          PLS-00321: 赋值语句左边的表达式 'MARK_RECORD' 不正确
17/1           PL/SQL: SQL Statement ignored

让我费解的是record内容明明就一样啊,也符合fetch into后面的类型一一对应啊,怎么就编译不成功呢?

再者 如果我只想取表的某些字段,那我又要再怎么定义这个record让它能跟游标导出的数据相匹配呢?

最后恳请大神们踊跃回答,谢谢。
oracle?游标?存储过程 oracle 游标 存储过程

------解决方案--------------------

create or replace procedure myProcedure(std_id in varchar2) is
  type mark_record_type is RECORD(
    mark_sno   SC.SNO%TYPE,
    mark_cno   SC.CNO%TYPE,
    mark_score SC.SCORE%TYPE);
  mark_record mark_record_type;
  type sc_cursor is ref cursor;
  my_cursor  sc_cursor;
  total_mark number;
  avg_mark   number;
  max_mark   number;
  min_mark   number;
begin
  open my_cursor for
    select sno, cno, score from SC where sno = std_id;
  fetch my_cursor
    into mark_record;
  close my_cursor;
end;

测试了下这样子么问题。