Reg: WMSYS. WM_CONCAT or LISTAGG

All,

I'm trying to select column names that begin with "E" in my sql query projection area. For this I used USER_TAB_COLS with WMSYS. WM_CONCAT / LISTAGG too.

I got the names of columns, with separator ", but could not inject it to the sql query. Please help me.

SQL > SELECT WMSYS. WM_CONCAT (column_name)
2 FROM user_tab_cols
3 WHERE table_name = 'EMP '.
4 AND column_name LIKE '% E ';

WMSYS. WM_CONCAT (COLUMN_NAME)
--------------------------------------------------------------------------------
EMPNO, ENAME

SQL > SELECT
2. (SELECT WMSYS. WM_CONCAT (column_name)
3 FROM user_tab_cols
4 WHERE table_name = 'EMP '.
5 AND COLUMN_NAME LIKE '% E '.
(6) a
7 FROM EMP where rownum < = 4;

A
--------------------------------------------------------------------------------
EMPNO, ENAME
ERROR:
ORA-22922: non-existent LOB value

-LISTAGG

SQL > select (selection ListAgg (column_name, ',')
2 IN THE GROUP (ORDER BY COLUMN_NAME DESC) AS CONCATV
3 to user_tab_cols
4. WHERE TABLE_NAME = 'EMP '.
5 AND COLUMN_NAME LIKE '% E') a FROM EMP WHERE ROWNUM < = 3;

A
----------------------------------------------------------------------------------------------------
ENAME, EMPNO
ENAME, EMPNO
ENAME, EMPNO

Thank you

Here is an example of what you want to do:

: c is of type cursor

declare

v varchar2 (4000);

Start

Select GROUP(ORDER BY COLUMN_NAME DESC) AS CONCATV ListAgg (column_name, ',')

v

of user_tab_cols

WHERE TABLE_NAME = 'MYTABLE ';

Open: c for 'select'. v. "from MYTABLE";

end;

----

Ramin Hashimzade

Tags: Database

Similar Questions

  • Wm_concat or Listagg

    Hi all

    I need a suggestion that one we should use wm_concat or listagg.
    My db is 11g Standard Edition.

    Please Guide!

    Yes, that's wht which suggest to my blog...

    Alexander gelin
    http://nimishgarg.blogspot.com

  • am getting error error when am with funcation wm_concat.

    Hi all
    am getting error error when am with funcation wm_concat.
    SQL> DECLARE
    2 ex VARCHAR2(200);
    3 BEGIN
    4 SELECT wm_concat(ename) INTO EX FROM EMP WHERE deptno=30;
    5 DBMS_OUTPUT.PUT_LINE(EX);
    6 END;
    7 
    8 .
    SQL> 
    SQL> /
    DECLARE
    *
    ERROR at line 1:
    ORA-06550: line 4, column 10:
    PL/SQL: ORA-00904: "WM_CONCAT": invalid identifier
    ORA-06550: line 4, column 3:
    PL/SQL: SQL Statement ignored
    Thanks to all in advance

    Published by: Maldini on 9 January 2012 22:02

    Cool wrote:
    Hello

    Please check the version of database you are using.

    wm_concat is available from 11 g Release 2.

    Incorrect answer.

    wm_concat is undocumented and should not be used.

    Even Tom Kyte tell you... Re: SEPARATE does not not with wmsys.wm_concat

    11 GR 2, there is a documented feature called LISTAGG...

    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions089.htm

  • Pls help to return the results in, separted.

    Hello

    To get the comma separated list I wrote below the user-defined function. Available in Oracle 10 g release2 any pre defined function.

    I tried wmsys.wm_Concat but invalid identifier. I tried SYS_CONNECT_BY_PATH but I could not able to get result. Please help on this

    If I run under function with input = 7 8.9 result gives.

    Currently I have writtenmy function like this

    FUNCTION get_file_child_meta_data (i_parent_metadata_id as a WHOLE) RETURN VARCHAR2

    AS

    v_text VARCHAR2 (50): = NULL;

    BEGIN

    FOR (IN) cur_rec

    SELECT element_metadata_id

    OF cw_elements_meta_lookup

    WHERE parent_metadata_id = i_parent_metadata_id ORDER BY element_metadata_id)

    LOOP

    v_text: = v_text | ',' || cur_rec.element_metadata_id;

    END LOOP;

    Ltrim (v_text, ',') RETURN;

    END get_file_child_meta_data;

    The only time where I couldn't use SYS_CONNECT_BY_PATH was inside trigger Forms 6i code, while the DB 10 g. You use directly in PL/SQL?

  • GROUP_CONCAT

    Hi all

    What is the equivalent of 'GROUP_CONCAT' in mysql to oracle?

    as in group_concat (emp_name) select from emp where dept_no = '10';

    output is 1 row: JUSTIN, HEMANT, BILLY, AMAN, SBT, ASAHI, BLU, ED, FRANK, RP, APC, WHOELSE


    Thank you

    asahide wrote:
    11g R1, you can use the wmsys.wm_concat function.
    But this func func undocumented...

    Kind regards

    and

    Alexandre Gelin says:
    Here's a simple example
    http://nimishgarg.blogspot.in/2010/02/Oracle-new-string-aggregation.html

    the two recommendations for use wm_concat are stupid.

    As mentioned, it is undocumented. This means that the mode of operation is not completely know we as developers. It also means that Oracle can change its operation in the different versions of the database, or they can even choose to get rid of the service overall, then you're going to have a broken application and Oracle are not required to support any application code that uses an undocumented feature.

    There are many examples of aggregation of the chain in the FAQ: {message identifier: = 9360005}
    including a link to where Tom Kyte says you shouldn't use wm_concat (and therefore it should not yet be recommended as an option by anyone)...
    {message: id = 9965699}

    Samir, he is also considered as a poor forum tag (and is frowned upon by the RTO admin that tighten the rules), to just post responds that the link to your own blog. It is enough just to link to your blog in support of an answer you gave on the forums, but the answer just directing people to your blog is close to being a bad use of the forums, and I think that I already warned you about this before, so please refrain from doing.

  • How do I get the data in order by date

    Hello

    I get the data as below, I need the data with null values

    Date col1 col2 col3 col4
    16 November 11 23
    November 17 11 12
    18 November 11 321
    19 November 11 23
    20 November 11 132
    2321 16 November 11
    17 November 11 112
    18 November 11 211
    19 November 11 132
    November 20, 11 12
    16 November 11 45
    17 November 11 465
    2123 18 November 11
    19 November 11 132
    20 November 11 65
    16 November 11 456
    17 November 11 546
    4656 November 18, 11
    19 November 11 566
    20 November 11 564

    need output like below

    Date col1 col2 col3 col4
    16 November 11 23 2321 45 456
    November 17 11 12 112 465 546
    18 November 11 321 211 2123 4656
    19 November 11 23 132 132 566
    20 November 11 132 12 65 564

    Thanks in advance,
    Vincent.

    Delighted ADIK wrote:
    Please post requests INSERT such as requested by another user of the forum. Also mention the version of Oracle.

    Please search for WM_CONCAT.

    http://www.Oracle-base.com/articles/Misc/StringAggregationTechniques.php

    Yes, search for WM_CONCAT, and then COMPLETELY IGNORE IT because it is not the right way to do things. It is undocumented and should not be used similarly recommended.

    Even Tom Kyte says that you should not use it...

    Re: SEPARATE does not not with wmsys.wm_concat

    WM_CONCAT is also an aggregation of chain function, and is not what the OP's request.

    Frank gave the good solution, as evidenced by...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select to_date('16-Nov-11','DD-Mon-RR') as dt, 23 as col1, null as col2, null as col3, null as col4 from dual union
      2             select to_date('17-Nov-11','DD-Mon-RR'), 12, null, null, null from dual union all
      3             select to_date('18-Nov-11','DD-Mon-RR'), 321, null, null, null from dual union all
      4             select to_date('19-Nov-11','DD-Mon-RR'), 23, null, null, null from dual union all
      5             select to_date('20-Nov-11','DD-Mon-RR'), 132, null, null, null from dual union all
      6             select to_date('16-Nov-11','DD-Mon-RR'), null, 2321, null, null from dual union all
      7             select to_date('17-Nov-11','DD-Mon-RR'), null, 112, null, null from dual union all
      8             select to_date('18-Nov-11','DD-Mon-RR'), null, 211, null, null from dual union all
      9             select to_date('19-Nov-11','DD-Mon-RR'), null, 132, null, null from dual union all
     10             select to_date('20-Nov-11','DD-Mon-RR'), null, 12, null, null from dual union all
     11             select to_date('16-Nov-11','DD-Mon-RR'), null, null, 45, null from dual union all
     12             select to_date('17-Nov-11','DD-Mon-RR'), null, null, 465, null from dual union all
     13             select to_date('18-Nov-11','DD-Mon-RR'), null, null, 2123, null from dual union all
     14             select to_date('19-Nov-11','DD-Mon-RR'), null, null, 132, null from dual union all
     15             select to_date('20-Nov-11','DD-Mon-RR'), null, null, 65, null from dual union all
     16             select to_date('16-Nov-11','DD-Mon-RR'), null, null, null, 456 from dual union all
     17             select to_date('17-Nov-11','DD-Mon-RR'), null, null, null, 546 from dual union all
     18             select to_date('18-Nov-11','DD-Mon-RR'), null, null, null, 4656 from dual union all
     19             select to_date('19-Nov-11','DD-Mon-RR'), null, null, null, 566 from dual union all
     20             select to_date('20-Nov-11','DD-Mon-RR'), null, null, null, 564 from dual)
     21  --
     22  -- end of test data
     23  --
     24  select dt
     25        ,max(col1) as col1
     26        ,max(col2) as col2
     27        ,max(col3) as col3
     28        ,max(col4) as col4
     29  from t
     30  group by dt
     31* order by dt
    SQL> /
    
    DT                COL1       COL2       COL3       COL4
    ----------- ---------- ---------- ---------- ----------
    16-Nov-2011         23       2321         45        456
    17-Nov-2011         12        112        465        546
    18-Nov-2011        321        211       2123       4656
    19-Nov-2011         23        132        132        566
    20-Nov-2011        132         12         65        564
    
    SQL>
    
  • Reg: WM_CONCAT

    Dear friends.

    I face this error
    ORA-06502: PL/SQL numeric or value error: character string buffer too small.
    ORA-06512: at the ' WMSYS '.»» WM_CONCAT_IMPL ".



    I keep files on my table and I want to display records in separate by commas.

    output 101,101,102,103 there are a thousand documents in the column.
    but when I used above function to concatenate its gave me error.

    Please help me or give me another Solution on it how do I record with comma.

    output 101,101,102,103 there are a thousand documents in the column.

    See this example:

    SQL> select deptno, rtrim (xmlagg (xmlforest (empno || ',' e)).extract ('//text()').getclobval (), ',') empnos
        from emp
    group by deptno
    /
        DEPTNO EMPNOS
    ---------- ----------------------------------------
            10 7782,7839,7934
            20 7369,7902,7876,7788,7566
            30 7499,7698,7654,7844,7900,7521           
    
    3 rows selected.
    
  • How can'i use wm_concat in ODI 10

    Hello

    I would like to know how to use the wm_concat function in an ODI interface (I use 10 ODI)

    For example, I have the following source data

    A    B     C

    ---       --- -------

    20     5     SMITH

    30     3     ALLEN

    30     2     WARD

    20     4     JONES

    30     2     MARTIN

    30     3     BLAKE

    10     1     CLARK

    20     3     SCOTT

    10     3     KING

    30     5     TURNER

    20     2     ADAMS

    30     5     JAMES

    20     1     FORD

    10     5     MILLER

    and I want to insert the next data kes

    A     sum(B)     wm_concat(c)

    ---    --- ------------------------

    10     9        CLARK,KING,MILLER

    20     15      SMITH,FORD,ADAMS,SCOTT,JONES

    30     20      ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD

    by adding a function of sum () in the column mapping B.

    The following query generates the ODI

    SELECT A, SUM (B), WM_CONCAT (C)
    FROM <table>
    GROUP BY A, WM_CONCAT (C);
    

    This means that the ODI does not recognize WM_CONCAT as aggregate function.

    don't you think that it is possible to say ODI to do not function in the group by

    PS: I use an Oracle 11 g database 2 which recognizes the WM_CONCAT function.

    Thank you very much

    Hello

    WM_Concat is no longer valid, that it has been deprecated by oracle, a long time ago.

    Using the LISTAGG function instead... It should work in ODI...

    SELECT deptno, LISTAGG (ename, ',') INTRA GROUP (ORDER BY ename) as employees

    WCP

    GROUP BY deptno;

    DEPTNO EMPLOYEES

    ---------- --------------------------------------------------

    10 CLARK, KING, MILLER

    ADAMS, FORD, JONES 20, SCOTT, SMITH

    ALLEN, JAMES, MARTIN, BLAKE, TURNER, WARD 30

    If this solves your problem... close the thread...

    Thank you

    ASP.

  • without using the listagg function

    Hi Sir,

    Today my Bishop asked me to write a sql query to display comma separated values using listagg, sys_connect_by_path, wm_concat?

    I said, we can write with the cursor... without predefined oracle functions? is this correct? or a Counselor about it?

    Please help me

    Concerning

    AR

    SQL > create table SEPM (deptno number (2), ename varchar2 (2));

    Table created

    SQL > insert all
    2 in samp (deptno, ename) values (10, 'A')
    3 in the SEPM (deptno, ename) values (20, 'd')
    4 in the samp (deptno, ename) values (20, 'E')
    5 SELECT * FROM DUAL;

    3 lines inserted

    SQL > SELECT * FROM SAMP;

    DEPTNO ENAME
    ------ -----
    10A
    20 D
    20 E

    Need to display like this

    10A

    20 D, E

    http://www.sqlsnippets.com/en/topic-11787.html

  • lines due to the wm_concat() in double request gorge yourself

    Here's the query I need to run

    SELECT the separate user interface. Index_name, UI. Owner, UI. Table_name, wm_concat (uic.column_name) on column_name (partition by order of position_colonne uic.index_name), the ui.index_type, the parameters
    Of
    all_IND_COLUMNS UI all_INDEXES JOIN UIC
    ON UIC. INDEX_NAME = UI. INDEX_NAME
    where
    SUBSTR (UI.index_name, 1, 3) not IN ("PK_", 'UQ_', ' DR$ ")
    and ui.index_name not like 'SYS_C00% '.
    and ui.index_name not like 'SYS_IOT_TOP_ %' and owner = 'USER1 '.
    control of the user interface. INDEX_NAME



    The problem is wm_concat() because the all_IND_COLUMNS table contains the entry duplicated for index (index1 of the table(column1,column2,column3) type)

    for this wm_concat returns the result as below:
    --------------------
    Column1
    Column1, Column2
    Column1, Column2, Column3

    But in * result I don't need it for a particular name of index (separate index)

    as an example, I have two indexes in schema:
    index1 on table1 (column1, column2, column3) and
    Index2 on table2 (column5)

    This result need
    Row1 - index1 Column1, Column2, Column3
    Index2 column 5 row2-


    my query returns
    index1 Column1 row1-
    row2 - index1 Column1, Column2
    row3 - index1 Column1, Column2, Column3
    row4 - column 5 index2

    Are you trying this?

    SELECT UI.INDEX_NAME,
      ui.owner ,
      UI.TABLE_NAME ,
      ui.index_type,
      parameters,
      listagg(column_name,',') within GROUP (
    ORDER BY column_position) column_name
    FROM all_INDEXES UI
    JOIN all_IND_COLUMNS UIC
    ON  ( UIC.INDEX_NAME                    = UI.INDEX_NAME
          and uic.index_owner = ui.owner)
    WHERE SUBSTR(ui.index_name,1,3) NOT IN ('PK_', 'UQ_','DR$')
    AND ui.index_name NOT LIKE 'SYS_C00%'
    AND ui.index_name NOT LIKE 'SYS_IOT_TOP_%'
    GROUP BY UI.INDEX_NAME,
      ui.owner ,
      UI.TABLE_NAME ,
      ui.index_type,
      parameters
    ORDER BY UI.INDEX_NAME;
    
  • WM_CONCAT() not available

    Hello

    I tried the below in Oracle 10 g XE.
    In fact, my requirement is, I have a table named "table1" that has a column ID.
    The values are:
    1
    2
    3
    4
    I need the result form:
    1,2,3,4
    I tried the query below:
    select wm_concat(ID) from table1
    select listagg(ID,',') from table1
    Two permits ORA-00904.
    Please help me to achieve this goal.

    Thank you

    Try this-

    SELECT rtrim(xmlagg(xmlelement(e,column_name,',').extract('//text()')),',') aa
    from TABLE_NAME;
    
  • ORA-06512: at "WMSYS. WM_CONCAT_IMPL', line 30

    Select No, wm_concat (cleared) in the clr of the association_1 group by the;

    That's what I get at the end;

    ERROR:
    ORA-06502: PL/SQL: digital or value error: character string buffer too small
    ORA-06512: at "WMSYS. WM_CONCAT_IMPL', line 30


    even if I use the 2nd method by creating type I still get the same error

    Select No, row_col (cleared) in the clr of the association_1 group by the;


    ORA-06502: PL/SQL: digital or value error: character string buffer too small
    ORA-06512: at "ALI. T_ROW_COL', line 22

    REATE OR REPLACE TYPE t_row_col AS OBJECT
    (
      g_string  VARCHAR2(32767),
    
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_row_col)
        RETURN NUMBER,
    
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_row_col,
                                           value  IN      VARCHAR2 )
         RETURN NUMBER,
    
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_row_col,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER,
    
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_row_col,
                                         ctx2  IN      t_row_col)
        RETURN NUMBER
    );
    /
    
    
    CREATE OR REPLACE TYPE BODY t_row_col IS
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_row_col)
        RETURN NUMBER IS
      BEGIN
        sctx := t_row_col(NULL);
        RETURN ODCIConst.Success;
      END;
    
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_row_col,
                                           value  IN      VARCHAR2 )
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := self.g_string || '/' || value;
        RETURN ODCIConst.Success;
      END;
    
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_row_col,
                                             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_row_col,
                                         ctx2  IN      t_row_col)
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := SELF.g_string || '/' || ctx2.g_string;
        RETURN ODCIConst.Success;
      END;
    END;
    /
    
    
    CREATE OR REPLACE FUNCTION row_col (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_row_col;
    /
    ************************************************************************************
    How can I fix this erros

    It is because there is a limit to how big a varchar2 can result (4000 bytes), and you exceed.

    What you need is to use a version of the CLOB basis rather for example

    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>
    
  • Order WM_CONCAT

    Hello

    Is it possible to put the values in the WM_CONCAT function:

    Statement:
    wm_concat (rental_next_date) rental_date,

    Output:
    25-FEB-11,25-OCT-12,25-APR-12,25-DEC-11,25-APR-11

    The above dates is controllable by Crescent?

    Thank you

    sliderrules wrote:
    Thank you all for your comments. The listagg has no effect on the order of dates.

    That's because you ordered solely on the id. If you want to order on the dates, you will have to ask him.

  • my PC Backup, Reg Clean Pro &amp; Research protect all piggyback on my Installer Firefox 26, for which I had to replace my Norton caveat regarding security issues.

    my PC Backup, Reg Clean Pro & Research protect ALL grafted onto my Installer Firefox 26, for which I had to replace my Norton caveat regarding security issues.

    Based on your research, I also substitute a Norton Security warning.

    I have windows 7 and complete Norton Security

    You downloaded firefox from the official site. Sometimes the software gets supplied with malware or adware, as in your case.
    In some cases, I recommend uninstalling (your software also mentioned), FF data directory deleting and then reinstalling FF of mozilla.org

  • Protector suite Reg Keys

    No one knows what the reg keys are created when you enable start of fingerprints? Or how to change the registry to reactivate without the Protector Suite software?

    And what is the reason for this?

Maybe you are looking for