Multiple lines in a single column in an SQL statement

Can someone provide me with a simple sql that runs on the underside of the table (USERROLE table)

ID ROLEUSER ROLENAME

1 user1 GL
User2 OBI_AP 2
User1 3 OBI_AP
User2 4 GL
User1 5 OBI_AR
User2 6 AR
7 the GL util_3

and give the result form

ROLENAMES ROLEUSER

User1 GL; OBI_AP; OBI_AR
User2 OBI_AP; GL; AR
the GL util_3


Thank you
Vikram

Hello

There is a similar thread, you can watch: concatenate the values of column in a row

Kind regards

Tags: Database

Similar Questions

  • Create views of data from multiple lines in a single column shows

    Hi all - it's probably posted in the wrong forum, but I couldn't find that was right.

    I'm almost a perfect beginner in sql, but I have a need to create a view that can be expanded to 10g (which effectively runs the volumes are likely to be high) who will do the following.

    Authentic table with columns Parent_code, Child_code
    Parent_Code Child_Code
    1000-2000
    1000-3000
    1000-4000
    2000 3000
    2000-5000

    (note that Parents may have several children and a child can have multiple parents!)

    What I have to finish with in my opinion is the following

    Child_Code Parent_List
    ' 2000 ' 1000 (3).
    3000 "1000 (3), 2000 (2)"
    ' 4000 ' 1000 (3).
    "5000 ' 2000 (2)"

    Note the number in parentheses is the number of children whose parent's - IE in the original parent a 1000, 3 table lines (one for each child)

    This point of view should be used as a quick glance upward (on the children's code) for a report of business objects.

    Is there someone who could you PLEASE, PLEASE help me quickly on what I have very little time to find a solution?

    Hello

    You can test these:

    select child_code
         , ltrim(sys_connect_by_path(parent_info,', '), ', ') as parent_list
    from (
      select child_code
           , to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
           , row_number() over(partition by child_code order by parent_code) rn
      from your_table
    )
    where connect_by_isleaf = 1
    connect by prior rn = rn-1
           and prior child_code = child_code
    start with rn = 1
    ;
    
    select child_code,
           rtrim(
             extract(
               xmlagg(xmlelement("e",parent_info||', ') order by parent_info)
             , '//text()'
             )
           , ', '
           ) as parent_list
    from (
      select child_code,
             to_char(parent_code) ||
             ' (' ||
             count(*) over(partition by parent_code) ||
             ')' as parent_info
      from your_table
    )
    group by child_code
    ;
    

    What you need is called 'chain aggregation '.
    See here for the various techniques, including the two above: http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

  • value of multiple line in a single row (nclob)

    Hello
    I have a requirement where I have to work on a nclob data type column, now here the value of 2 lines in a single column. Like this:

    Select extractvalue (xmltype (details), '/ Anything/invoiceNumber') separate as invoices,
    actinguserid as user_id, createdt
    of bchistevent where bucket = 201301
    and upper (type) = ' COM. AVOLENT. PRESENTATION. EVENT. INVOICEDOWNLOADEVENT'
    - and bchistevent.bucket = to_char (add_months (sysdate-1), "YYYYMM")

    000-395452969-20130103 1.46388193452398E37 08/01/2013 03:05:42
    300000590-000-20090723 1.46388193452398E37 11/01/2013 08:11:45
    300000590-000-20090723 1.46388193452398E37 11/01/2013 08:12:50
    000-395453127-20130103 1.46388193452398E37 14/01/2013 04:44:26
    * 300084670-000-20120906, 300084671-000-20120906 * 1.46388193452398E37 07/01/2013 12:45:19 AM
    000-395452626-20130103 1.46388193452398E37 08/01/2013 03:03:57
    000-300084679-20120906-1.46388193452398E37 11/01/2013 08:10:47
    300000728-000-20090731 1.46388193452398E37 11/01/2013 08:19:19
    000-300084679-20120906 1.46388193452398E37 14/01/2013 12:31:48 AM
    300000590-000-20090723 1.46388193452398E37 14/01/2013 04:13:19
    000-395452718-20130103 1.46388193452398E37 08/01/2013 07:10:19
    000-300084679-20120906 1.46388193452398E37 23/01/2013 06:54:11
    000-300084679-20120906 1.46388193452398E37 22/01/2013 03:11:54
    300000590-000-20090723 1.46388193452398E37 11/01/2013 08:14:02
    000-395453127-20130103 1.46388193452398E37 14/01/2013 04:33:12
    000-300084679-20120906 1.46388193452398E37 22/01/2013 03:03:36
    000-300084679-20120906 1.46388193452398E37 14/01/2013 12:34:13 AM
    000-395452997-20130103 1.46388193452398E37 07/01/2013 03:31:38
    000-395452391-20121027 1.46388193452398E37 03/01/2013 04:40:05

    and the value of the "BOLD" highlighted line is coming in a single line, please help how to break this in 2 rows?

    Published by: user1175303 on March 13, 2013 05:43

    user1175303 wrote:
    the value of the column that is involved is 300084670-000-20120906, 300084671-000-20120906 here I get 2 values in a single column, and for this reason, I am unable to get the desired result.

    If you have XML question but try to solve in Oracle? Why is the owner of two invoice numbers? In any case:

    with t as (
               select  distinct extractvalue(xmltype(details),'/Anything/invoiceNumber') as invoices,
                       actinguserid as user_id,
                       createdt
                 from  bchistevent
                 where bucket = 201301
                   and upper(type) = 'COM.AVOLENT.PRESENTATION.EVENT.INVOICEDOWNLOADEVENT'
              )
    select  regexp_substr(invoices,'[^,]+',1,column_value) invoices,
            user_id,
            createdt
      from  t,
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= length(regexp_replace(invoices,'[^,]')) + 1
                               )
                       as sys.OdciNumberList
                      )
                 )
    /
    

    SY.

  • How to insert multiple lines using a single query

    Hi all

    How to insert multiple lines using a single query to the emp table?
    I have the number of rows to insert into table x. consumes a lot of time. I tried to insert several lines using a single query, but get errors. I know exactly the query to do this.


    Thank you
    Sunil

    Like this?

    SQL> create table test(id number , dt date);
    
    Table created.
    
    SQL> insert into test values(&a,&b);
    Enter value for a: 1   --- It asked me and I entered 1
    Enter value for b: sysdate  --- It asked me and I entered sysdate
    old   1: insert into test values(&a,&b)
    new   1: insert into test values(1,sysdate)
    
    1 row created.
    
    SQL> 
    

    g.

  • Convert multiple lines in a single value separated by commas

    Is is possible to convert multiple lines in a single value by concatenating the value of each line in OBIEE. I think that IO had seem a blog related to this by I'm not able to find him. Essentially, here's what I would do:
    Number of customer location
    101
    101 NY
    101 PA
    102 TX
    102 CA

    This is to convert
    101. HE, NY, PA
    102 TX, CA

    Can you get it someone please let me know if this is possible and how to operate it.

    Thanks in advance for the help.

    You can do this by creating a DB function,

    Visit this link
    Re: Display of the horizontal values

    Thank you
    Vino

  • Convert lines to a single column

    Hi all


    Need help, I have a table where I want the output to a single column

    ex: Select in t1. *
    the query result_

    rownum col_1
    1 8217
    2 6037
    3-5368
    4 5543
    5 5232

    I want the result to be: * 8217,6037,5368,5543,5232 *.


    Thank you for your help in advance.

    I search the web but couldn't find a solution that is easily understandable.

    WM_CONCAT is not documented, so not everyone would want to use it in production code.
    However, SYS_CONNECT_BY_PATH might work:

    SQL> create table t as
      2  select 1 rn, 8217 count_1 from dual union
      3  select 2, 6037 from dual union
      4  select 3, 5368 from dual union
      5  select 4, 5543 from dual union
      6  select 5, 5232  from dual;
    
    Table created.
    
    SQL> select * from t;
    
           RN    COUNT_1
    --------- ----------
            1       8217
            2       6037
            3       5368
            4       5543
            5       5232
    
    5 rows selected.
    
    SQL>
    SQL> select rownum
      2  ,      ltrim(sys_connect_by_path(count_1, ','), ',') count_1
      3  from   t
      4  where  connect_by_isleaf=1
      5  start with t.rn=1
      6  connect by t.rn  = prior t.rn+1;
    
     ROWNUM
    -------
    COUNT_1
    -------------------------------------------------------------------------------------
          1
    8217,6037,5368,5543,5232
    
    1 row selected.
    

    Or LISTAGG on 11.2:

    SQL> select listagg(count_1, ',') within group (order by rn) agged from t;
    
    AGGED
    -------------------------
    8217,6037,5368,5543,5232
    
    1 row selected.
    

    I really hope that you do not really use ROWNUM as column name? I used instead RN...

  • Multiple lines in a single pipe delimited lines...

    Hi all

    I have the following data in multiple columns that should be converted online unique pipedelimited.
    Following is the example:

    DEPTNO ENAME
    ===== =====
    10A
    10 B
    10 C

    Now my requirement is to output, I should be able poster A | B | C|.........

    Note: The number of lines for any DEPTNO is not constant.

    Thank you
    Kalyan Kumar P

    The link that allowed to Hoek

    SELECT
           LTRIM(MAX(SYS_CONNECT_BY_PATH(ename,','))
           KEEP (DENSE_RANK LAST ORDER BY curr),',') AS employees
    FROM   (SELECT deptno,
                   ename,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) AS curr,
                   ROW_NUMBER() OVER (PARTITION BY deptno ORDER BY ename) -1 AS prev
            FROM   emp WHERE deptno=10)
    GROUP BY deptno
    CONNECT BY prev = PRIOR curr AND deptno = PRIOR deptno
    START WITH curr = 1
    

    If please visit once and read it.

    Kind regards
    Bobin

  • Convert different lines in a single column

    DB: 11.1.0.7
    Operating system: Solaris Sparc 5.10

    I have a query that is joining a few tables and give me output like below.
    personnum orgnm
    ======= =======
    The 6 key holder
    9 sales
    3 Mgmt

    I would like to only convert a single as column below.

    col1
    ========
    6, keeper of the key, 9, sales, 3, Mgmt

    I tried with pivot and decode, but not get out that I'm exepcting. Any suggesstions?

    yashwanth437 wrote:
    listagg() function might work.

    LISTAGG is not available in 11.1. It was introduced in 11.2.

    In any case, XML solution:

    with sample_table as (
                          select 6 personnum,'Keyholder' orgnm from dual union all
                          select 9,'Sales' from dual union all
                          select 3,'Mgmt' from dual
                         )
    select  rtrim(xmlagg(xmlelement(e,personnum || ',' || orgnm,',').extract('//text()')),',') col1
      from  sample_table
    /
    
    COL1
    ---------------------------
    6,Keyholder,9,Sales,3,Mgmt
    
    SQL> 
    

    SY.

  • Splitting of multiple lines on a single line with different fields

    Hi all

    I have a table. A Course_Code have section_codes several other words ('NUM' column is not sectype is just an order!)

    Code---num---Sec_code---Sectype---DESC---WEIGHT
    1603 1 - C 7427 - Coursework - 50
    1603--------2-------7428-----------E------------     Exam----------------     50

    I query this table I want to be able to see the course work, review divided on the same line. i.e.


    Code - Coursework - review
    1603 C = 50 - E = 50

    any help would be great

    Hello

    'Splitting' means take an element (such s as a string 'C = 50') and diviiding in smal; LER objects (such as the chains under "C" and "50"). Are you really trying to divide something, or are you trying to do exactly the opposite (for example, combine smaller chains in a larger string)?

    I think that what you are looking for is a Pivot . Like so many other things, exactly how do depends on your version of Oracle and your needs.
    Here's one way:

    SELECT       code
    ,       MIN (CASE WHEN descr = 'Coursework' THEN sectype END)
           ||  '='
           MIN (CASE WHEN descr = 'Coursework' THEN weight  END)     AS coursework
    ,       MIN (CASE WHEN descr = 'Exam'       THEN sectype END)
           ||  '='
           MIN (CASE WHEN descr = 'Exam'           THEN weight  END)     AS exam
    FROM       table_x
    GROUP BY  code
    ;
    

    It will work in Oracle 8.1 and higher. From Oracle 11.1, you can also use the SELECT... Function PIVOT.

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • Multiple lines in a single count

    Hello

    I have a table (join actually) similar to the following:

    Tree leaf... TLigne
    1... 1... 1
    1... 2... 2
    2... 3... 1
    3... 4... 2
    3... 5... 3
    3... 6... 3
    3... 7... 3

    What would be the best approach if I wanted to count the frequency of each type of leaf per tree?
    The goal contains a line for each tree and three different columns representing
    the number of occurrences of each journal type.

    Example:

    tree... LT1... LT2... LT3
    1... 1... 1... 0
    2... 1... 0... 0
    3... 0... 1... 3

    Thanks for any help.

    >

    Select tree, sum (decode (TLigne, 1, 1, 0)), sum (decode (TLigne, 2, 1, 0)), sum (decode (TLigne, 3, 1, 0)))

    Select 1 tree, 1 extension, 1 TLigne of all the double union

    Select TLigne 1,2,2 Union double all the

    Select TLigne 2,3,1 Union double all the

    Select 3,4,2 TLigne from all the double union

    Select TLigne 3,5,3 of all the double union

    Select 3,6,3 TLigne from all the double union

    Select 3,7,3 double TLigne

    )

    Group by tree

    Kind regards
    Ritesh

    Published by: Ritesh Kumar S on December 25, 2008 15:56

  • Combine multiple lines in a single line

    Hello

    I want the output of several data of line in a row.

    I try to display the supervisor of people and their supervisors and so on. I am able to display the Level1 supervisor and not able to display the next level.

    Here is the code:

    
    
    

    with

    Nobody like

    (select person_id 100299, employee_name 'VELASCO, OMAR' Union double all the)

    58293, select "UREÑA, PABLO" Union double all the

    Select 98539, 'USLENGHI, MATIAS slimani' Union double all the

    Select 68240, "Slimani, Mr. Vrishal A" Union double all the

    Select 72230, 'Harvey, Mr. Darin S' Union double all the

    Select 76200, 'CLARK, TIM MIDDLE EAST' of all the double union

    Select 67819, "BOEHLER, JEFF a." everything double union

    29202, select "FRADIN, ROGER" the double

    ),

    master_slave as

    (select 100299 slave, master 58293 Union double all the)

    Select 58293,98539 from all the double union

    Select 98539,68240 from all the double union

    Select 68240,72230 from all the double union

    Select 72230,76200 from all the double union

    Select 76200,67819 from all the double union

    Select 67819,29202 from all the double union

    Select 29202, the double null

    ),

    hierarchy as

    (select level lvl, sys_connect_by_path(slave,'|') path, max (level) on max_level)

    of master_slave

    where connect_by_isleaf = 1

    connect by slave = master prior

    ),

    Splitter (LVL, person_id, supervisor_1, supervisor_2, path) as

    (select lvl,

    regexp_substr (path '(\ |) [ ^|] +)', 1, 1, null, 1).

    regexp_substr (path '(\ |) [ ^|] +)', 1, 2, null, 1).

    regexp_substr (path '(\ |) [ ^|] +)', 1, 3, null, 1).

    regexp_replace (path,'^-|) [ ^|] +')

    of the hierarchy

    where lvl = max_level

    Union of all the

    Select lvl,

    regexp_substr (path '(\ |) [ ^|] +)', 1, 1, null, 1).

    regexp_substr (path '(\ |) [ ^|] +)', 1, 2, null, 1).

    regexp_substr (path '(\ |) [ ^|] +)', 1, 3, null, 1).

    regexp_replace (path,'^-|) [ ^|] +')

    between the separator

    where path is not null

    )

    Select person_id, to_number (ltrim(s.person_id,'|')),

    (select employee_name from person where person_id = to_number (ltrim(s.person_id,'|'))) employee_name,

    (select employee_name from person where person_id = to_number (ltrim(s.supervisor_1,'|'))) supervisor_1,

    (select employee_name from person where person_id = to_number (ltrim(s.supervisor_2,'|'))) supervisor_2

    s separator

    where s.person_id is not null

    order by length (s.path) desc nulls last

    PERSON_ID Employee_name SUPERVISOR_1 SUPERVISOR_2
    100299 VELASCO, OMAR UREÑA, PABLO USLENGHI, MATIAS slimani
    58293 UREÑA, PABLO USLENGHI, MATIAS slimani Slimani, Mr. Vrishal A
    98539 USLENGHI, MATIAS slimani Slimani, Mr. Vrishal A Harvey, Mr. Darin S
    68240 Slimani, Mr. Vrishal A Harvey, Mr. Darin S CLARK, TIM MIDDLE EAST
    72230 Harvey, Mr. Darin S CLARK, TIM MIDDLE EAST BOEHLER, JEFF HAS
    76200 CLARK, TIM MIDDLE EAST BOEHLER, JEFF HAS FRADIN, ROGER
    67819 BOEHLER, JEFF HAS FRADIN, ROGER -
    29202 FRADIN, ROGER - -

    Concerning

    Adrien

  • SQL - Multiple Fetch in a single column with a comma separator

    Hello Experts,
    Good day to all...

    I need your help on the following scenarios. The following query returns all channels titleID. Rather than print them one under the other as a result of the query, I want the output to be in the batch of 25 values.i.e than each line must have 25 values separated by commas. IE if there are 100 titles satisfying the output, then there should be only four lines with and each line with 25 titles in comma separated way.
    SELECT DISTINCT title_id
               FROM pack_relation
              WHERE package_id IN (      SELECT DISTINCT fa.package_id
                                                    FROM annotation fa
                                                GROUP BY fa.package_id
                                                  HAVING COUNT
                                                            (fa.package_id) <100);
    I tried with the PL/SQL block; Whereas it is printing all the values permanently :(
    I have to stop with 25 values and display.

    If its possible with SQL block alone. then it would be a great help

                                                           
                                                                          
    DECLARE
       v_str   VARCHAR2 (32767)  := NULL;
    
       CURSOR c1
       IS
         SELECT DISTINCT title_id
               FROM pack_relation
              WHERE package_id IN (      SELECT DISTINCT fa.package_id
                                                    FROM annotation fa
                                                GROUP BY fa.package_id
                                                  HAVING COUNT
                                                            (fa.package_id) <100);
    BEGIN
       FOR i IN c1
       LOOP
          v_str := v_str || ',' || i.title_id;
       END LOOP;
       v_str := SUBSTR (v_str, 2);
       DBMS_OUTPUT.put_line (v_str);
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line ('Error-->' || SQLERRM);
    END;
    Thank you...

    You can use CEIL

    Code example

    SELECT
        nt,
        LTRIM(MAX(SYS_CONNECT_BY_PATH(val,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
    FROM
        (
            SELECT
                val,
                nt,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val)    AS curr,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY val) -1 AS prev
            FROM
                (
                    SELECT
                        level                          AS val,
                        ceil(rownum/3)  as nt /* Grouped in batches of 3 */
                    FROM
                        dual
                        CONNECT BY level <= 10
                )
        )
    GROUP BY
        nt
        CONNECT BY prev = PRIOR curr
    AND nt              = PRIOR nt
        START WITH curr = 1;
    
            NT CONCAT_VAL
    ---------- --------------------------------------------------------------------------------
             1 1,2,3
             2 4,5,6
             3 7,8,9
             4 10
    

    Your code

    SELECT
        nt,
        LTRIM(MAX(SYS_CONNECT_BY_PATH(title_id,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS concat_val
    FROM
        (
            SELECT
                title_id,
                nt,
                ROW_NUMBER () OVER (PARTITion BY nt ORDER BY title_id)   AS curr,
                ROW_NUMBER() OVER (PARTITION BY nt ORDER BY title_id) -1 AS prev
            FROM
                (
                    SELECT
                        title_id,
                        ceil(rownum/25) AS nt /* Grouped in batches of 25 */
                    FROM
                        pack_relation tdpr
                    JOIN annotation fa
                    ON
                        tdpr.package_id = fa.package_id
                    GROUP BY
                        title_id,
                        fa.package_id
                    HAVING
                        COUNT (fa.package_id) < 500
                )
        )
    GROUP BY
        nt
        CONNECT BY prev = PRIOR curr
    AND nt              = PRIOR nt
        START WITH curr = 1;
    
  • Need to concat lines to a single column

    Hi all

    Some examples of data.

    col1 col2 col3

    125 200 abc

    126 200 def

    127 200 IGS

    128 210 homeless

    129 rte 210

    130 211 uiy

    I need output like this.

    col2 col3

    200 abc, def, ghi

    210 homeless, rte

    uiy 211

    I need data with order of col1

    Could you please let me know how to build the query for this.

    Thanks in advance.

    Hello

    Use the function of aggregation LISTAGG, like this:

    SELECT col2

    LISTAGG (col3, ",") THE Group (ORDER BY col1) AS col3_list,

    FROM table_x

    GROUP BY col2

    ;

    This requires that you use Oracle 11.2 or greater.

    The generic term for this is the String aggregation.

    For more on the aggregation of the chain, including how to do this in earlier versions of Oracle, see ORACLE-BASE - String aggregation Techniques

  • Use of multiple sequence on a single column of odi

    My requirement is-
    I have the source table
    S
    1
    1
    1
    2
    2
    3
    1 and so on

    I want that in the target
    SEQ S
    1 1
    1 2
    1 3
    2 1
    2 2
    1 s
    1 4
    It should maintain the sequence for each SDC of the source table.

    Published by: SSZ on 3 Sep 2012 06:55

    If you have any problem to create simple interface then do not use the user function.

    How to create the interface
    1. run ODI Studio
    2. choose the tab "designer".
    3. in the section models : model to create and import target and source of db
    4. in the sections of projects :
    Create interface
    Go to Quick-editing (bottom). The target and Source value. Expression of mapping of the group as row_number() over (partition S)
    Go to the stream. Choose the stage space, and in the Properties window, set IKM.
    Run the interface.

    Read manual (press F1 in ODI Studio). ODI is not easy to understand software.

  • Convert the lines into a single column

    create table suresh
    (
    Identification number,
    ch char (1)
    )
    ;

    Insert in suresh values(1,'i');
    Insert in suresh values(1,'a');
    Insert in suresh values(1,'m');
    Insert in suresh values(1,'b');
    Insert in suresh values(1,'o');
    Insert in suresh values(1,'y');

    Select * from suresh

    ID ch
    1 I
    1 a
    1 m
    1 b
    1 o
    1 y


    I'm looking for output something like this

    ID ch
    1 iamboy
    ..
    select id,listagg(ch) within group(order by ch) as ch
    from suresh
    group by id 
    

Maybe you are looking for