/* Formatted on 2013-1-11 13:23:55 (QP5 v5.185.11230.41888) */
CREATE OR REPLACE FUNCTION getgiftsname (RID in number)//rid wear parameters
RETURN VARCHAR2
As
STR VARCHAR2 (1000); /* The data set returned by */
BEGIN
DECLARE
V_medcode VARCHAR2 (100); /* Where temporary variables are stored */
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.bgif T= ";
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
The effect of the implementation is that you can query a field data under the same ID and separate it with commas (California prune, California Prune 2)
Oracle uses functions to implement multiple rows of data merge effects