SQL - Multiple Fetch into Single Column with Comma Separator

Hello Experts,
Good Day to all...
I need your help on following scenarios. The below query returns set of titleID strings. Instead of printing them one below the other as query output, I want the output to be in batch of 25 values.i.e each row should have 25 values separated by comma. i.e If there are 100 titles satisfying the output, then there should be only four rows with and each row having 25 titles in comma separated manner.
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 continously :(
I need to stop with 25 values and display.
If its possible with SQL block alone; then it would be of 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;Thanks...

You can use CEIL
Sample code
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 10Your 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;

Similar Messages

  • Rows into single column with comma seperator

    Hi Friends,
    I have the following Query
    select A.tradeid||','||A.TICKER||'|'||A.SUBORDINATION||'|'||A.CUSIP||'|'||A.DOCCLAUSE||'|'||A.CURRENCY from table A
    where A.ticker in ('LYME','GAADF') and A.tradeid in('456777')
    which is returning
    456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD
    456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
    I want the result set as:
    456777,LYME|SENIOR UNSECURED|Z1700990|MM|USD,456777,GAADF|SENIOR UNSECURED|Z1246790|MM|USD
    Please help me to get the result set
    Thanks,
    ragu.
    Edited by: user533548 on Apr 3, 2009 12:54 AM
    Edited by: user533548 on Apr 3, 2009 12:55 AM

    you could do
    select max (ltrim (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY, ','), ','))
      from (
    select tradeid
         , ticker
         , subordination
         , cusip
         , docclause
         , currency
         , row_number() over (partition by tradeid
                                  order by null
                             ) rn
      from x)
    start with rn = 1
    connect by rn = prior rn + 1like in
    SQL> with x as
      2  (
      3  select 456777 tradeid ,'LYOE' ticker ,'SENIOR UNSECURED' subordination,'Z1830990' cusip,'MM' docclause,'USD'  currency from dual union all
      4  select 456777 tradeid ,'GAZDF','SENIOR UNSECURED','Z8446790','MM','USD' from dual
      5  )
      6  select max (
      7        ltrim
      8        (sys_connect_by_path (tradeid||'|'||TICKER||'|'||SUBORDINATION||'|'||CUSIP||'|'||DOCCLAUSE||'|'||CURRENCY
      9         , ',')
    10        , ',')) str
    11    from (
    12  select tradeid
    13       , ticker
    14       , subordination
    15       , cusip
    16       , docclause
    17       , currency
    18       , row_number() over (partition by tradeid
    19                                order by null
    20                           ) rn
    21    from x)
    22   start with rn = 1
    23   connect by rn = prior rn + 1
    24 
    SQL> /
    STR
    456777|GAZDF|SENIOR UNSECURED|Z8446790|MM|USD,456777|LYOE|SENIOR UNSECURED|Z1830990|MM|USD

  • How to Splilit The String Into Single Column using Comma As Delimiter ?

    How to Splilit The String Into Single Column using Comma As Delimiter ?
    using Function

    refer my thread ,code is also available see if that helps you
    error while executing the sp ORA-21779: duration not active

  • How can i get all these values in single row with comma separated?

    I have a table "abxx" with column "absg" Number(3)
    which is having following rows
    absg
    1
    3
    56
    232
    43
    436
    23
    677
    545
    367
    xxxxxx No of rows
    How can i get all these values in single row with comma separated?
    Like
    output_absg
    1,3,56,232,43,436,23,677,545,367,..,..,...............
    Can you send the query Plz!

    These all will do the same
    create or replace type string_agg_type as object
    2 (
    3 total varchar2(4000),
    4
    5 static function
    6 ODCIAggregateInitialize(sctx IN OUT string_agg_type )
    7 return number,
    8
    9 member function
    10 ODCIAggregateIterate(self IN OUT string_agg_type ,
    11 value IN varchar2 )
    12 return number,
    13
    14 member function
    15 ODCIAggregateTerminate(self IN string_agg_type,
    16 returnValue OUT varchar2,
    17 flags IN number)
    18 return number,
    19
    20 member function
    21 ODCIAggregateMerge(self IN OUT string_agg_type,
    22 ctx2 IN string_agg_type)
    23 return number
    24 );
    25 /
    create or replace type body string_agg_type
    2 is
    3
    4 static function ODCIAggregateInitialize(sctx IN OUT string_agg_type)
    5 return number
    6 is
    7 begin
    8 sctx := string_agg_type( null );
    9 return ODCIConst.Success;
    10 end;
    11
    12 member function ODCIAggregateIterate(self IN OUT string_agg_type,
    13 value IN varchar2 )
    14 return number
    15 is
    16 begin
    17 self.total := self.total || ',' || value;
    18 return ODCIConst.Success;
    19 end;
    20
    21 member function ODCIAggregateTerminate(self IN string_agg_type,
    22 returnValue OUT varchar2,
    23 flags IN number)
    24 return number
    25 is
    26 begin
    27 returnValue := ltrim(self.total,',');
    28 return ODCIConst.Success;
    29 end;
    30
    31 member function ODCIAggregateMerge(self IN OUT string_agg_type,
    32 ctx2 IN string_agg_type)
    33 return number
    34 is
    35 begin
    36 self.total := self.total || ctx2.total;
    37 return ODCIConst.Success;
    38 end;
    39
    40
    41 end;
    42 /
    Type body created.
    [email protected]>
    [email protected]> CREATE or replace
    2 FUNCTION stragg(input varchar2 )
    3 RETURN varchar2
    4 PARALLEL_ENABLE AGGREGATE USING string_agg_type;
    5 /
    CREATE OR REPLACE FUNCTION get_employees (p_deptno in emp.deptno%TYPE)
    RETURN VARCHAR2
    IS
    l_text VARCHAR2(32767) := NULL;
    BEGIN
    FOR cur_rec IN (SELECT ename FROM emp WHERE deptno = p_deptno) LOOP
    l_text := l_text || ',' || cur_rec.ename;
    END LOOP;
    RETURN LTRIM(l_text, ',');
    END;
    SHOW ERRORS
    The function can then be incorporated into a query as follows.
    COLUMN employees FORMAT A50
    SELECT deptno,
    get_employees(deptno) AS employees
    FROM emp
    GROUP by deptno;
    ###########################################3
    SELECT SUBSTR(STR,2) FROM
    (SELECT SYS_CONNECT_BY_PATH(n,',')
    STR ,LENGTH(SYS_CONNECT_BY_PATH(n,',')) LN
    FROM
    SELECT N,rownum rn from t )
    CONNECT BY rn = PRIOR RN+1
    ORDER BY LN desc )
    WHERE ROWNUM=1
    declare
    str varchar2(32767);
    begin
    for i in (select sal from emp) loop
    str:= str || i.sal ||',' ;
    end loop;
    dbms_output.put_line(str);
    end;
    COLUMN employees FORMAT A50
    SELECT e.deptno,
    get_employees(e.deptno) AS employees
    FROM (SELECT DISTINCT deptno
    FROM emp) e;
    DEPTNO EMPLOYEES
    10 CLARK,KING,MILLER
    20 SMITH,JONES,SCOTT,ADAMS,FORD
    30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
    CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN SYS_REFCURSOR)
    RETURN VARCHAR2
    IS
    l_return VARCHAR2(32767);
    l_temp VARCHAR2(32767);
    BEGIN
    LOOP
    FETCH p_cursor
    INTO l_temp;
    EXIT WHEN p_cursor%NOTFOUND;
    l_return := l_return || ',' || l_temp;
    END LOOP;
    RETURN LTRIM(l_return, ',');
    END;
    COLUMN employees FORMAT A50
    SELECT e1.deptno,
    concatenate_list(CURSOR(SELECT e2.ename FROM emp e2 WHERE e2.deptno = e1.deptno)) employees
    FROM emp e1
    GROUP BY e1.deptno;
    DEPTNO EMPLOYEES
    10 CLARK,KING,MILLER
    20 SMITH,JONES,SCOTT,ADAMS,FORD
    30 ALLEN,WARD,MARTIN,BLAKE,TURNER,JAMES
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
    g_string VARCHAR2(32767),
    STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
    value IN VARCHAR2 )
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
    returnValue OUT VARCHAR2,
    flags IN NUMBER)
    RETURN NUMBER,
    MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
    ctx2 IN t_string_agg)
    RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
    STATIC FUNCTION ODCIAggregateInitialize(sctx IN OUT t_string_agg)
    RETURN NUMBER IS
    BEGIN
    sctx := t_string_agg(NULL);
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateIterate(self IN OUT t_string_agg,
    value IN VARCHAR2 )
    RETURN NUMBER IS
    BEGIN
    SELF.g_string := self.g_string || ',' || value;
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateTerminate(self IN t_string_agg,
    returnValue OUT VARCHAR2,
    flags IN NUMBER)
    RETURN NUMBER IS
    BEGIN
    returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
    RETURN ODCIConst.Success;
    END;
    MEMBER FUNCTION ODCIAggregateMerge(self IN OUT t_string_agg,
    ctx2 IN t_string_agg)
    RETURN NUMBER IS
    BEGIN
    SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
    RETURN ODCIConst.Success;
    END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    /

  • Combining Multiple Rows into single row with multple columns

    Hi Experts,
    I have the following requirement, kindly help me.
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.
    ID NAME DEPT1 DEPT2 DEPT3
    1 Sam 10 20
    2 alex 30 40 50
    3 vinod 60 70
    It's urgent requirement, kindly help me.
    Thanks in advance.

    Right I've had my drink, so what was this "urgent" question then?
    798616 wrote:
    I have data in my table like below.
    ID NAME DEPT
    1 Sam 10
    1 Sam 20
    2 alex     30
    2 alex 40
    2 alex 50
    3 vinod 60
    3 vinod 70
    I want to show the same data into single row with dynamically generating columns for DEPT. I want show like below.Dynamic numbers of columns eh! Tricky.
    If you understand how SQL statements are executed it's along these lines...
    1. Open Cursor
    2. Parse SQL statement and determine columns
    3. Bind in any input values
    4. Fetch data
    5. Bind out values to columns
    6. Repeat step 3 until no more data
    7. Close cursor
    Now, you're expecting that you can determine the columns (step 2) from the fetched data (step 4 onwards). You can't. The SQL engine needs to know the expected columns before any data is fetched so, it can't base the number of columns on the data itself.
    If you need that requirement, you would need to query the data first and build up a dynamic query based on the data and then execute that dynamically built query to fetch the data and pivot it into those columns, which means that you have queried the data twice. Not good practice and not good (or simple) coding.
    What you're talking of doing is something that should be handled at the presentation/interface layer, not as part of the data fetch.
    Typically these sorts of things are handled most easily in report generation/writer tools such as Oracle Reports, Business Objects etc. where they fetch the data from the database and then process it to format it on the display, pivoting the results as required.
    It's not something that lends itself to be easily achieved in SQL. Yes, SQL can do pivoting of data quite easily, but NOT with a dynamic number of columns.
    If you were to specify that there is a maximum number of columns that you could get (rather than wanting it dynamic), then you can do it simply in SQL with the max-decode method...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select deptno, ename, row_number() over (partition by deptno order by ename) as rn from emp)
      2  --
      3  select deptno
      4        ,max(decode(rn,1,ename)) as ename1
      5        ,max(decode(rn,2,ename)) as ename2
      6        ,max(decode(rn,3,ename)) as ename3
      7        ,max(decode(rn,4,ename)) as ename4
      8        ,max(decode(rn,5,ename)) as ename5
      9        ,max(decode(rn,6,ename)) as ename6
    10        ,max(decode(rn,7,ename)) as ename7
    11        ,max(decode(rn,8,ename)) as ename8
    12        ,max(decode(rn,9,ename)) as ename9
    13        ,max(decode(rn,10,ename)) as ename10
    14  from t
    15  group by deptno
    16* order by deptno
    SQL> /
        DEPTNO ENAME1     ENAME2     ENAME3     ENAME4     ENAME5     ENAME6     ENAME7     ENAME8     ENAME9     ENAME10
            10 CLARK      KING       MILLER
            20 ADAMS      FORD       JONES      SCOTT      SMITH
            30 ALLEN      BLAKE      JAMES      MARTIN     TURNER     WARD
    SQL>

  • Query on column with comma separated values

    I have a proposed table with unnormalized data like the following:
    ID COLA COLB REFLIST
    21 xxx  zzz  24,25,78,412
    22 xxx  xxx  21
    24 yyy  xxx  912,22
    25 zzz  fff  433,555,22
    .. ...  ...  ...There are 200 million rows. There is maximum of about 10 IDs in the REFLIST, though typically two or three. How could I efficiently query this data on the REFLIST column? e.g. something like:
    SELECT id FROM mytable WHERE :myval in reflistLogically there is a many to many relationship between rows in this table. The REFLIST column contains pointers to ID values elsewhere in the table. The data could be normalized so that the relationship keys are in a separate table (in fact this is the current solution that we want to change).
    ID  REF
    21  24
    21  25
    21  78
    21  412
    22  21
    24  912
    ... ...The comma separated list seems instinctively like a bad idea, however there are various reasons for proposing it. The main reason is because the source for this data has it structured like the REFLIST example. It is an OLTP-like system rather than a data warehouse. The source code (and edit performance) would benefit greatly from not having to maintain the relationship table as the data changes.
    Going back to querying the REFLIST column, the problem seems to be building an approriate index for the data. The ideas proposed so far are:
    <li>Make a materialized view that presents the relationships as normalized (e.g. as in the example with ID, REF columns above), then index the plain column - the various methods of writing the view SQL have been widely posted.
    <li>Use a Oracle Text Index (not something I have ever had call to use before).
    Any other ideas? Its Oracle 10.2, though 11g could be possible.
    Thanks
    Jim

    Something like this ?
    This is test demo on my 11.2.0.1 Windows XP
    SQL> create table test (id number,reflist varchar2(30));
    Table created.
    SQL> insert into test values (21,'24,25,78,412');
    1 row created.
    SQL> insert into test values (22,'21');
    1 row created.
    SQL> insert into test values (24,'912,22');
    1 row created.
    SQL> insert into test values (25,'433,555,22');
    1 row created.
    SQL> select * from test
      2  where
      3  ',' || reflist || ',' like '%,22,%';
            ID REFLIST
            24 912,22
            25 433,555,22
    SQL>Source:http://stackoverflow.com/questions/7212282/is-it-possible-to-query-a-comma-separated-column-for-a-specific-value
    Regards
    Girish Sharma
    Edited by: Girish Sharma on Jul 12, 2012 2:31 PM

  • Displaying data from a list into a single field with comma separated values

    Hi,
    I have a requirement to change a report with an XML structure (simplified version) as below
    <Protocol>
    <ProtocolNumber>100</ProtocolNumber>
    <SiteName>Baxter Building</SiteName>
    <ListOfActivity>
    <Activity>
    <Description>Communication Memo Description.</Description>
    <Name>James</Name>
    </Activity>
    <Activity>
    <Description>Visit 4</Description>
    <Name>James</Name>
    </Activity>
    <ListOfActivity/>
    </Protocol>
    On the report I need to display all the 'Names' for each of the Child (Activities) in a single field at the Parent (Protocol) level, with each Name separated by a comma.
    How do I go about getting this to work?
    Thanks

    Take a look at this: http://blogs.oracle.com/xmlpublisher/entry/inline_grouping
    You could do this (ofcourse, you will need to add extra logic to ensure that there is no comma added after the last name..)
    <?for-each@inlines:Name?><?.?><?', '?><?end for-each?>
    Thanks,
    Bipuser

  • Collect Multiple Responses Into Single Column

    I need a form that can collect multiple names and phone numbers and save the data in two columns. One column for names and one column for phone numbers.
    How can I do this?

    My form looks like this:
    Name:
    Phone:
    Name:
    Phone:
    Name:
    Phone:
    So responses come in looking like this:
    Name:          Phone:                 Name:          Phone:             Name:          Phone:
    John             xxx-xxx-xxxx          Jane          xxx-xxx-xxxx          Paul          xxx-xxx-xxxx
    I need them to look like this:
    Name:          Phone:
    John          xxx-xxx-xxxx
    Jane          xxx-xxx-xxxx
    Paul          xxx-xxx-xxxx

  • Multiple values into single column

    Hi ,
    Im having the query like as below
    with t as ( select 'Approved' as "Code" from dual union all
    select 'Historically Relevant' from dual union all
    select 'In Progress' from dual union all
    select 'Internal Review' from dual )
    select "Code"  from t  where "Code" in ('Approved,Historically Relevent')
    in this i need the output like below . ie, what are the things i have selected in where clause based on that the output need to come
    'Approved,Historically Relevent'
    Thanks in Advance ...

    Always remember to post your database version as it can make a difference to the answer.
    In 10g you would use sys_connect_by_path to aggregate strings together...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'Approved' as code from dual union all
      2             select 'Historically Relevant' from dual union all
      3             select 'In Progress' from dual union all
      4             select 'Internal Review' from dual )
      5  --
      6  -- end of test data
      7  --
      8  select ltrim(sys_connect_by_path(code,','),',') as codes
      9  from (
    10        select code, rownum r
    11        from t
    12        where code in ('Approved','Historically Relevant')
    13       )
    14  where connect_by_isleaf = 1
    15  connect by r = prior r + 1
    16* start with r = 1
    SQL> /
    CODES
    Approved,Historically Relevant
    In 11gR2 onwards you can use the new LISTAGG function
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'Approved' as code from dual union all
      2             select 'Historically Relevant' from dual union all
      3             select 'In Progress' from dual union all
      4             select 'Internal Review' from dual )
      5  --
      6  -- end of test data
      7  --
      8  select listagg(code,',') within group (order by rownum) as codes
      9  from t
    10* where code in ('Approved','Historically Relevant')
    SQL> /
    CODES
    Approved,Historically Relevant

  • One column having multiple values with comma separator.

    Hey Guys,
    In my db, one culmn having multiple values with comma separator. like column_name = 'value1,value2,value3'. Now I want to compare this column to another column and fetch in Cursor.
    and each value having corresponding email_id, By fetching cursor, I need to populate email_ids.
    Thanks in advance!!
    -Lakshman

    Please compare and fetch cursor and populate result with out extract data into temp table. Give me the query!You have not provided DDL for table so I don't know table or column name to write any SQL.
    You have not provided DML for test data to run SQL against.

  • Merge multiple columns into single column?

    Hi,
    I need to execute queries dynamically and return the values. I need to fetch the values of the queries in single column only by concatenating the multiple columns. I cannot use PL/SQL in my scenario.
    is there any way to execute a query and the result will be fetched in single column (values of multiple columns needs to be concatenated)?
    Thanks,
    Raja.

    hi,
    do you mean this??
      1* select EMPNO||' '||ENAME||' '||JOB||' '||MGR||' '||HIREDATE||' '||SAL||' '||COMM||' '||DEPTNO||
    SQL> /
    MULTIPLE_COL
    100 JDF DIR  05-SEP-09 200 1000 10
    7497 MILLER CLERK 7782 23-JAN-82 25000 195 35
    7566 JONES MANAGER 7839 02-APR-81 3175 446.25 20
    7654 RAR SALESMAN 7698 28-SEP-81 1450 1587.5 30
    7698 BLAKE MANAGER 7839 01-MAY-81 3050 427.5 30
    7782 CLARK MANAGER 7839 09-JUN-81 2650 367.5 10
    7788 SCOTT ANALYST 7566 09-DEC-82 3200 450 20
    7839 KING PRESIDENT  17-NOV-81 5200 8250 10
    7844 TURNER SALESMAN 7698 08-SEP-81 1700 225 30
    7876 ADAMS CLERK 7788 12-JAN-83 1300 165 20
    7900 JAMES CLERK 7698 03-DEC-81 1150 85.5 30 [email protected]
    MULTIPLE_COL
    7902 FORD ANALYST 7566 03-DEC-81 3200 450 20
    8000 KINGBABA PRESIDENT  17-NOV-81 5200 8250 10
    8001 TURNER RAV SALESMAN 8000 08-SEP-81 1700 450 30
    1001 KITTU DOR  05-SEP-09 1200 100 40
    15 rows selected.Or
    Mean this??
    SQL> ed
    Wrote file afiedt.buf
      1  With T As
      2     ( Select Level col1 From dual Connect By Level<=10
      3     )
      4     Select Max(SYS_CONNECT_BY_PATH(COL1||',',' ')) Multi_col
      5       From
      6     ( Select COL1, Lag(COL1) Over (Order By COL1) As Lag
      7             From   T  )
      8      Start With Lag Is Null
      9        Connect By
    10*    Prior col1 = LAG
    SQL> /
    MULTI_COL
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,Edited by: user291283 on Sep 8, 2009 10:10 PM

  • Merge multiple rows into single row (but multiple columns)

    How to merge multiple rows into single row (but multiple columns) efficiently.
    For example
    IDVal IDDesc IdNum Id_Information_Type Attribute_1 Attribute_2 Attribute_3 Attribute_4 Attribute_5
    23 asdc 1 Location USA NM ABQ Four Seasons 87106
    23 asdc 1 Stats 2300 91.7 8.2 85432
    23 asdc 1 Audit 1996 June 17 1200
    65 affc 2 Location USA TX AUS Hilton 92305
    65 affc 2 Stats 5510 42.7 46 9999
    65 affc 2 Audit 1996 July 172 1100
    where different attributes mean different thing for each Information_type.
    For example for Information_Type=Location
    Attribute_1 means Country
    Attribute_2 means State and so on.
    For example for Information_Type=Stats
    Attribute_1 means Population
    Attribute_2 means American Ethnicity percentage and so on.
    I want to create a view that shows like below:
    IDVal IDDesc IDNum Country State City Hotel ZipCode Population American% Other% Area Audit Year AuditMonth Audit Type AuditTime
    23 asdc 1 USA NM ABQ FourSeasons 87106 2300 91.7 46 85432 1996 June 17 1200
    65 affc 2 USA TX AUS Hilton 92305 5510 42.7 46 9999 1996 July 172 1100
    Thanks

    Hi,
    That's called Pivoting . The forum FAQ has a section on this subject: {message:id=9360005}
    I hope this answers your question.
    If not, post your best attempt, along with a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data. (You did post the results you wanted, but they're very hard to read because they're not formatted. Use \ tags, as described in the forum FAQ, below.)
    Explain, using specific examples, how you get the results you want from the data given.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).  This is always important, but especially so with pivots.
    See the forum FAQ {message:id=9360002}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Convert different rows into single column

    DB : 11.1.0.7
    OS : Solaris Sparc 5.10
    I have one query which is joining few tables and giving me output like below.
    personnum orgnm
    ======= =======
    6     Keyholder
    9     Sales
    3     Mgmt
    I would like to convert that into single column like below.
    col1
    ========
    6,Keyholder,9,Sales,3,Mgmt
    I have tried with pivot and decode, but not getting resule which I am exepcting. Any suggesstions ?

    yashwanth437 wrote:
    listagg() function could work.LISTAGG is not available in 11.1. It was introduced in 11.2.
    Anyway, 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.

  • Scanning multiple pages into single document

    Is there a way to scan multiple pages into single document?  I am using the following: HP pavilion laptop with windows 8,  HP photosmart C6380 all in one printer scanner copier.

    Hi,
    Please try
    Double click printer icon on desktop,
    Select Scan a Document or Photo,
    Put the first page on the glass (face down),
    Check options (size, dpi ...), and select Scan document to file,
    Click Scan - machine will scan the first page
    Remove the first page on the glass, put the second page,
    Click + (plus sign) It sits on the left hand side of a red x
    Machine will scan the second page, put 3rd page on the glass and click + again ..... to the end then click Save
    Click Done after Save
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to Pass multiple parameter into single store procedure

    How to Pass multiple parameter into single store procedure
    like a one to many relationship.
    it is possible then reply me immediatly

    you mean like this .....
    CREATE OR REPLACE procedure display_me(in_param in varchar2,in_default in varchar2 := 'Default') is
    BEGIN
    DBMS_OUTPUT.put_line ('Values is .....'||in_param || '....'||in_default);
    END display_me;
    CREATE OR REPLACE procedure display_me_2 as
    cnt integer :=0;
    BEGIN
    For c1_rec In (SELECT empno,deptno FROM test_emp) Loop
         display_me(in_param => c1_rec.empno);
         cnt := cnt+1;
         end loop;
         DBMS_OUTPUT.put_line('Total record count is ....'||cnt);
    END display_me_2;
    SQL > exec display_me_2
    Values is .....9999....Default
    Values is .....4567....Default
    Values is .....2345....Default
    Values is .....7369....Default
    Values is .....7499....Default
    Values is .....7521....Default
    Values is .....7566....Default
    Values is .....7654....Default
    Values is .....7698....Default
    Values is .....7782....Default
    Values is .....7788....Default
    Values is .....7839....Default
    Values is .....7844....Default
    Values is .....7876....Default
    Values is .....7900....Default
    Values is .....7902....Default
    Values is .....7934....Default
    Values is .....1234....Default
    Total record count is ....18

Maybe you are looking for

  • Passing the values to Hyperlink

    Hi, My requirement is I want to pass two values to hyperlink from a table. My table looks like            <b>  Column 1; Column 2</b> Row 1     Value1 ;  Value 2 Row 2     Value 3; Value 4. I want that If someone clicks on value1..... the Row1 and Co

  • How to restore/reset downloads to default to open pdf forms in preview instead of adobe?

    I downloaded Adobe Reader 11 yesterday in order to view my electronic university transcripts.  In the course of installing, ALL pdf files on my hard-drive were converted to adobe pdf files and will not open with preview.  I don't mind keeping the one

  • Displaying a mix of L to R and R to L readable strings in a single text box

    Folks, Is it possible to get accurate display of fields when  English string values and hebrew characters are dragged into a single text box for viewing. Currently while doing this the display gets erratic as some of the english strings gets displaye

  • MISSING FROM CC | Flash with SCORM 1.2 Tracking

    Hello Anyone-   We use Flash as our main tool to create eLearning for our organization.  The CC seems to have dropped the SCORM 1.2 and 2004 tracking methods from the HTML Wrapper. Is there any way to get this back? Joel

  • Mac Pro laptop running very slow and freezing often

    Recently my Mac has been acting funny. I will be surfing the net or just trying to check my email and the spinning wheel will come up and spin forever. Sometimes it stops and lets me continue, sometimes and stops for a few minutes and does it again,