Merge datasets in Oracle (Change multiple rows to one row)

Source: Internet
Author: User
In Oracle, the dataset is merged (multiple rows and one row), and the relationship between table A and table B is one-to-many. Query all the data in Table A and merge A project in Table B corresponding to Table A into one row,

In Oracle, the dataset is merged (multiple rows and one row), and the relationship between table A and table B is one-to-many. Query all the data in Table A and merge A project in Table B corresponding to Table A into one row,

In Oracle, the dataset is merged (multiple rows and one row), and the relationship between table A and table B is one-to-many.

Requirements:

Query all the data in Table A and merge A project in Table B corresponding to Table A into A row separated.

ORACLE FUNCTION

Create or replace function FUN_GETNAME (
ID IN NUMBER
) RETURN VARCHAR2
IS
RESULT_OUT VARCHAR2 (20000 );
BEGIN
Declare cursor C_CUR is select ctaskid from TABLE_ B WHERE CID = ID ORDER BY CTASKID;
BEGIN
For rowstr in C_CUR LOOP
RESULT_OUT: = RESULT_OUT | ',' | ROWSTR. CTASKID;
End loop;
END;
RESULT_OUT: = SUBSTR (RESULT_OUT, 2 );
RETURN RESULT_OUT;
END;
/

SQL statement for Data Query:

Select a. ID, A. NAME, A. FLAG, A. DELETE_FLAG, FUN_GETNAME (A. CODE) as sch from TABLE_A order by a. ID, SCH

Same data in Oracle merge tables

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.