题目是:输入学生编号,将学生的所有课程成绩打印出来
用到的表 student 学生表
         course 课程表
         grade 成绩表
过程如下:
create or replace procedure my_pro
(param1 in number)
as
info_stu varchar2(10000);
begin
select s.stuname,c.couname,g.grade into info_stu from student s,course c,grade g
where s.stuid=g.stuid and c.couid=g.couid and g.stuid = param1;
dbms_output.put_line(info_stu);
end;
oracle 报出没有足够的值 请问是哪里的问题呢? 语法逻辑已经测试没错。是不是查出来的值 放进INFO_STU类型错误 怎么设置变量呢

解决方案 »

  1.   

    s.stuname,c.couname,g.grade into info_stu  
    是这里的问题,你可以写两个查询语句,第一个得到info_stu,第二个关联查询
      

  2.   

    select s.stuname,c.couname,g.grade into info_stu from student s,course c,grade g
    where s.stuid=g.stuid and c.couid=g.couid and g.stuid = param1;
    这句找出了三列的值,却只用了一个变量来接,所以报错。应该再定义两个变量来存放其他的列,如
    select s.stuname,c.couname,g.grade into info_stu,v_couname,v_grade  from student s,course c,grade g
    where s.stuid=g.stuid and c.couid=g.couid and g.stuid = param1;
      

  3.   

    每个字段需要对应一个赋值变量
    如果你这个查询返回多行结果,也不能直接用你定义的变量,可以改成如下的游标方式:
    create or replace procedure my_pro(param1 in number)
    as
    info_stu varchar2(10000);
    begin
      for vc in
        (select s.stuname,c.couname,g.grade
           from student s,course c,grade g
           where s.stuid=g.stuid and c.couid=g.couid and g.stuid = param1)
        loop
          dbms_output.put_line('姓名:'||vc.stuname||' 课程:'||vc.couname||' 成绩:'||to_char(vc.grade));
        end loop;
    end;
      

  4.   

    select s.stuname,c.couname,g.grade into info_stu,a1,a2 from ...
    定义三个变量来接就好了啊。。
      

  5.   

    看了看语句应该是一条记录!
    剩下的问题就是,定义多个变量接收查询出来的结果,定义的方法是:定义的变量要与查询的字段类型相一致
    另外我想说的是varchar2类型的变量最大长度是4000字符,也就是2000个汉字
      

  6.   

    查询3个变量 INTO 到1个变量里面。你说行不行?
      

  7.   

    s.stuname,c.couname,g.grade into info_stu1,info_stu2,info_stu3
      

  8.   


    create or replace procedure my_pro(param1 in number)
    as
    --游标定义    
    type t_cur is ref cursor;
         v_cur01 t_cur;--参数定义        
    info_stu  varchar2(10000); /*学生姓名*/
    info_couname  varchar2(10000); /*学生课程*/
    info_grade  varchar2(10000); /*学生班级*/begin
    --打开游标
    open v_cur01 for
     select s.stuname,
      c.couname,
      g.grade  
     from student s,
      course c,
      grade g
     where s.stuid=g.stuid 
     and c.couid=g.couid 
     and g.stuid = param1;
    loop
      fetch v_cur01 into info_stu,info_couname,info_grade;
      exit when v_cur01%NOTFOUND;
      
      --打印信息 
      dbms_output.put_line('姓名:'||info_stu||' 课程:'||info_couname||' 成绩:'||to_char(info_grade)); end loop;
    close v_cur01; --关闭游标end;