How to get the list in a single column in a query

Hello.

I wonder if there is a way to get a query (no pl/sql code) a list of columns with a separator between them.

I know I can get that without separators with an expression of cursor:
SQL> with test_table as (
  2  select 1 col1, 'a' col2 from dual
  3  union
  4  select 1 col1, 'b' col2 from dual
  5  union
  6  select 1 col1, 'c' col2 from dual
  7  union
  8  select 2 col1, 'a' col2 from dual
  9  union
 10  select 2 col1, 'c' col2 from dual
 11  union
 12  select 2 col1, 'd' col2 from dual
 13  union
 14  select 2 col1, 'z' col2 from dual
 15  )
 16  select col1, cursor (select b.col2 from test_table b where b.col1 = a.col1 order by b.col2) col2_list from test_table a
 17  group by col1
 18  /

      COL1 COL2_LIST
---------- --------------------
         1 CURSOR STATEMENT : 2

CURSOR STATEMENT : 2

C
-
a
b
c

         2 CURSOR STATEMENT : 2

CURSOR STATEMENT : 2

C
-
a
c
d
z
But the result I want is (by using the separator ';'):
      COL1 COL2_LIST
---------- --------------------
         1 a;b;c
         2 a;c;d;z
I don't know how to manage a cursor expression without using a pl/sql function block. Can it be done using analytical functions?

Thanks in advance.

Hello

This is called 'aggregation of chain.
This site:

http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2196162600402

shows different ways to do this, including the SYS_CONNECT_BY_PATH solution which gave Blushadow.

I got a lot of use of the first solution on this page, the function defined by the user STRAGG, that you can copy.

Once you have installed STRAGG, your query is simply

SELECT    col1
,         STRAGG (col2)     AS col2_list
FROM      test_table
GROUP BY  col1;

The query above do not put items in a particular order.

On Oracle 10 (and more) you can have a similar function, the WM_CONCAT (property WMSYS), already installed.
WM_CONCAT is not documented, so you can't use it in your Production applications.

Tags: Database

Similar Questions

  • How to get the list of RDM?

    Hi all

    In our environment both of RDM is presented to different virtual machines in physical compatibility mode. It was very difficult for me to keep track

    Could you get it someone please let me know, how to get the list of the RDM presented to ESXI 5.0 host?

    Thank you!

    Ravindra Reddy

    Thank you... A P... for your response tools RV is the right tool, but I wanted to naa number of LUNS as well.

    After 2 hours, I had below power CLI command to get the list of the virtual machine.

    PowerCLI C:\ > Get - VM | Get-hard drive - DiskType "RawPhysical", "RawVirtual" | Select name, Parent, ScsiCanonicalName, DiskType | FL | Out-file C:\RDMlist.xlx

    Thank you!

  • How to get the list of active users in Essbase 6.5.6

    Hi gurus,

    How to get the list of active users in Essbase version 6.5.6

    I can't find any Esscmd list of active users...

    I used the command LISTLOGINS in ESSCMD, but it did not help me...

    pls suggest me an approach to find the list of active users.

    Thanks in advance...

    Hi guru,.

    When you connect to the application, you will find the security option---> connect you will find active use in the ESSBASE.

    If you need the list of users in the use of ESSBASE that recommends essmsh

    go for the race---> essmsh---> login user server use this tribute

    (1) session view all this;

    If you want to export the active users usebelow congratulate.

    2)

    spool to 'D:\suresh.txt ';

    poster session;

  • How to get the list of files for a virtual machine?

    Hello

    Virtual machines can have their files distributed on several issues (even through several data warehouses).

    PowerCLI gives us an easy way to retrieve the data warehouse associated with a virtual (Get-data store) machine, but it doesn't seem to be a built-in method to get the list of all records where a given virtual machine stores all its files. Or maybe I'm just blind ;-)

    Can anyone offer an overview on how to achieve this?

    Thank you

    No, that sounds like a good idea to copy/back up virtual machines.

    I adapted the script. She now returns one row for each unique record

    foreach($vm in Get-VM){
      $folders = $vm.ExtensionData.LayoutEx.File | %{$_.Name.Split('/')[0]} | Sort-Object -Unique  $folders | Select @{N="VM";E={$vm.Name}},@{N="Folder";E={$_}}
    }
    
  • How to get the use of database tables/columns in the table of edge/analysis?


    Hi all

    Anyone has an idea on how to get the tables in DB/colomns usaged in edge/analysis table in OBIEE 11 G?

    Thanks in advance!

    Anne

    You can try to generate a report of Catalog Manager for analysis / SA want to create the line and your RPD you can go to utilities > documentation of the repository and get the domain you want to and get all the mappings in Excel format.

    I hope this helps.

    SVS

  • How to get the value of a particular column column name?

    Hi all

    How to get the column name for a particular column value.
    example:

    create table test (ID number, col2, col3 varchar varchar);

    Insert into test values (1, 'true', 'false');
    Insert into test values (2, 'false', 'true');
    commit;

    I want to choose the name of the data column 'true' with id = 1;

    That is to say) while waiting for answer is "col2". pls help someone.

    This might help:

    DECLARE
       c1 SYS_REFCURSOR;
    BEGIN
       OPEN c1 FOR
       SELECT col2,
              col3
       FROM   test
       WHERE  id = 1;
       --
       FOR c IN (SELECT rownum rn,
                        t2.column_value.getrootelement() name,
                        EXTRACTVALUE(t2.column_value, 'node()') value
                   FROM TABLE(XMLSEQUENCE(c1)) t,
                        TABLE(XMLSEQUENCE(EXTRACT(column_value, '/ROW/node()'))) t2)
       LOOP
          IF c.value = 'true' THEN
             DBMS_OUTPUT.PUT_LINE(c.name);
          END IF;
       END LOOP;
    END;
    
  • How to get the list of video playback

    Hello

    can anyone suggest me how can I get the number of playlist, the name of all the playlist available in videos and the number of items in each list of reading...

    Thank you...

    QString currentpath(QDir::currentPath());)
    currentpath = music_database_path + "/ db/mmlibrary.db";

    SqlDataAccess sqlDataAccess (music_database_path);

    SqlData QVariantList = sqlDataAccess.execute ("Select c0filename, c2artist, c3album, c4genre, c5composer, c6title, audio_search_content c7description') .value();

    using this we can get all the file name, playlist, albums, genre, etc.

  • How to get the list permissions wise page name or menu-wise

    Hello

    I want to know this authorization list associated with a specific page or a menu. Please help me how to get that

    Check the following on the internet regarding the area of authorizedaction, which contains the information you need.

    http://peoplesoftwiki.blogspot.nl/2009/12/finding-barname-ItemName-and-all-about.html

    you want to hide the PeopleTools menu? If so, mke sure (s) he doesn't have the permision list that grants the permissions so that you do not want.

  • Please, I beg you! Need a c# example on how to get the list of all host ESX via SDK... I can connect... etc...

    Hello

    I am train to figure this out for a few hours now... and all I find is some examples related to the properties of the VM or something else.

    Now I am able to connect to the server and retrieve things like: Server date and time, version of the API etc...

    I would like to get a code example that would give me the list of ESX servers include within a Virtual Center Server... the last thing I used I got something like: If. Content.searchIndex.ToMo & lt; Indexderecherche & gt; (so). FindEntities & lt; HostSystem & gt; (null, null);...

    This well liked not... Maybe it was too easy...; (o)

    And if you also have a quick way to let me know how to retrieve a simple thing as a host network adapter config... as if I want to know if it is a static address or dhcp etc...

    PS. I have created also a ref to the service instance and service content.

    Here's an example to get the version of the API: (I want that same thing as host nic for setting... but have not yet found the correct syntax)

    var test = SERVICE_CONTENT.about.apiVersion.ToString ();

    MessageBox.Show ("test");

    Also... YES, I'm looking at the SDK prog. Guide... but all of the examples in which are in java... and a little far, the syntax is the same as c#

    Jon

    Thank you and I will award points to a significant response...

    consoleVnic is an array of HostVirtualNic. Therefore, you must print a specific item from the array and not the array itself. It seems that this is the problem.

  • How to get the color of a single pixel?

    Hi all.

    Part of my application is transparent. The other party is not.

    But I would like to have 'match' colors (is not very pretty orange to pink, but it's a matter of personal taste, I guess).

    That's why I need now to a background color.

    That's what I had in mind:

    Because we cannot get information about the currently active theme, I can do a screen capture and extract a single pixel of interest and get its color information. If it is green (for example) - I'll tryto use more Brown colors in my application.

    So basically, is it possible to get the color of a pixel in a bitmap (or something?)

    My last resort would be to save the Bitmap image to a file and then read that file.

    Bitmap.getARGB (int [] argbData, int offset, int scanLength, int x, int y, int width, int height)
    Gets the raw data ARGB region of this Bitmap and stores it in the table provided.

  • How to get the list of parameters of a stored procedure in Oracle?

    I'm calling an Oracle stored procedure and use the OCIBindByPos for each parameter.
    Example:
    /* Do the bind for date, using OCIIOV */
    OCIBindByPos (stmthp, &bindhp2, errhp, 2, (void *)&bvec[0], 
                  sizeof(buf_1[0]), SQLT_STR, 
                  (void *)inddate, (ub2 *)alendate, (ub2 *)rcodedate, 0,
                  (ub4 *)0,  OCI_IOV);
    In this case, its necessary for a list of the parameters of the stored procedure, information such as type and the input/output parameter, etc.

    I can get the parameters of a stored procedure using the DESCRIBE statement.
    Example:
    SQL> DESCRIBE SP_GETCITIES
    PROCEDURE SP_GETCITIES
     Argument Name                  Type          In/Out Default?
     ---------------------- --------------------- ------ --------
     STATE_KEY              VARCHAR2               IN
     FECHA                  DATE                   IN
     RC1                    REF CURSOR             OUT
    
    SQL>
    Is there a better way to get the name, type, input/output for each parameter of an Oracle stored procedure, using the BEAK?

    Best regards.

    Antonio García (Mexico)

    Hi Antonio,.

    Take a look at "Describing metadata schema" in the programmer's Guide. He has this kind of information, which may be enough to get you going in the right direction. The guide is here:

    http://download.Oracle.com/docs/CD/E11882_01/AppDev.112/e10646/oci06des.htm#i446492

    In particular, see the code example in the section "describing the stored procedure.

    Kind regards

    Mark

  • How to get the ID of a single data centre and the Cluster

    Hello

    We have a product we need get the detail of data centers, Clusters, the Esx host and all Virtual Machines of a Virtual Center. And keep it in sync with the VCenter. I use a thread that queries the VCenter every 5 minutes and retrieves the data.

    We use Java VI SDK 4.0 for this.

    At the present time I am able to read all the details using PropertyCollector. But once a data center is renowned for my application, it is similar to a fact that a data center with the old name has been deleted and a data center with the new name has been added. For this reason, when data center is renamed, I remove entities for the former my application Esx host and adding new features to the ESX hosts in new data center. It causes a lot of unwanted things.

    So, I want to go get some unique Id of the dataCenter and Cluster, so that when a cluster/datacenter is renamed, uniqueId is always the same and my app will be able to know that it is just a change of name. And entities for ESX/VirtualMachine will be kept.

    Please, help me to know the unique id of the cluster/datacenter.

    Thank you

    Deepak

    Yes, there are supposed to be unique UUID generated by vCenter or ESX (i) and if you have not manually mux with values. The UUID is guaranteed to be unique within a given instance of vCenter.

    =========================================================================

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    Twitter: @lamw

    repository scripts vGhetto

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    VMware Code Central - Scripts/code samples for developers and administrators

    150 VMware developer

    If you find this information useful, please give points to "correct" or "useful".

  • How to get the result of a single line in several columns

    I have a scenario where I asked five different columns in a table and it would still look back one line.

    So, for example: the query would be
     Select user1, user2, user3, user4 from table1 where tblkey= 2 
    So, this would mean 1 row with the value of their respective areas.

    In my code, I have a common function I can call to send an email to the list of people (User1, User2, user3, user4).

    So rather than call this function each time for each user, is there a way I can display the output to 4 different rows and use the loop For to call this function only once.

    In this way, the loop For running 4 times (if not nulls for all users) and call this function of e-mail.

    Really, I'd appreciate if someone could give me an idea of this scenario.

    Thank you
    AR

    If the number of columns is fixed you may be able to use this:

    SELECT  DECODE
            (
                    RN
            ,       1,USER1
            ,       2,USER2
            ,       3,USER3
            ,       4,USER4
            )       AS USERS
    FROM    TABLE1
    CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
    WHERE   TBLKEY = 2
    

    This UN-pivot results.

    Here's an example of it in action:

    SQL> CREATE TABLE TABLE1
      2  (
      3          TBLKEY  NUMBER
      4  ,       USER1   VARCHAR2(1)
      5  ,       USER2   VARCHAR2(1)
      6  ,       USER3   VARCHAR2(1)
      7  ,       USER4   VARCHAR2(1)
      8  );
    
    Table created.
    
    SQL> INSERT INTO TABLE1
      2  SELECT  ROWNUM
      3  ,       SUBSTR(OBJECT_NAME,1,1)
      4  ,       SUBSTR(OBJECT_NAME,2,1)
      5  ,       SUBSTR(OBJECT_NAME,3,1)
      6  ,       SUBSTR(OBJECT_NAME,4,1)
      7  FROM    ALL_OBJECTS
      8  WHERE ROWNUM <= 10;
    
    10 rows created.
    
    SQL> SELECT * FROM TABLE1 WHERE TBLKEY = 2;
    
                  TBLKEY USER1      USER2      USER3      USER4
    -------------------- ---------- ---------- ---------- ----------
                       2 I          _          U          S
    
    SQL> SELECT  DECODE
      2          (
      3                  RN
      4          ,       1,USER1
      5          ,       2,USER2
      6          ,       3,USER3
      7          ,       4,USER4
      8          )       AS USERS
      9  FROM    TABLE1
     10  CROSS JOIN (SELECT ROWNUM RN FROM DUAL CONNECT BY ROWNUM <= 4)
     11  WHERE   TBLKEY = 2
     12  /
    
    USERS
    -------------------------
    I
    _
    U
    S
    

    HTH!

    Published by: Centinul on February 24, 2010 11:21

  • How to get the Max value with other columns data also.

    Suppose that a query is covered with the data as

    Time of ID
    01 07/12/2014
    02 07/05/2014
    03 16/07/2014
    04 07/07/2014

    I need to get the ID and time to time max.
    that is, should I get
    Time of ID
    03 16/07/2014

    To do this, I wrote a query that gives me necessary data. But I thought that's the best way?
    Is it an effective way to get this data?
    My query that returns the data required is:

    SELECT ID, MAX_DT FROM
    (
    Select 'DUMMY', ID, TIME1, MAX (TIME1) OVER (PARTITION 'DUMMY') AS MAX_DT FROM TAB1
    WHERE ID IN (BLAH BLAH)
    )
    WHERE MAX_DT = (EDT) 1

    Frank mentioned links


    WITH test_data (id, time) LIKE)

    SELECT 01, to_date('2014/07/12','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 02, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 03, to_date('2014/07/16','yyyy-mm-dd') FROM dual

    UNION ALL

    SELECT 04, to_date('2014/07/07','yyyy-mm-dd') FROM dual

    )

    SELECT id, time

    go (select id,

    time,

    Max (Time) on latest_time (order by time lines between unbounded preceding and following unbounded)

    of test_data

    )

    where time = latest_time

    ID TIME
    3 16/07/2014
    2 16/07/2014

    Concerning

    Etbin

  • How to get the list view in iTunes 12.4.3 for Windows

    Guys, I'm LOSING MY MIND. I had to re - download iTunes (which I refused to update in eternity because I know of updated versions are generally never good), and this new Interface is making me remove my hair and cry. Not only is it completely intuitive, but it makes it incredibly difficult to navigate.

    I'm seeing all my music in classic list view, which I know he can do. When I first loaded it upward, she appeared in list view, but the time that I started clicking around, it became this heavy nightmare of the image. Every article I've read has a UI that I don't HAVE, where there is a drop-down list of some sort. Does anyone know how? I have attached a screenshot. BTW, that blue icon that you THINK would be seen list said just what is the next song. Complete waste of space. Jesus, just put it in a status bar, or scroll across the top.

    FYI: the only changes that I made in the preferences has been disable anything itunes store or apple related radio because literally ALL itunes became ads.

    How can I view my mode music list in iTunes 12.4?

    In the drop-down list, select music. Once in the music, in the sidebar, select the songs and you should be intraditional list view.

Maybe you are looking for