create or replace function fun_get_itemgrade(pact_code VARCHAR2,his_code VARCHAR2) return varchar2 isitem_grade_name  Varchar2(10);BEGINselect decode(a.center_item_grade,'1','甲类','2','乙类','自费')
  into item_grade_name
  from fin_com_compare a
 where a.pact_code = pact_code
   and a.his_code = his_code;RETURN item_grade_name;end fun_get_itemgrade;
提示ora-01422 返回多行的错误,但是我看了一下没有多行的啊,his_code就能定位到一行啊。select fun_get_itemgrade('02','12345678')
   from --
  where his_code = '12345678'即使是一行也报错

解决方案 »

  1.   

    问题是你这个语句:Select decode(a.center_item_grade,'1','甲类','2','乙类','自费')
      into item_grade_name
      from fin_com_compare a
     where a.pact_code = pact_code
      and a.his_code = his_code;
    能查询出多少条结果?你要控制以上的语句只返回一个值才能保证你的方法执行正确。
    检查一下。
      

  2.   


    create or replace function fun_get_itemgrade(pact_code VARCHAR2,
                                                 his_code  VARCHAR2)
      return varchar2 is  item_grade_name Varchar2(10);BEGIN
      
      --这样打印一下结果  你就能看出来问题了
      for rec in (select decode(a.center_item_grade,
                                '1',
                                '甲类',
                                '2',
                                '乙类',
                                '自费') de
                    from fin_com_compare a
                   where a.pact_code = pact_code
                     and a.his_code = his_code)
      
       loop
             dbms_output.put_line(rec.de);
       end loop;  /*select decode(a.center_item_grade,'1','甲类','2','乙类','自费')
       into item_grade_name   -- 这个地方查询到的肯定是多个值,所以into会出错
       from fin_com_compare a
      where a.pact_code = pact_code
       and a.his_code = his_code;*/  RETURN item_grade_name;end fun_get_itemgrade;