hurry up:oracle 游标变量与record之间的匹配

Mr_joy 2013-01-17 02:28:27
我创建了一个如下的存储过程:
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让它能跟游标导出的数据相匹配呢?

最后恳请大神们踊跃回答,谢谢。
...全文
540 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
foolish_cc1986 2013-01-18
  • 打赏
  • 举报
回复
引用 2 楼 Mr_joy 的回复:
引用 1 楼 foolish_cc1986 的回复:SQL code?12345678910111213141516171819create or replace procedure myProcedure(std_id in varchar2) is type mark_record_type is RECORD( mark_sno SC.SNO%TYPE,……
是呀。。。这只是定义一个符合变量类型而已。。并不是定义变量的
Mr_joy 2013-01-17
  • 打赏
  • 举报
回复
引用 1 楼 foolish_cc1986 的回复:
SQL code?12345678910111213141516171819create 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……
我晕,难道说type sth is record(...)只是定义了一种类型,而不是可以使用的变量... 谢谢了。。。
foolish_cc1986 2013-01-17
  • 打赏
  • 举报
回复

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;
测试了下这样子么问题。

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧