我创建了一个如下的存储过程:
create or replace procedure myProcedure(std_id in varchar2)
is
/*type _record is RECORD

  _sno SC.SNO%TYPE,
  _cno SC.CNO%TYPE,
  _score SC.SCORE%TYPE
);*/
_record SC%ROWTYPE;
type sc_cursor is ref cursor;
my_cursor sc_cursor;
total_ number;
avg_ number;
max_ number;
min_ number;
begin
open my_cursor for select sno,cno,score from SC where sno=std_id;
fetch my_cursor into _record;
close my_cursor;
end;
这样是正确的,但如果把_record换成/*..*/的内容发生错误。错误如下:
Warning: 执行完毕, 但带有警告
17/22          PLS-00321: 赋值语句左边的表达式 'MARK_RECORD' 不正确
17/1           PL/SQL: SQL Statement ignored让我费解的是record内容明明就一样啊,也符合fetch into后面的类型一一对应啊,怎么就编译不成功呢?再者 如果我只想取表的某些字段,那我又要再怎么定义这个record让它能跟游标导出的数据相匹配呢?最后恳请大神们踊跃回答,谢谢。oracle 游标 存储过程oracle游标存储过程

解决方案 »

  1.   


    create or replace procedure myProcedure(std_id in varchar2) is
      type _record_type is RECORD(
        _sno   SC.SNO%TYPE,
        _cno   SC.CNO%TYPE,
        _score SC.SCORE%TYPE);
      _record _record_type;
      type sc_cursor is ref cursor;
      my_cursor  sc_cursor;
      total_ number;
      avg_   number;
      max_   number;
      min_   number;
    begin
      open my_cursor for
        select sno, cno, score from SC where sno = std_id;
      fetch my_cursor
        into _record;
      close my_cursor;
    end;测试了下这样子么问题。
      

  2.   


    我晕,难道说type sth is record(...)只是定义了一种类型,而不是可以使用的变量...
    谢谢了