Concatenation in a Group by

Hi,
I'd like to concatenate attributes on a vertical basis when I perform a Group by
For example:
TABLE_TEST
ID STATUS
1003 PL
1003 OP
1003 OP
I am looking for
ID STATUS
1003 PL, OP, OP
The query would be something like:
Select ID, concat(STATUS)
From TABLE_TEST
Group by ID
Is that possible? Cheers

SQL> desc table_test;
Name Null? Type
ID NUMBER
STATUS VARCHAR2(20)
SQL> select * from table_test;
ID STATUS
1 a
1 b
2 c
2 d
DECLARE
all_status VARCHAR2(100) := '' ;
comma varchar2(1) := ',';
id number;
id1 number;
status varchar2(20);
flag number := 0;
cursor cur_tabletest is
select id,status from table_test order by id ;
begin
open cur_tabletest;
loop
fetch cur_tabletest into id,status ;
if (flag = 0) then
id1 := id;
flag := 1 ;
end if;
exit when CUR_tabletest%NOTFOUND;
if(id1 = id) then
     all_status := all_status || comma || status ;
else
dbms_output.put_line(id1 || ' ' || ltrim(all_status,',') );
all_status := '';
all_status := all_status || comma || status ;
end if;
id1 := id;
end loop;
dbms_output.put_line(id1 || ' ' || ltrim(all_status,',') );
close CUR_tabletest;
END;
1 a,b
2 c,d
PL/SQL procedure successfully completed.

Similar Messages

  • Concatenating clobs

    Hi
    I have a question on concatenating many small clobs into a large. DB = 11.2.0.1.
    The following is a sample set of data;
    create table t_bi001_payment
    (customer_number number
    ,payment clob
    begin
    for i in 1..1000 loop
    insert into t_bi001_payment (customer_number
                                ,payment)
    values  
    (1
    ,'200003783511655968                   000000000000100000320000000000100
    26Kalles Plåt AB
    27Storgatan 2                        12345
    28Storåker
    29005500001234
    210003783511                    898540000000000000500002200023000011100
    26Kalles Plåt AB
    27Storgatan 2                        12345
    28Storåker
    2900550000' || lpad(i, 4, '0'));
    end loop;
    commit;
    end;
    /There are thousands of such clobs, which have to be concatenated per customer into a single clob.
    Each clob should start on a new line.
    The first technique I used was connect by, which I picked up from; http://www.williamrobertson.net/
    create table abc (c clob)
    insert into abc (c)
    select ltrim(max(sys_connect_by_path(payment,',')) keep (dense_rank last order by curr),',') as clob_val
    from   (select customer_number
                  ,payment
                  ,row_number() over (partition by customer_number order by customer_number) AS curr,
                   row_number() over (partition by customer_number order by customer_number) -1 AS prev
            from   t_bi001_payment)
    group by customer_number
    connect by prev = prior curr and customer_number = prior customer_number
    start with curr = 1
    commit
    /The above statement returns error:
    ORA-01489: result of string concatenation is too long
    The following statement is an alternative method:
    insert into abc (c)
    select to_clob(concatenated)
    from
    select   xmlagg (xmlelement (c, payment || chr(13))).extract ('//text()') as concatenated
    from     t_bi001_payment
    group by customer_number
    commit
    /The above statement returns a similar error, but different message:
    ORA-19011: Character string buffer too small
    I realise that in both cases the SQL 4000 varchar2 limit has been reached.
    The question I have is how can I concatenate hundreds or possibly
    thousands of clobs (all relatively small, mostly around 1 or 2k)
    into a single larger clob using SQL without having to revert to PL/SQL ?
    thx
    Edited by: bluefrog on Mar 8, 2011 10:52 AM

    Oddly, I was just looking at the following example code in relation to another thread.
    This is a user defined aggregate function for concatenating clobs...
    create or replace
      type clobagg_type as object(
                                  text clob,
                                  static function ODCIAggregateInitialize(
                                                                          sctx in out clobagg_type
                                    return number,
                                  member function ODCIAggregateIterate(
                                                                       self  in out clobagg_type,
                                                                       value in     clob
                                    return number,
                                  member function ODCIAggregateTerminate(
                                                                         self        in     clobagg_type,
                                                                         returnvalue    out clob,
                                                                         flags       in     number
                                    return number,
                                  member function ODCIAggregateMerge(
                                                                     self in out clobagg_type,
                                                                     ctx2 in     clobagg_type
                                    return number
    create or replace
      type body clobagg_type
        is
          static function ODCIAggregateInitialize(
                                                  sctx in out clobagg_type
            return number
            is
            begin
                sctx := clobagg_type(null) ;
                return ODCIConst.Success ;
          end;
          member function ODCIAggregateIterate(
                                               self  in out clobagg_type,
                                               value in     clob
            return number
            is
            begin
                self.text := self.text || value ;
                return ODCIConst.Success;
          end;
          member function ODCIAggregateTerminate(
                                                 self        in     clobagg_type,
                                                 returnvalue    out clob,
                                                 flags       in     number
            return number
            is
            begin
                returnValue := self.text;
                return ODCIConst.Success;
            end;
          member function ODCIAggregateMerge(
                                             self in out clobagg_type ,
                                             ctx2 in     clobagg_type
            return number
            is
            begin
                self.text := self.text || ctx2.text;
                return ODCIConst.Success;
            end;
    end;
    create or replace
      function clobagg(
                       input clob
        return clob
        deterministic
        parallel_enable
        aggregate using clobagg_type;
    SQL> select trim(',' from clobagg(ename||',')) as enames from emp;
    ENAMES
    SMITH,ALLEN,WARD,JONES,MARTIN,BLAKE,CLARK,SCOTT,KING,TURNER,ADAMS,JAMES,FORD,MILLER
    SQL>Not my code, just one I've picked up from elsewhere over time.

  • OBIEE 10g Java Custom Authenticator

    I've scoured the web and these forums and I think I know the answer, but I'll ask anyways.
    I need to write a custom authenticator. I want to write it in Java if I can. I see there is an 'obicustomauthenticator.jar' in /OracleBI/web/sdk. Any chance I can use that and hook it in so that I can avoid having to do this in C++? If so, how?
    Thanks in advance
    Andy O

    Turribeach wrote:
    I am under the impression that OBI doesn't support GROUPs very well in LDAP.Correct, but there are several options. Here is one way of getting group information from LDAP:
    http://oraclebizint.wordpress.com/2007/10/12/oracle-bi-ee-101332-and-oid-user-and-group-phase-2/
    Yup, saw that. Might just go with it as we're also considering migrating to OBI 11g in the not-too-distant future.
    IIRC, the SSO solution only passes USER info, not groups along w/ it so wrapping OBI w/ a thin Java Security webapp won't work.You can pass custom variables via SSO so you could potentially pass a variable with a concatenated list of groups and then break them up in rows in an Init Block.Hmm. Have any specifics re: that option? Would likely work as well for us, but I'm a bit unclear how you get other variables from SSO into OBI...

  • OBIEE Group By on 2 facts and concatenated columns from different dimensions

    Hi
    I have a different kind of problem involving 2 fact tables with different dimensional attributes.
    Fact 1 has Dim Attributes ( Cust,Facility )
    Measure - Gross Amount
    Fact2 has Dim attributes (Cust,Facility and Risk Group )
    Measure : Exposure Amount
    Since we have 2 facts with different dimensions,
    to exclude the 'Risk Group' dimension column from the group by for the Fact1,
    we set the 'Gross Amount' measure to total level (Risk Group Dimension ) in contents tab.
    So the values from both the fact tables appears in the same report correctly.
    But in the same report we have another requirement where the rating column from the customer dimension has to be concatenated with the ratings column in the facility dimension.
    We have to concatenate customer.rating with the facility.rating and display it in the report.
    when we just pull the individual columns from the dimensions into the report it works fine.
    But when we try to concatenate the 2 columns and show it in the report,
    the concatenated column does not appear in the select or the group by in the SQL Fact2.( Generated by OBIEE )
    The other fact1 has the concatenated column in the select as well as the group by clause ( Generated by OBIEE )
    As a result the report shows the concatenated values only for the results from the Fact1. But the results from Fact2 does not have the concatenated column values.
    The report should look like the below:
    Custor.Name,     Customer.Id,     Facility.Name,     Facility.Id,     Customer.Rating/Facility.Rating,     Risk Group,     Gross Amount,     Exposure Amount
    ===========    =========      ===========     =========   ========================      =========     ===========     ===============
    JPMC                123                    GROSS               123               08/10                                                  LNL                    45,000               25,000
    CLAIRE               456                    NET                    456               07/10                                                  RNK                    50,000               30,000
    Thanks,
    Chandra

    As suggested you really want to move your none-aggregated fact attributes to a logical dimension (using the same physical table as the logical fact). Map this in the BMM layer as a snowflake, Place a hierarchy on this dimension with (at minimum) Total -> Detail levels, then on the other fact table you want to include in the report, set the content level on your other fact measures to the 'Total' level for your new logical Dim and it will allow them to be present in the same report.

  • Data Concatenation - Looking to have result in the Group header

    Dear all,
    Few months ago, I try to concatenate cells under a Group,
    I succeed using the formula gave by Raghavendra 
    Initialize:
    whileprintingrecords;
    stringvar i:="";
    Place the above formula in group header and suppress group header section.
    evaluate:
    whileprintingrecords;
    stringvar i;
    i:=i", "name field;
    Place the above formula in detail section and suppress the details section.
    display:
    whileprintingrecords;
    stringvar i;
    country field" - "i;
    Place the above formula in group footer and right click go to format field and check the option "can grow" in common tab.
    My today issues is that I'm still looking for concatenation but I need it in the Header of the Group, not in the footer
    As far as I understood
      - Crystal Report is reading line by Line, so I can't retrieve the value in the Header before the value are calculate.
      - Moreover I've issue on initialize the value
    I thougth an GlobalVar Array can work, but I can't find the way to do it
    My request is, I've have this DataSet
    Paris | Louvre
    Paris | Eiffel
    Sydney | Opéra
    I'm looking Group on City to have in the Header, the value concatened
    Paris | Louvre, Eiffel
    Sydney | Opéra
    Thanks in advance
    Edited by: Alexandre VANNIER on Dec 2, 2008 2:09 PM

    if i have manual running totals that need to display in the header i do the following
    i create the group - ie- jobid
    i either insert a sub group below or create a 2nd group with the same field
    then i create a 3rd group with the same field
    i place my reset in the 1st group
    calc in 2nd
    display in 3rd

  • Grouping and Concatenating of Data

    SQL> DESC TEST
    Name                                      Null?    Type
    BAND                                               VARCHAR2(2)
    BRANCH_CODE                                        VARCHAR2(4)
    COUNTRY                                            VARCHAR2(3)
    SERVICE_CATEGORY                                   VARCHAR2(2)
    RESIDENTIAL                                        VARCHAR2(1)
    COMMERCIAL                                         VARCHAR2(1)
    ZIP_CODE                                           VARCHAR2(5)
    SQL>SELECT BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL, ZIP_CODE
    FROM TEST
    GROUP BY BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL, ZIP_CODE
    ORDER BY BAND, BRANCH_CODE, COUNTRY, SERVICE_CATEGORY, RESIDENTIAL, COMMERCIAL;
    BA BRAN COU SE R C ZIP_C
    TM 2001 US  PC N Y 32011
    TM 2001 US  PC N Y 56321
    TM 2001 US  PC Y N 01011
    TM 2001 US  PC Y N 01206
    TM 2001 US  PC Y N 01302
    TM 2003 CAN TC Y N 90981
    TQ 2005 BAU PC N Y 98180
    TQ 2005 BAU PC N Y 98321
    TQ 2005 BAU PC N Y 98734
    TQ 2005 BAU PC Y N 93672
    10 rows selected.I want to pull the data by concatenating the zip_code based on the unique combination of other fields :
    And the result should be like :
    BA BRAN COU SE R C ZIP_CODE
    TM 2001 US  PC N Y 32011|56321
    TM 2001 US  PC Y N 01011|01206|01302
    TM 2003 CAN TC Y N 90981
    TQ 2005 BAU PC N Y 98180|98321|98734
    TQ 2005 BAU PC Y N 93672If anyone can provide some inputs that would be great ...

    Frank Kulash wrote:
    You don't have to use all of the techniques from http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
    Hi Frank,
    The link provides sub-optimal technique using analytic ROW_NUMBER. I mentioned this many times on the forum - there is no need to group by:
    SELECT  BAND,
            BRANCH_CODE,
            COUNTRY,
            SERVICE_CATEGORY,
            RESIDENTIAL,
            COMMERCIAL,
            LTRIM(SYS_CONNECT_BY_PATH(ZIP_CODE,'|'),'|') ZIP_CODE
      FROM (
            SELECT  t.*,
                    ROW_NUMBER() OVER(PARTITION BY BAND,BRANCH_CODE,COUNTRY,SERVICE_CATEGORY,RESIDENTIAL,COMMERCIAL ORDER BY ZIP_CODE) RN
              FROM  TEST t
      WHERE CONNECT_BY_ISLEAF = 1
      START WITH RN = 1
      CONNECT BY RN = PRIOR RN + 1
      ORDER BY BAND,
               BRANCH_CODE,
               COUNTRY,
               SERVICE_CATEGORY,
               RESIDENTIAL,
               COMMERCIAL
    /And same for pre-10g versions:
    SELECT  BAND,
            BRANCH_CODE,
            COUNTRY,
            SERVICE_CATEGORY,
            RESIDENTIAL,
            COMMERCIAL,
            LTRIM(SYS_CONNECT_BY_PATH(ZIP_CODE,'|'),'|') ZIP_CODE
      FROM (
            SELECT  t.*,
                    ROW_NUMBER() OVER(PARTITION BY BAND,BRANCH_CODE,COUNTRY,SERVICE_CATEGORY,RESIDENTIAL,COMMERCIAL ORDER BY ZIP_CODE) RN,
                    COUNT(*) OVER(PARTITION BY BAND,BRANCH_CODE,COUNTRY,SERVICE_CATEGORY,RESIDENTIAL,COMMERCIAL) CNT
              FROM  TEST t
      WHERE RN = 1
      START WITH RN = CNT
      CONNECT BY RN = PRIOR RN + 1
      ORDER BY BAND,
               BRANCH_CODE,
               COUNTRY,
               SERVICE_CATEGORY,
               RESIDENTIAL,
               COMMERCIAL
    /SY.

  • Group By Concatenated Value

    Hi, just looking for some help with concatenated fields as getting an error (ORA-00904: "USERNAME": invalid identifier)
    Currently I have the following code:
    select table2.userid, table1.forename||' '||table1.surname AS username
    from table2 inner join table1
    on table2.telno = table1.dir_no
    group by table2.userid, username;Any ideas where I am going as not used concatenated values before.
    Any help would be appreciated.

    You cannot use an alias in the group by.
    group by table2.userid, table1.forename||' '||table1.surname

  • SQL query group by with concatenation

    How can i put the name of the column i concatenated in group by command?
    Example is:
    tbl_staff
    user_id     name          profile          last_name
    1     una          0001          astfirst
    2     pangalawa     0001          lastsecond
    3 pangatlo     0001          lastthird
    4 pangapat     0001          lastfourth
    5 panglima     0002          lastfifth
    tbl_work_assignment
    wa_id     handled_by     status
    10     1          active
    20     1          active
    30     2          closed
    40     3          active
    50     3          closed
    60     3          active
    If my Query is:
    select s.user_id, s.name, count(wa.wa_id)
    from tbl_staff s
    left join tbl_work_assignment wa
    on wa.handled_by = s.user_id
    where profile = '0001' and status = 'active'
    group by s.user_id, s.name
    I will get this result
    s.user_id     s.name          count(wa.wa_id)
    1          una          2
    3          pangatlo     2
    My question is:
    "HOW CAN I CONCATENATE THE 'NAME' AND 'LAST_NAME' COLUMNS AND PUT THEIR COLUMN NAME IN GROUP BY?"
    Desired Resultset is:
    s.user_id     s.name          full_name count(wa.wa_id)
    1          una          una lastfirst 2
    3          pangatlo     pangatlo lastthird 2
    I hope you understood my question.. I can explain further if its not clear. Thanks

    And the proof that Alex's last suggestion works:
    SQL> create table tbl_staff (user_id,name,profile,last_name)
      2  as
      3  select 1, 'una', '0001', 'astfirst' from dual union all
      4  select 2, 'pangalawa', '0001', 'lastsecond' from dual union all
      5  select 3, 'pangatlo', '0001', 'lastthird' from dual union all
      6  select 4, 'pangapat', '0001', 'lastfourth' from dual union all
      7  select 5, 'panglima', '0002', 'lastfifth' from dual
      8  /
    Tabel is aangemaakt.
    SQL> create table tbl_work_assignment (wa_id,handled_by,status)
      2  as
      3  select 10, 1, 'active' from dual union all
      4  select 20, 1, 'active' from dual union all
      5  select 30, 2, 'closed' from dual union all
      6  select 40, 3, 'active' from dual union all
      7  select 50, 3, 'closed' from dual union all
      8  select 60, 3, 'active' from dual
      9  /
    Tabel is aangemaakt.
    SQL> select s.user_id
      2       , s.name
      3       , s.name || ' ' || s.last_name full_name
      4       , count(wa.wa_id)
      5    from tbl_staff s
      6         left join tbl_work_assignment wa on wa.handled_by = s.user_id
      7   where profile = '0001'
      8     and status = 'active'
      9   group by s.user_id
    10       , s.name
    11       , s.last_name
    12  /
       USER_ID NAME      FULL_NAME            COUNT(WA.WA_ID)
             1 una       una astfirst                       2
             3 pangatlo  pangatlo lastthird                 2
    2 rijen zijn geselecteerd.Regards,
    Rob.

  • Grouping by a concatenated field?

    I have a report with 1 group and 3 additional sort fields. What I'd LIKE to do is have a single field that I add all the sort fields into, to create a single field, and then group by that. So that any time any of the elements of that field change, it triggers the group change. For example:
    Group on: FIELD1
    Sort on: FIELD2, FIELD3, FIELD4
    Goal:
    Build a single string, MyStr := FIELD1 + FIELD2 + FIELD3 + FIELD4
    Remove all groups and sorts, then group on that formula field.
    Can that be done, and if so, can someone point me in the right direction?
    Thanks a million! You guys are really helping me get this project off the ground.
    (CR2010)
    ETA: Though this sounds ridiculous, this particular report would benefit greatly from this methodology. Long story (sigh).

    On another thread I posted this morning, I asked for assistance with creating a string in which multiple Hard Drive capacities were placed (i.e. "500G, 1T, 2T", etc) and only displayed when the group changed. While that worked well, there are SIX total group/sort fields. I would really like to combine all those into a single string, group on that, and insert the formula when the group changes. It seems easier than trying to manage so many fields. If I want to keep them individual, I have to change them all to Groups, because when any ONE of those fields changes (and yes, the are in order of frequency-of-change), I'd need to display a line of data that would include the capacity string.
    The detail section would be entirely suppressed.
    It just seems that it would be easier to have a single group to manage, rather than a group plus 4 or more sort fields.

  • Sql group by query and concatenation

    Hi folks,
    I have question.I need to concatenate the columns like this.
    i/p
    i_txt txt
    1000 abc
    1000 def
    1001 things
    1001 to
    1001 do
    1002 is
    1002 it
    1002 possible
    O/P should be like this
    i_txt txt
    1000 abcdef
    1001 things to do
    1002 is it possible
    Thanks in advance
    Raj

    Tubby's provided the useful search term: String Aggregation.
    Assuming you've studied Tim's article, you now know that the approach and techniques you can use are database-version dependant.
    So, please: always mention your database-version when posting a question.
    Now, when looking at your desired output, it looks like a simple string aggregation question, however:
    You don't seem to want 'abcdef' connected by a space?
    Without knowing why, you can use case and replace the space for that specific i_txt.
    But, that requires some hard-coding:
    SQL> select * from t;
         I_TXT TXT
          1000 abc
          1000 def
          1001 things
          1001 to
          1001 do
          1002 is
          1002 it
          1002 possible
    8 rows selected.
    SQL> select i_txt
      2  ,      ltrim(sys_connect_by_path(txt, ' '), ' ') txt
      3  from ( select i_txt
      4         ,      txt
      5         ,      row_number() over (partition by i_txt order by i_txt ) rn
      6         from t
      7       )
      8  where connect_by_isleaf=1    
      9  start with rn=1
    10  connect by i_txt = prior i_txt
    11         and rn = prior rn+1;
         I_TXT TXT
          1000 abc def
          1001 things to do
          1002 is it possible
    3 rows selected.
    SQL> select i_txt
      2  ,      case i_txt
      3           when 1000
      4           then  replace(sys_connect_by_path(txt, ' '), ' ')
      5           else  ltrim(sys_connect_by_path(txt, ' '), ' ')
      6         end txt
      7  from ( select i_txt
      8         ,      txt
      9         ,      row_number() over (partition by i_txt order by i_txt ) rn
    10         from t
    11       )
    12  where connect_by_isleaf=1    
    13  start with rn=1
    14  connect by i_txt = prior i_txt
    15         and rn = prior rn+1;
         I_TXT TXT
          1000 abcdef
          1001 things to do
          1002 is it possible
    3 rows selected. This example works when you're on database version 10G and onwards.
    Perhaps we could find other ways, if you can explain when you do and do not want your strings aggregated/concatenated by a space

  • How to concatenated columns group by clause

    with apps AS (
    SELECT 'a' AS APP_ID,1 AS RANK FROM DUAL
    UNION
    SELECT 'a' AS APP_ID,2 AS RANK FROM DUAL
    UNION
    SELECT 'a' AS APP_ID,3 AS RANK FROM DUAL
    UNION
    SELECT 'b' AS APP_ID,4 AS RANK FROM DUAL
    UNION
    SELECT 'b' AS APP_ID,5 AS RANK FROM DUAL
    UNION
    SELECT 'c' AS APP_ID,6 AS RANK FROM DUAL
    SELECT APP_ID,RANK FROM apps ORDER BY 2;
    A RANK
    a 1
    a 2
    a 3
    b 4
    b 5
    c 6
    6 rows selected.
    concatenated_column
    a,1, 2,3
    b,4, 5
    c,6

    Few days earlier someone has posted this - i think this might help u---
    CREATE OR REPLACE FUNCTION scott.rowtocol(p_slct IN VARCHAR2,p_dlmtr IN VARCHAR2 DEFAULT ',')
    RETURN VARCHAR2 AUTHID CURRENT_USER
    AS
      TYPE c_refcur IS REF CURSOR;
      lc_str VARCHAR2 (4000);
      lc_colval VARCHAR2 (4000);
      c_dummy c_refcur;
    BEGIN
      OPEN c_dummy FOR p_slct;
      LOOP
        FETCH c_dummy
        INTO lc_colval;
        EXIT WHEN c_dummy%NOTFOUND;
        lc_str := lc_str || p_dlmtr || lc_colval;
      END LOOP;
      CLOSE c_dummy;
      RETURN SUBSTR (lc_str, 2);
    END;
    SELECT DISTINCT a.job,
                    rowtocol
                    ( 'SELECT ename FROM emp WHERE job = '
                      || ''''
                      || a.job
                      || ''''
                      || ' ORDER BY ename'
                    ) AS employees
    FROM emp a;
    JOB                  EMPLOYEES
    SALESMAN      ALLEN,MARTIN,TURNER,WARD
    CLERK             ADAMS,Avik,BARRY,MILLER,Roni,prithwi
    ANALYST         FORD,SCOTT
    PRESIDENT      KING
    MANAGER        BLAKE,CLARK,JONESRegards.
    Satyaki De.

  • Concatenating values in one row

    I need to write a function that will give me a concatenated list of all the records where gurmail_matl_code_mod like '8%'
    This query is giving me those results:
    GURMAIL_PIDM     CODE1     CODE2
    1135711          
    1135711          8IBD
    1135711     8IBW     
    I want something like this 1135711 8IBW 8IBD in one row.
    select
    gurmail_pidm,
    max(decode(rn,1,gurmail_matl_code_mod )) code1,
    max(decode(rn,2,gurmail_matl_code_mod )) code2
    from (select gurmail_pidm,
                  gurmail_matl_code_mod,
                  row_number() over (partition by gurmail_pidm order by gurmail_matl_code_mod desc) rn
                  from
                      (select  gurmail_pidm,gurmail_matl_code_mod
                               from saturn.spriden,
                                    general.gurmail
                                    where spriden_pidm = gurmail_pidm
                                    and spriden_change_ind is null
                                    and gurmail_matl_code_mod  like '8%'
                                    and gurmail_pidm = 1135711
                                    and GURMAIL_DATE_PRINTED is null
                                    and gurmail_matl_code_mod is not null))
                                    group by gurmail_pidm, gurmail_matl_code_mod   How I can modify this query or let me know if you have other ideas..
    Thank you

    Hello
    try this,
    SQL>  with tab as(Select 1135711 GURMAIL_PIDM, Null CODE1 from dual Union All
      2               Select 1135711 GURMAIL_PIDM, '8IBD' CODE1 from dual Union All
      3               Select 1135711 GURMAIL_PIDM, '8IBW' CODE1 from dual)
      4  SELECT GURMAIL_PIDM || sys_connect_by_path(CODE1,' ') Result
      5    FROM (SELECT GURMAIL_PIDM
      6                ,code1
      7                ,row_number() over(Partition BY GURMAIL_PIDM Order BY GURMAIL_PIDM) rn
      8            FROM tab)
      9   WHERE connect_by_isleaf = 1
    10   Start With rn = 1
    11  Connect BY Prior rn = rn - 1;
    RESULT
    1135711  8IBW 8IBDHope this helps
    Christian Balz

  • Create a new Grouping in IBY_FD_EXTRACT_EXT_PUB

    Hi,
    I need to create a new group in  IBY_FD_EXTRACT_EXT_PUB like below.
    eg:
    +*<OutboundPaymentInstruction>*+
    ---+
    +*<OutboundPayment>*+
    ---+
    +*<ExtendValue>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 1</OUTPUTVALUE>+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 2</OUTPUTVALUE>+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 3</OUTPUTVALUE>+
    +*</Extend>*+
    *</ExtendValue*
    +*<OutboundPayment>*+
    ---+
    +*<ExtendValue>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 1</OUTPUTVALUE>+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 2</OUTPUTVALUE>+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 3</OUTPUTVALUE>+
    +*</Extend>*+
    +*</ExtendValue>*+   
    I have got the Concatenated value inside a loop, but I need to split each of the values into 80 characters and then insert it into <OUTPUTVALUE>+
    So, if I have 240 characters, then I need it like+
    +*<OutboundPayment>*+
    ---+
    +*<ExtendValue>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 80 characters*</OUTPUTVALUE>*+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 80 characters*</OUTPUTVALUE>*+
    +*</Extend>*+
    -- <Extend>+
    ---<OUTPUTVALUE>Concatenated Value - 80 characters*</OUTPUTVALUE>*+
    +*</Extend>*+
    +*</ExtendValue>*+
    What I have tried is
    FUNCTION Get_Pmt_Ext_Agg(p_payment_id IN NUMBER)
    RETURN XMLTYPE
    IS
    l_ins_ext_agg XMLTYPE;
    CURSOR get_invoices_cur(cp_payment_id in number) is
    SELECT IDP.document_payable_id DOCUMENT_PAYABLE_ID
    ,SUBSTR(IDP.calling_app_doc_ref_number,1,30) REFERENCE_NUMBER
    ,IDP.payment_amount PAYMENT_AMOUNT
    ,IDP.document_amount DOCUMENT_AMOUNT
    ,IDP.payment_curr_discount_taken DISCOUNT_AMOUNT
    ,SUBSTR(IDP.po_number,1,30) PO_NUMBER
    ,IPA.payment_amount PAYMENT_AMNT
    ,IPA.ext_branch_number EXT_BRANCH_NUMBER
    ,IPA.ext_bank_account_number EXT_BANK_ACCOUNT_NUMBER
    ,IPA.payee_name PAYEE_NAME
    ,IPA.int_bank_name INT_BANK_NAME
    ,IPA.payment_reference_number PAYMENT_REFERENCE_NUMBER
    ,IPA.creation_date CREATION_DATE
    ,IPA.payment_instruction_id PAYMENT_INSTRUCTION_ID
    FROM iby_docs_payable_all IDP
    ,ap_invoices_all AIA
    ,iby_payments_all IPA
    WHERE AIA.invoice_id = idp.calling_app_doc_unique_ref2
    AND IPA.payment_id = IDP.payment_id
    AND IDP.payment_id = cp_payment_id;
    BEGIN
    <Initialize all valiables>
    FOR get_invoices_rec IN get_invoices_cur(p_payment_id)
    LOOP
    lc_concatenate: = <Get the concanated Value as required>;
    lc_split:= < Written some logic to split it into char >
    BEGIN
    SELECT XMLConcat(
    XMLElement("Extend",
    XMLElement("lc_value1" lc_split))
    INTO lc_extendval
    FROM dual
    END;
    END LOOP;
    BEGIN
    SELECT XMLConcat(
    XMLElement("ExtendVal",lc_extendval),
    INTO l_ins_ext_agg
    FROM dual;
    END;
    RETURN l_ins_ext_agg;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN NULL;
    END Get_Pmt_Ext_Agg;
    Now, my output comes only as the last 80 characters, I do not have the first 80 and second 80 characters.
    ANy inputs to achieve all the 240 characters split into 3 rows like described above would be helpful.
    Thanks

    >
    Now, my output comes only as the last 80 characters, I do not have the first 80 and second 80 characters.
    >
    based on
    >
    lc_split:= < Written some logic to split it into char >
    >
    so check logic for splitting
    i can't test on your data but
    >
    SELECT XMLConcat(
    XMLElement("Extend",
    XMLElement("lc_value1" lc_split))
    INTO lc_extendval
    FROM dual
    >
    what's code doing?
    looks like it's wrong because it create tag "lc_value1"
    >
    BEGIN
    SELECT XMLConcat(
    XMLElement("ExtendVal",lc_extendval),
    INTO l_ins_ext_agg
    FROM dual;
    END;
    RETURN l_ins_ext_agg;
    >
    what's code doing?
    so try another way
    FUNCTION Get_Pmt_Ext_Agg(p_payment_id IN NUMBER)
    RETURN XMLTYPE
    IS
    l_ins_ext_agg XMLTYPE;
    CURSOR get_invoices_cur(cp_payment_id in number) is
    SELECT IDP.document_payable_id DOCUMENT_PAYABLE_ID
    ,SUBSTR(IDP.calling_app_doc_ref_number,1,30) REFERENCE_NUMBER
    ,IDP.payment_amount PAYMENT_AMOUNT
    ,IDP.document_amount DOCUMENT_AMOUNT
    ,IDP.payment_curr_discount_taken DISCOUNT_AMOUNT
    ,SUBSTR(IDP.po_number,1,30) PO_NUMBER
    ,IPA.payment_amount PAYMENT_AMNT
    ,IPA.ext_branch_number EXT_BRANCH_NUMBER
    ,IPA.ext_bank_account_number EXT_BANK_ACCOUNT_NUMBER
    ,IPA.payee_name PAYEE_NAME
    ,IPA.int_bank_name INT_BANK_NAME
    ,IPA.payment_reference_number PAYMENT_REFERENCE_NUMBER
    ,IPA.creation_date CREATION_DATE
    ,IPA.payment_instruction_id PAYMENT_INSTRUCTION_ID
    FROM iby_docs_payable_all IDP
    ,ap_invoices_all AIA
    ,iby_payments_all IPA
    WHERE AIA.invoice_id = idp.calling_app_doc_unique_ref2
    AND IPA.payment_id = IDP.payment_id
    AND IDP.payment_id = cp_payment_id;
    BEGIN
    <Initialize all valiables>
    FOR get_invoices_rec IN get_invoices_cur(p_payment_id)
    LOOP
    lc_concatenate: = <Get the concanated Value as required>;and add logic for splitting like
    select xmlelement("ExtendValue", xmlagg(xmlelement("Extend", substr(lc_concatenate,1+80*(level-1),80) )))
    INTO lc_extendval
    from dual
    connect by level <= ceil(length(lc_concatenate)/80)so example
    SQL>
    SQL> with t as
      2  (
      3  select 1 id, lpad('a',80,'a') ||lpad('b',80,'b') ||lpad('c',80,'c') str from dual
      4  )
      5  --
      6  select xmlelement("ExtendValue", xmlagg(xmlelement("Extend", substr(str,1+80*(level-1),80) )))
      7  from t
      8  connect by level <= ceil(length(str)/80)
      9  /
    XMLELEMENT("EXTENDVALUE",XMLAG
    <ExtendValue><Extend>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    SQL> if you have some problem then plz post test data

  • Is it possible to number within groups to achieve heirarchal export?

    Hi there!
    I have created a multi-group crystal report using summary totals in the Group Footer.  And, have concatenated some of the fields to create my groups.
    Studies are assigned to one MDC
    Studies can be conducted in many regions, countries and have many centers.
    Group 1 - MDC
    Group 2 - Study ID
    Group 3 - Study ID & Region (concatenated field)
    Group 4 - Study ID & Country (concatenated field)
    Group 3 - Study ID & Center (concatenated field)
    My drill down in crystal preview mode is exactly how it should be ie.:
    Example for one study:
    NEURO
    ABC123456
    ABC123456, North America
    ABC123456, Canada
    ABC123456, 033465
    I would like to achieve the same heirarchal look when exported to excel.  Can anyone provide guidance here?

    Hi,
    Group 1 - MDC
    Group 2 - Study ID
    Create 3 formulas for the below fields and place each one in details section
    Details section 1 - Study ID & Region (concatenated field)
    Details section 2 - Study ID & Country (concatenated field)
    Details section 3 - Study ID & Center (concatenated field)
    Hope this helps,
    Jyothi
    Edited by: Jyothi Yepuri on Sep 1, 2009 4:51 AM

  • Sort order for group by functions

    I have table TAB1(notenum number, linenum number, linetext varchar2(100)).
    Each note can have multiple lines of text. Eg data
    NOTENUM     LINENUM     LINETEXT
    1     1     THIS IS LINE1.
    1     2     THIS IS LINE2.
    2     1     THIS IS LINE1 OF NOTE2.
    2     2     THIS IS LINE2 OF NOTE2.
    I need the text of lines of the most recent note (max notenum)
    <Note>THIS IS LINE1 OF NOTE2. THIS IS LINE2 OF NOTE2</Note>.
    I have a query like this
    SELECT XMLAGG(XMLPARSE(CONTENT LINETEXT WELLFORMED))
    FROM TAB1
    GROUP BY NOTENUM
    ORDER BY NOTENUM DESC
    Above query would return the text of all lines concatenated for each note and the first row would be the one with highest notenum value.
    My problem is that concatenation of the LINETEXT should happen in ascending order of LINENUM. Since LINENUM is not in GROUP BY clause I cannot specify it in ORDER BY.
    How can I specify to XMLAGG (for that matter any group by function) to concatenate text in a specific order.
    I hope I was able to explain my problem clear enough for somebody to help.
    thanks for all the help
    Message was edited by:
    user448703
    Message was edited by:
    user448703

    Never mind. I just found out that XMLAGG function has the option to specify ORDER BY. I think that will work.

Maybe you are looking for