sql 函数的运用问题 求解SQL codecreate or replace FUNCTION get_maxmissreason (param1 IN VARCHAR)retu
sql 函数的运用问题 求解
SQL code
create or replace FUNCTION get_maxmissreason (param1 IN VARCHAR) return NUMBERAS v_missreason number; --v_max_updatetime date; --v_orderno varchar2(20); CURSOR c_max_updatetime IS select a.orderno µ¥ºÅ,max(b.updatetime) ·þÎñÐÐΪ¸üÐÂʱ¼ä from servicerepair a,serviceaction b,a1report c where a.orderno = b.orderno and a.orderno = c.orderno group by a.orderno;BEGIN FOR r_max_updatetime IN c_max_updatetime LOOP --v_max_updatetime := r_max_updatetime.·þÎñÐÐΪ¸üÐÂʱ¼ä; --v_orderno := r_max_updatetime.µ¥ºÅ; select missreason into v_missreason from serviceaction where orderno = r_max_updatetime.µ¥ºÅ and updatetime = r_max_updatetime.·þÎñÐÐΪ¸üÐÂʱ¼ä; return v_missreason; END LOOP;END;
查询代码
select a.orderno,get_maxmissreason(a.orderno) from servicerepair a,a1report b where a.orderno = b.orderno
BEGIN FOR r_max_updatetime IN c_max_updatetime LOOP --v_max_updatetime := r_max_updatetime.·þÎñÐÐΪ¸üÐÂʱ¼ä; --v_orderno := r_max_updatetime.µ¥ºÅ; select missreason into v_missreason from serviceaction where orderno = r_max_updatetime.µ¥ºÅ and updatetime = r_max_updatetime.·þÎñÐÐΪ¸üÐÂʱ¼ä; return v_missreason; END LOOP; END; [解决办法]