Concatenate Multiple columns to one Row - Oracle 10.1

Hi Friends,
I have the item id in the item table and list of warehouses in another table.
SDM_ITEM_TABLE
ITM_ID ITM_DESC
1 Baby Oil
2 Shampoo
SDM_OUTBOUND_LOG
ITM_ID WHS_ID
1 1
1 2
1 3
1 4
2 1
2 2
SDM_OUTBOUND_DESC
WHS_ID WHS_SNAME
1 NJ
2 WN
3 CA
4 CN
Expected Result
ITM_ID WHS_SNAME
1 NJ WN CA CN
2 NJ WN
I am using the below query to join the above 3 tables , but i am unable to concatenate the warehouse short names as displayed above.
select t.itm_id,(SELECT H.WHS_SNAME FROM SDM_OUTBOUND_DESC H WHERE H.WHS_ID = t.WHS_ID) WHS_SNAME
from SDM_OUTBOUND_LOG t, SDM_ITEM_TABLE i
where t.itm_id = i.itm_id
Please let me know how to proceed further in modifying the query to concatenate the warehouse names.
Thanks

Centinul gave you the links to many examples.
You should try them all and find out how they work and let us know what parts are not clear.
Not sure why you are joining all three tables here, it looks like the desired resultset can be selected using
sdm_outbound_log and sdm_outbound_desc only?
One way of concatenating column values, is to use SYS_CONNECT_BY_PATH (but there are many more).
The query below reads from 'inside-out':
SQL> create table sdm_outbound_log as
  2  select 1 itm_id, 1 whs_id from dual union
  3  select 1, 2 from dual union
  4  select 1, 3 from dual union
  5  select 1, 4 from dual union
  6  select 2, 1 from dual union
  7  select 2, 2 from dual;
Table created.
SQL> create table sdm_outbound_desc as
  2  select 1 whs_id, 'NJ' whs_sname from dual union
  3  select 2, 'WN' from dual union
  4  select 3, 'CA' from dual union
  5  select 4, 'CN' from dual;
Table created.
SQL> select itm_id
  2  ,      ltrim(replace( sys_connect_by_path(whs_sname, ',') 
  3                      , ',', chr(32)
  4                      )
  5              ) whs_sname
  6  from ( select l.itm_id
  7         ,      d.whs_sname
  8         ,      row_number() over (partition by l.itm_id order by l.itm_id) rn
  9         from   sdm_outbound_log l
10         ,      sdm_outbound_desc d
11         where  d.whs_id = l.whs_id
12       )
13  where connect_by_isleaf=1    
14  start with rn=1
15  connect by rn=prior rn+1    
16         and itm_id=prior itm_id;
    ITM_ID WHS_SNAME
         1 NJ WN CA CN
         2 NJ WN
2 rows selected.So, in the innermost query we start by using row_number() to obtain a rownumber within each occurence of itm_id,
and then we connect by that rownumber and itm_id in the outermost query.
Since it looks like you want your values delimited by a space, I added a replace and a ltrim.

Similar Messages

  • Concatenate multiple columns into one string

    Hello,
    I am using Oracle 11.2, how can I concatenate the value of multiple columns into one string with one SQL:
    create table testTb(classId number(5), classRoom varchar2(32));
    insert into testTb value(101, 'room101');
    insert into testTb value(101, 'room201');
    insert into testTb value(101, 'room301');
    insert into testTb value(202, 'room444');
    insert into testTb value(202, 'room555');
    I would like to generate the result as followings:
    Class 101 is in room101, room201, room301
    Class 202 is in room444, room555
    Thanks,

    Hi,
    Since you're using Oracle 11.2, you can use the aggregate LISTAGG function:
    SELECT       'Class ' || classid
                   || ' is in '
                 || LISTAGG ( classroom
                         ) WITHIN GROUP (ORDER BY classroom)
                   AS txt
    FROM       testtb
    GROUP BY  classid
    ;The generic name for concatenating all the strings in a group is String Aggregation . This page shows several ways to do it, suitable for different versions of Oracle.

  • Multiple rows to multiple columns on one row using SQL

    Hi
    I am attempting to select back multiple values for a specific key on one row. See the example below. I have been able to use the sys_connect_by_path to combine the fields into one field but I am unable to assign them to fields of their own. See the example below
    TABLE DETAILS:
    Policy id plan name
    111 A Plan
    111 B Plan
    111 Z Plan
    112 A Plan
    112 Z Plan
    My desired result is to be able to show the output as follows
    Policy ID Plan_1 Plan_2 Plan_3
    111 A Plan B Plan Z PLan
    112 A Plan Z PLan
    Can you help???

    Thanks for all the replies. Perhaps I could give a little more detail incldung a sample table and insert statements. The repsonses work fine but the problem I was having was that I did not want to have to hardcode in the plan_name to a decode statement. The list of plans is not exhaustive. There could be numerous different plans in the table. I have amended the details below slightly to try and give a little more information as I was probably not too clear at the start. Would you know if there is a way to do this without hardcoding the plan values in?
    Thanks in advance!
    CREATE TABLE TEST_SAMPLE (
    POLICY_NUMBER VARCHAR2(10),
    plan_name varchar2(20) );
    INSERT INTO TEST_SAMPLE VALUES ('111', 'A Plan');
    INSERT INTO TEST_SAMPLE VALUES ('111', 'B Plan');
    INSERT INTO TEST_SAMPLE VALUES ('111', 'C Plan');
    INSERT INTO TEST_SAMPLE VALUES ('112', 'J Plan');
    INSERT INTO TEST_SAMPLE VALUES ('112', 'Z Plan');
    My desired result is to be able to show the output as follows
    Policy ID Plan_1 Plan_2 Plan_3
    111 A Plan B Plan C PLan
    112 J Plan Z PLan

  • Converting multiple columns into one.

    All,
    I have a requirement to convert multiple columns into one. Following is the pseudo code of current implementation. It unions the various columns ( col1, col2........) into a new column new_col. But perforamnce is extrmely slow owing to multiple unions. It may be noted that tables and where conditions of all these queries are same.
    Can you help me create a more efficient query?
    select col1 , col2, col3, col4 from my_tables where some_cols = my_condition;Below is the query used to convert these columns into one.
    select col1 new_col from my_tables where some_cols = my_condition
    union all
    select col2 from my_tables where some_cols = my_condition
    union all
    select col3 from my_tables where some_cols = my_condition
    union all
    select col4 from my_tables where some_cols = my_condition

    Without looking at those things you could be barking up the wrong tree by assuming the issue relates to the unioning of queries or other such things.Well, might be.........
    Execution time of this query (just the execution time not the retrival) is around 34 seconds with connect-by clause for returning 22,000 records.
    Here's the plan
    Execution Plan
    | Id  | Operation                          | Name                        | Rows
    | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                             |   326
    | 33904 |   135   (2)|
    |   1 |  SORT ORDER BY                     |                             |   326
    | 33904 |   135   (2)|
    |   2 |   MAT_VIEW ACCESS BY INDEX ROWID   | MV_COMQ_RM_DEAL             |     1
    |    62 |     1   (0)|
    |   3 |    NESTED LOOPS                    |                             |   326
    | 33904 |   134   (1)|
    |   4 |     MERGE JOIN CARTESIAN           |                             |   326
    | 13692 |     3   (0)|
    |   5 |      VIEW                          |                             |     1
    |    13 |     2   (0)|
    |   6 |       COUNT                        |                             |
    |       |            |
    |   7 |        CONNECT BY WITHOUT FILTERING|                             |
    |       |            |
    |   8 |         FAST DUAL                  |                             |     1
    |       |     2   (0)|
    |   9 |      BUFFER SORT                   |                             |   326
    |  9454 |     3   (0)|
    |  10 |       TABLE ACCESS BY INDEX ROWID  | SF_SEARCH_IDS_TMP_COMQ      |   326
    |  9454 |     1   (0)|
    |  11 |        INDEX RANGE SCAN            | IDX1_SF_SEARCH_IDS_TMP_COMQ |   349
    |       |     1   (0)|
    |  12 |     INDEX RANGE SCAN               | IDX_MV_COMQ_RM_DEAL         |     9
    |       |     1   (0)|
    -----------------------     Hope, It's readable.......
    I would have posted sample data and query but........I cant do that...:(

  • Help needed in returning multiple columns from one field

    Hi,
    I have been given a task to rewrite the query (see below), so that I get three columns from the one field, based on their contents.
    The script returns all the columns and concatenates them into one, but returns them as comma delimmited within the returned column, to generate a report.
    These tables are from Siebel.
    Our Oracle version is:
    select banner from sys.v_$version;
    --returns
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    PL/SQL Release 8.1.7.4.0 - Production
    CORE     8.1.7.0.0     Production
    TNS for Solaris: Version 8.1.7.4.0 - Production
    NLSRTL Version 3.4.1.0.0 - Production
    Here is what I was given;
    set arraysize 200
    Spool d:\Daily_reports\Data\RegManage\Electricity\eCISPLUS_Product_Switch_Not_Started_Discount.csv
    -- this will concatenate all the returned columns into one
    SELECT DISTINCT '"'||
    rtrim(ltrim(S_ORG_EXT.OU_NUM)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.NAME)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.TODO_CD)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.EVT_STAT_CD)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_SOURCE_TYPE)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_TXU_PRICELIST_NAME)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PEAKANYTIME_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PA_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.X_OTH_ACCOUNT_NUMBER)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_NUM)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_CHECKSUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.QUOTE_NUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_COOLING_OFF_DATE)) || '","' ||
    rtrim(ltrim(S_PROD_INT.NAME)) || '"'
    The field S_PROD_INT.NAME is the one that I need to split so that it is retured
    into three different columns.
    1st column needed -
    where S_PROD_INT.NAME Like 'Electricity TRUenergy Business Edge __ %'
    OR S_PROD_INT.NAME Like 'Electricity TRUenergy Business Now __ %'
    OR S_PROD_INT.NAME Like 'Electricity Go for More __ %'
    OR S_PROD_INT.NAME Like 'Electricity Mates Rates __ %'
    2nd column needed -
    where S_PROD_INT.NAME Like 'Gas TRUenergy Business Edge __ %'
    OR S_PROD_INT.NAME Like 'Gas TRUenergy Business Now __ %'
    OR S_PROD_INT.NAME Like 'Gas Go for More __ %'
    OR S_PROD_INT.NAME Like 'Gas Mates Rates __ %'
    3rd column needed from
    S_PROD_INT.NAME Like '* ___ Discount for Paying Your Bill by the Due Date')
    -- Tables
    FROM SIEBEL.S_ADDR_PER S_ADDR_PER,
    SIEBEL.S_DOC_QUOTE S_DOC_QUOTE,
    SIEBEL.S_EVT_ACT S_EVT_ACT,
    SIEBEL.S_ORG_EXT S_ORG_EXT,
    SIEBEL.S_PRI_LST S_PRI_LST,
    SIEBEL.S_PROD_INT S_PROD_INT,
    SIEBEL.S_QUOTE_ITEM S_QUOTE_ITEM
    WHERE S_EVT_ACT.TARGET_OU_ID = S_ORG_EXT.ROW_ID
    AND S_DOC_QUOTE.ROW_ID = S_QUOTE_ITEM.SD_ID
    AND S_ADDR_PER.ROW_ID = S_ORG_EXT.PR_ADDR_ID
    AND S_PROD_INT.ROW_ID = S_QUOTE_ITEM.PROD_ID
    AND S_ORG_EXT.ROW_ID = S_DOC_QUOTE.TARGET_OU_ID
    AND S_DOC_QUOTE.PRI_LST_ID = S_PRI_LST.ROW_ID
    AND S_EVT_ACT.TODO_CD = 'Product Switch-Electricity'
    AND S_EVT_ACT.EVT_STAT_CD In ('In Progress','Not Started','On Hold')
    AND S_DOC_QUOTE.STAT_CD In ('Completed','Verbal Acceptance','Written Acceptance')
    AND S_DOC_QUOTE.X_OFFER_TYPE = 'Product Switch'
    AND (S_PROD_INT.NAME Like 'Electricity TRUenergy Business Edge __ %' OR S_PROD_INT.NAME Like 'Electricity TRUenergy Business Now __ %'
    OR S_PROD_INT.NAME Like 'Electricity Go for More __ %' OR S_PROD_INT.NAME Like 'Electricity Mates Rates __ %'
    OR S_PROD_INT.NAME Like 'Electricity __ Discount for Paying Your Bill by the Due Date' or S_PROD_INT.NAME Like 'Electricity TRUenergy Business Edge ___ %'
    OR S_PROD_INT.NAME Like 'Electricity TRUenergy Business Now ___ %'
    OR S_PROD_INT.NAME Like 'Electricity Go for More ___ %'
    OR S_PROD_INT.NAME Like 'Electricity Mates Rates ___ %'
    OR S_PROD_INT.NAME Like 'Electricity ___ Discount for Paying Your Bill by the Due Date')
    UNION
    SELECT DISTINCT '"'||
    rtrim(ltrim(S_ORG_EXT.OU_NUM)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.NAME)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.TODO_CD)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.EVT_STAT_CD)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_SOURCE_TYPE)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_TXU_PRICELIST_NAME)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PEAKANYTIME_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PA_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.X_OTH_ACCOUNT_NUMBER)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_NUM)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_CHECKSUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.QUOTE_NUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_COOLING_OFF_DATE)) || '"'
    FROM SIEBEL.S_ADDR_PER S_ADDR_PER,
    SIEBEL.S_DOC_QUOTE S_DOC_QUOTE,
    SIEBEL.S_EVT_ACT S_EVT_ACT,
    SIEBEL.S_ORG_EXT S_ORG_EXT,
    SIEBEL.S_PRI_LST S_PRI_LST
    WHERE S_EVT_ACT.TARGET_OU_ID = S_ORG_EXT.ROW_ID
    AND S_ADDR_PER.ROW_ID = S_ORG_EXT.PR_ADDR_ID
    AND S_ORG_EXT.ROW_ID = S_DOC_QUOTE.TARGET_OU_ID
    AND S_DOC_QUOTE.PRI_LST_ID = S_PRI_LST.ROW_ID
    AND S_EVT_ACT.TODO_CD = 'Product Switch-Electricity'
    AND S_EVT_ACT.EVT_STAT_CD In ('In Progress','Not Started','On Hold')
    AND S_DOC_QUOTE.STAT_CD In ('Completed','Verbal Acceptance','Written Acceptance')
    AND S_DOC_QUOTE.X_OFFER_TYPE = 'Product Switch'
    AND NOT EXISTS (SELECT /*+ unnest */ 'X'
    FROM SIEBEL.S_PROD_INT S_PROD_INT, SIEBEL.S_QUOTE_ITEM S_QUOTE_ITEM
    WHERE S_DOC_QUOTE.ROW_ID = S_QUOTE_ITEM.SD_ID
    AND S_PROD_INT.ROW_ID = S_QUOTE_ITEM.PROD_ID
    AND (S_PROD_INT.NAME Like 'Electricity TRUenergy Business Edge __ %'
    OR S_PROD_INT.NAME Like 'Electricity TRUenergy Business Now __ %'
    OR S_PROD_INT.NAME Like 'Electricity Go for More __ %'
    OR S_PROD_INT.NAME Like 'Electricity Mates Rates __ %'
    OR S_PROD_INT.NAME Like 'Electricity __ Discount for Paying Your Bill by the Due Date' or S_PROD_INT.NAME Like 'Electricity TRUenergy Business Edge ___ %'
    OR S_PROD_INT.NAME Like 'Electricity TRUenergy Business Now ___ %'
    OR S_PROD_INT.NAME Like 'Electricity Go for More ___ %'
    OR S_PROD_INT.NAME Like 'Electricity Mates Rates ___ %'
    OR S_PROD_INT.NAME Like 'Electricity ___ Discount for Paying Your Bill by the Due Date'));
    spool off
    This is what one row looks like;
    "1-UWLHY","Alpha Vic Kelly Kay","Product Switch-Electricity","Not Started","AMBASS_50REBATE","Go Green PKANY-Powercor","QEGS1","GG","QEGS1","GG","","6407421678","8","1-UWLI6","12-JUN-07","Electricity Mates Rates 7% Discount"
    we want
    "1-UWLHY","Alpha Vic Kelly Kay","Product Switch-Electricity","Not Started","AMBASS_50REBATE","Go Green PKANY-Powercor","QEGS1","GG","QEGS1","GG","","6407421678","8","1-UWLI6","12-JUN-07",'Electricity Mates Rates 7% Discount","Gas TRUenergy Business Edge 10% Discount","Electricity 3% Discount for Paying Your Bill by the Due Date"
    I have tried to:
    - create a cursor
    - each column as - ie
    S_PROD_INT.NAME as "EVD",
    S_PROD_INT.NAME as "GVD",
    S_PROD_INT.NAME as "PbDDD"
    but when I try to use them in where "EVD" Like 'etc...'
    error that table does not exist
    I have tried also as
    where 'EVD' Like 'etc...' -- error
    where EVD Like 'etc...' -- error
    - create them as %TYPE variable
    - more
    but keep getting errors
    Any ideas and help will be most appreciated as I have tried and researched all I can think and get my hands on with my limited skills.
    Thanks.
    Regards, Steve

    Unfortunately my skills are not high enough as I obviously don't know where to put the code exaclty.
    I am first just running it on the top part of the script but get the error;
    ORA-00900: invalid SQL statement
    What I am running is; -- Commented
    WITH s_prod_int AS
    SELECT 1 row_id, 'Electricity Mates Rates 7% Discount' name FROM s_prod_int --these were 'FROM dual' originally, I changed to s_prod_int (Received same error regardless whether from dual or s_prod_int)
    UNION ALL
    SELECT 1, 'Gas TRUenergy Business Edge 10% Discount' FROM s_prod_int
    UNION ALL
    SELECT 1, 'Electricity 3% Discount for Paying Your Bill by the Due Date' FROM s_prod_int
    SELECT DISTINCT '"'||
    rtrim(ltrim(S_ORG_EXT.OU_NUM)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.NAME)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.TODO_CD)) || '","' ||
    rtrim(ltrim(S_EVT_ACT.EVT_STAT_CD)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_SOURCE_TYPE)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_TXU_PRICELIST_NAME)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PEAKANYTIME_ELEC)) || '","' ||
    rtrim(ltrim(S_PRI_LST.X_TXU_CISRATE_PA_CLASS_ELEC)) || '","' ||
    rtrim(ltrim(S_ORG_EXT.X_OTH_ACCOUNT_NUMBER)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_NUM)) || '","' ||
    rtrim(ltrim(S_ADDR_PER.X_NMI_CHECKSUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.QUOTE_NUM)) || '","' ||
    rtrim(ltrim(S_DOC_QUOTE.X_COOLING_OFF_DATE)) || '","' ||
    rtrim(ltrim(a.name)) ||'","'|| --I assume I am still able to right and left trim
    rtrim(ltrim(b.name)) ||'","'||
    rtrim(ltrim(c.name))||'"' name -- not sure what this name is here for (have ran with and without it here
    FROM SIEBEL.S_ADDR_PER S_ADDR_PER,
    SIEBEL.S_DOC_QUOTE S_DOC_QUOTE,
    SIEBEL.S_EVT_ACT S_EVT_ACT,
    SIEBEL.S_ORG_EXT S_ORG_EXT,
    SIEBEL.S_PRI_LST S_PRI_LST,
    s_prod_int a, -- I assume these needed to go in here
    s_prod_int b,
    s_prod_int c
    SIEBEL.S_QUOTE_ITEM S_QUOTE_ITEM
    WHERE S_EVT_ACT.TARGET_OU_ID = S_ORG_EXT.ROW_ID
    AND S_DOC_QUOTE.ROW_ID = S_QUOTE_ITEM.SD_ID
    AND S_ADDR_PER.ROW_ID = S_ORG_EXT.PR_ADDR_ID
    AND S_PROD_INT.ROW_ID = S_QUOTE_ITEM.PROD_ID
    AND S_ORG_EXT.ROW_ID = S_DOC_QUOTE.TARGET_OU_ID
    AND S_DOC_QUOTE.PRI_LST_ID = S_PRI_LST.ROW_ID
    AND S_EVT_ACT.TODO_CD = 'Product Switch-Electricity'
    AND S_EVT_ACT.EVT_STAT_CD In ('In Progress','Not Started','On Hold')
    AND S_DOC_QUOTE.STAT_CD In ('Completed','Verbal Acceptance','Written Acceptance')
    AND S_DOC_QUOTE.X_OFFER_TYPE = 'Product Switch'
    AND a.NAME LIKE 'Electricity TRUenergy Business Edge%' --Placed all the where part in the original where clause
    OR a.NAME LIKE 'Electricity TRUenergy Business Now%'
    OR a.NAME LIKE 'Electricity Go for More%'
    OR a.NAME LIKE 'Electricity Mates Rates%'
    AND a.row_id = b.row_id
    AND (
    b.NAME LIKE 'Gas TRUenergy Business Edge%'
    OR b.NAME LIKE 'Gas TRUenergy Business Now%'
    OR b.NAME LIKE 'Gas Go for More%'
    OR b.NAME LIKE 'Gas Mates Rates%'
    AND b.row_id = c.row_id
    AND (
    c.NAME LIKE '%Discount for Paying Your Bill by the Due Date'
    NAME -- Not sure what this NAME is for - tried with and without - same error

  • How to concatenate multiple records into one

    Hi everybody:
    I want to know if exist some way to concat multiple records into one without using cursors. For example, I have a table named "Authors" like this:
    Lan|Author
    English|Ernest Hemingway
    Spanish|Octavio Paz
    Spanish|Mario Vargas Llosa
    English|Sinclair Lewis
    Spanish|Gabriel García Márquez
    And I want to get this:
    Author
    Octavio Paz, Mario Vargas Llosa, Gabriel García Márquez
    I have worked with SQL Server and I can do something like this:
    CREATE FUNCTION dbo.MyConcat (@lan varchar(10))
    RETURNS varchar(5000) AS
    BEGIN
    declare @retvalue varchar(5000)
    set @retvalue=''
    select @retvalue = @retvalue + Author +',' from Authors where lan = @lan
    return substring(@retvalue,1,len(@retvalue)-1)
    END
    ie, do not use cursors to concatenate records. However, with ORACLE, I have to do someting like this.
    FUNCTION MyConcat(P_Lan IN VARCHAR2) RETURN VARCHAR2 IS
    v_ret VARCHAR2(4000);
    v_element VARCHAR2(4000);
    v_cursor sys_refcursor;
    BEGIN
    OPEN v_cursor FOR SELECT Author FROM Authors where Lan = P_Lan
    LOOP
    FETCH v_cursor INTO v_elemento;
    EXIT WHEN v_cursor%NOTFOUND;
    IF v_ret IS NULL THEN
    v_ret := v_element;
    ELSE
    v_ret := v_ret || ', ' || v_element;
    END IF;
    END LOOP;
    RETURN v_ret;
    END;
    Exist some other way to do this?
    Best Regards
    Jack

    Tks both for answer... I forgot to mention that I am using Oracle 10g. I read about LISTAGG() but this function is available for Oracle 11g release 2.
    I wil read about the other techniques than Hoek mention
    Best Regards.
    Jack

  • Select multiple column into one column

    Hi..!!!
    Is it possible to select 4 columns in to 1 columns?
    I've major1, major 2, major 3, major 4 and i want to retrieve all the columns into one column called "Majors".
    Is it possible? if yes then how?
    Help me out.
    Thanks,
    Himadri

    If you had given a proper example this thread would have been over in two posts. What you are looking for is often described as an UNPIVOT.
    I tend to use a collection type for this, e.g.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE OR REPLACE TYPE varchar2_table AS TABLE OF VARCHAR2 (4000);
      2  /
    Type created.
    SQL> SELECT empno, column_value
      2  FROM   emp, TABLE (varchar2_table (ename, job));
         EMPNO COLUMN_VALUE
          7369 SMITH
          7369 CLERK
          7499 ALLEN
          7499 SALESMAN
          7521 WARD
          7521 SALESMAN
          7566 JONES
          7566 MANAGER
          7654 MARTIN
          7654 SALESMAN
          7698 BLAKE
    (snipped)
    28 rows selected.
    SQL>

  • Multiple record in one row..

    Hi experts,
    I want to merge multiple row from same table into one row... is it possible? if so then how??
    Regards,
    SKP

    Sure, it's possible
    create table scott.a
    as
    select 1 a, 2 b from dual     
    union all
    select 3 a, 4 b from dual     
    create table scott.b
    (a number, b number, c number, d number)
    insert into scott.b
    select a1.a,a1.b,a2.a,a2.b from scott.a a1, scott.a a2
    where a1.a = 1 and a2.a = 3
    P.S. Sorry, at first misunderstood the task
    Message was edited by:
    Dmytro Dekhtyaryuk

  • How can i create my BC featured product list in to a slide show for multiple products in one row. i have products aligned in a row i just would like to make it a slide show of the multiple (20) products.

    i have products aligned in a row already using custom css.i just would like to make it a slide show of the multiple (20) products in the one row.
    i am using the featured product module from the development section of business catalyst. i would love to display as many new products as possible in one row of products. so i can just click a arrow left button and scroll through the products.
    holy-shippers.businesscatalyst.com is the site i am mentioning.

    Hello,
    Aside from any custom implementations that may be suggested by any other members, you could also consider using some hero-type slider like those found on our new responsive templates, and have each web-app item contain a product.
    Kind Regards,
    Alex Pavelescu

  • Concatenate multiple records into one single record

    Hello everyone,
    Can anyone guide me how to merge multiple records into one single record
    like......... I am getting the data in the file like
    aaaaa/bbbbbbb/ccccccccccc/dddddddddddd/eee
    ffffff/gggg/hhhhhhhhhhhhhh
    /123/4567/55555/99999999/kaoabfa/eee
    fffff/kkkkkkkk/llllllllllllllllllllllll
    when i use gui_upload I am getting the data into the internal table in the above format.
    My main intension is to split the record at / to multiple lines and dowload it into another file.
    What i am planning to do is... if the line does not start with / then i want to concatenate the multiple lines into single line and then split it into multiple records. Can anyone guide me how to achieve this.

    Yes, it should work.
    In my example
    Loop at itab.
    concatenate i_text itab into i_text.
    endloop.
    You change that loop for the loop of your internal table with the file records
    So if you have this three records
    'aaaa/bbb/ccc'
    '/dddd/efg'
    'hijk/lmn'
    i_text will look like this at the end
    'aaaa/bbb/ccc/dddd/efghijk/lmn'
    then in this part of the code
    split i_text at '/' into table itab2.
    itab2 will have the records looking like this
    aaaa
    bbb
    ccc
    dddd
    efghijk
    lmn'

  • Concatenate Multiple Columns into Single

    Hi All,
    I am developing a report and there is a field called FUNDING_SOURCE.
    This field is being picked from class_code of PA_PROJECT_CLASSES table as shown below:
    (select distinct(class_code)
    from pa_project_classes ppc,
    pa_projects_all ppa
    where class_category = 'FUNDING SOURCE'
    and ppc.project_id = :project_id)
    But, the requirement is to have all values of Funding Source for a particular project ID concatenated into a single column.
    Eg: If I run the above code, the output would be in 3 rows,
    Intenal
    External
    Other
    I want the output concatenated and displayed as Internal, External, Other.
    Please help me ASAP. Need to finish this soon.
    Thanks!

                        SELECT substr(MAX(sys_connect_by_path(a,
                                                              '~')),
                                      2) --first character wil be ~ max is used because the query will return 3 rows and u need only one row with all values appended
                          FROM (SELECT a,
                                       row_number() over(ORDER BY t.b) AS curr, --order in which appending happens
                                       row_number() over(ORDER BY t.b) - 1 AS prev --order in which appending happens
                                  FROM (SELECT 'Internal' a,
                                               1 b
                                          FROM dual
                                        UNION ALL
                                        SELECT 'External' a,
                                               2 b
                                          FROM dual
                                        UNION ALL
                                        SELECT 'Other' a,
                                               3 b
                                          FROM dual) t --creating dummy table
                        CONNECT BY prev = PRIOR curr
                         START WITH curr = 1;

  • Setting different Tabel Cell SemanticColor for Multiple Columns of each row

    Hi,
    I have requirement of setting different colors to different columns for each row based on some condition in table data.
    The data to table is coming from model, hence table is mapped to model node and attributes.
    I have created Seperate Node CellColorNode with attribue CellClr1 and CellClr2 of type TextView Semantic Color.
    Set the calculated, read only attribute to True. Mapped table columns text view to the CellColorNode->CellClr1 and CellColorNode-->CellClr2 correspondingly.
    Now, my query is how do i set the colors to CellClr1 and CellClr2 attributes. As I need to set the color for multiple columns of each table row.
    Is it in method getColorCellCellClr generated? Any  Example Code?

    Its resolved by following below link
    http://scn.sap.com/thread/158286

  • Multiple columns with uneven rows

    Good Evening Everybody
    Could somebody advise me on the best solution to do the following.
    I have a csv file. The csv file is being read using "read from spreadsheet file" vi.
    The file contains multiple columns. The columns all have a different last row address. By this I mean that...say...the last row of column 1 is 5. Column 2 last row is 23, Column 3 last row is 12. etc. The file might look like the following...note...this is an example of a file only, and any implications can't be construed.
                Column1    Column2    Column3    Column4     Column5
    Row1        0               1                 2             3                 4
    Row2       12             23              13            34                 0
    Row3       11             44              23                               11
    Row4       34             55            
    Row5       21           
    Lets assume that the value(s) of interest are contained in columns 2,4 and 5. Therefore the values I want to extract would be 55, 34 and 11
    I can select the columns of interest fine, but am having difficulty working out how to find the last row for these columns
    Caveats:
    1. The number of columns changes
    2. Position of column in file changes address...never found in same address
    Does anybody know how I might be able to locate the last row in the column of my choosing.
    Thanks for any assistance.
    best regards
    Ray

    Hi Ray,
    load the csv as an array of strings. Empty cells will result in empty strings. So you can easily test each column for an empty item, which will mark the "End of Data"...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Concatenate multiple lines into one

    Post Author: [email protected]
    CA Forum: General
    Hi,I'm trying to pull data out of one table that could have multiple lines (indicated by a line count field for each row).  The user wants to see all lines in one field only.  I tried the following but am running into issues if there's only one row (one line count). With this, the single row is concatenated with itself. //@groupheader-initilizewhileprintingrecords;stringvar x:=""//@detailwhileprintingrecords;stringvar x:=x+ //@groupfooterwhileprintingrecords;stringvar x Any ideas appreciated.  Thanks!

    Post Author: Charliy
    CA Forum: General
    Take the initialize formula out of the Group Header.
    Place it an the Report Header, and create a second (print suppressed) Group Footer and place it there

  • Multiple records in one row

    Hi all,
    I want to display all the party codes which have same party name,
    and I want to display all the party codes in one row separated by comma. is it possible?

    You can either use analytic functions + hierarchy or stragg (listagg if you are on 11.2) or undocumentd wm_concat. There are plenty examples on this forum. For example:
    select  deptno,
            ltrim(sys_connect_by_path(job,','),',') job_list
      from  (
             select  deptno,
                     job,
                     row_number() over(partition by deptno order by job) rn
               from  emp
      where connect_by_isleaf = 1
      start with rn = 1
      connect by deptno = prior deptno
             and rn = prior rn + 1
        DEPTNO JOB_LIST
            10 CLERK,MANAGER,PRESIDENT
            20 ANALYST,ANALYST,CLERK,CLERK,MANAGER
            30 CLERK,MANAGER,SALESMAN,SALESMAN,SALESMAN,SALESMAN
    select  deptno,
            rtrim(stragg(job || ','),',') job_list
      from  emp
      group by deptno
        DEPTNO JOB_LIST
            10 MANAGER,PRESIDENT,CLERK
            20 CLERK,ANALYST,CLERK,ANALYST,MANAGER
            30 SALESMAN,MANAGER,SALESMAN,SALESMAN,CLERK,SALESMAN
    select  deptno,
            wm_concat(job) job_list
      from  emp
      group by deptno
        DEPTNO JOB_LIST
            10 MANAGER,PRESIDENT,CLERK
            20 CLERK,ANALYST,CLERK,ANALYST,MANAGER
            30 SALESMAN,MANAGER,SALESMAN,SALESMAN,CLERK,SALESMANSY.

Maybe you are looking for

  • Tax in credit Memo

    Hello, I have a doubt regarding tax posting in credit memo. When we create an invoice , let us say we charged 12% of tax of final price $1000, means $120/-, which will post to a seperate account. when we create a credit memo with reference to the inv

  • Comp recognizes iPod but iTunes doesn't

    I will attach my iPod into the USB port and the copmuter will begin to chargge it. My iTunes, however, will not recognize the iPod tho open up the window. My iTunes will not even open up if I click on it. I've gone through all the steps, but it still

  • Old Keynote files--can't open

    I have Keynote files from April 2004 that I need to open, edit and use. They won't open with '06 or '08. Here are the 2 error messages I keep getting: The error 9 was found while parsing the XML: "Found illegal character while parsing element tag." U

  • Empty Crystal Report

    Hi Experts, I tried to change old crystal Reports template (AR invoice)  after I imported in into 8.8 like this. 1. Rename parameter to DocKey@ 2. Change Selection Record fomulas as  {OINV.DocNum} = {?DocKey@} 3. Change Datasource to SAPB1 (In ODBC s

  • How to add rules?

    I have a form where i need the user to specify which Sector they are installing service on, Alpha, 1, 2, 3, 4 etc it can be multiple like Alpha 1 & Alpha 4 both require installtion on them. Now the RULE i want to apply is: If they select Alpha 1 & Al