Oracle uses functions to implement multiple rows and columns of data merge effects

Source: Internet
Author: User

/* 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.