CREATE OR REPLACE FUNCTION GetGiftsName (rid in number)//rid 穿的参数
RETURN VARCHAR2
AS
STR VARCHAR2 (1000);
BEGIN
DECLARE
v_medCode VARCHAR2 (100);
CURSOR D_cursor
IS
select b.cproname from cc_promotions a left join cc_progifts b on a.ipromosid=b.ipromosid where a.ipromosid=rid and b.bgift='';
BEGIN
OPEN D_cursor;
loop
fetch D_cursor into v_medCode;
EXIT WHEN D_cursor%NOTFOUND;
if length(STR) > 0 THEN
STR := STR ||','|| v_medCode;
ELSE
STR := STR || v_medCode;
END IF;
END LOOP;
close D_cursor;
end;
RETURN STR;
END GetGiftsName;
select GetGiftsName(428) from dual
实现的效果为可以把相同id下的一个字段数据查询出来并且以逗号分开( 加州西梅,加州西梅2)