function wm_concat

Hello

I am using Oracle 11g, and I have a question about the following.

I have a table with the following data

Value of category name
AA 01 012
AA 02 63-123
BB 01 012
BB 02 63-114
03 55 BB
CC 01 088
DD 01 088
DD 02 63-145
03 65 DD

I need to extract the data in the following format

Name 01 02 03
AA 012 63-123
BB 012 55 63 - 114
CC 088
DD 088 65 63 - 145

How should I do for this?
I tried to use the wm_concat function, then using substr to extract each item, but the wm_concat function will extract some lines in the sequence (01,02,03) and other lines of the sequence (01,03,02). What can I do?

Thank you.
SQL> -- generating sample data
SQL> with t as (
  2  select 'AA' name, '01' category, '012' value from dual union
  3  select 'AA', '02', '63-123' from dual union
  4  select 'BB', '01', '012' from dual union
  5  select 'BB', '02', '63-114' from dual union
  6  select 'BB', '03', '55' from dual union
  7  select 'CC', '01', '088' from dual union
  8  select 'DD', '01', '088' from dual union
  9  select 'DD', '02', '63-145' from dual union
 10  select 'DD', '03', '65' from dual
 11  )
 12  --
 13  -- actual query:
 14  --
 15  select name
 16  ,      max(decode(category, '01', value)) "01"
 17  ,      max(decode(category, '02', value)) "02"
 18  ,      max(decode(category, '03', value)) "03"
 19  from   t
 20  group by name
 21  order by name;

NA 01     02     03
-- ------ ------ ------
AA 012    63-123
BB 012    63-114 55
CC 088
DD 088    63-145 65

Tags: Database

Similar Questions

  • pls suggest me

    Hi Master,

    I use the wm_concat function in my application. I know that's not good as well, not correct. But I use the oracle 11.1.0 version. I have no listagg function.

    Can you suggest me without function wm_concat how can I write the query below?

    SELECT WM_CONCAT (USER_GROUP_NAME)

    IN l_condition

    (SELECT DISTINCT MU. USER_GROUP_NAME

    OF EE_USER_GROUP UG.

    EE_USR_GRP_PROD_GRP UGPG,

    EE_PROD_GRP_ENTITLEMENT EGP

    WHERE UG. USER_GROUP_ID = UGPG. USER_GROUP_ID

    AND UGPG. PRODUCT_GROUP_ID = EGP. PRODUCT_GROUP_ID

    AND pge.entitlement_id = i_entitlement_id

    );

    Concerning

    AR

    Roger Troller blog: 5 ways to aggregate in a comma separated string columns

    HTH

  • 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

  • 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.

  • Select Into statement in the function db - query issued schema table

    problem with "select into" in the function db to point 10.2


    There are two schemas. "mdbdev" is the master database, and 'devusr' is granted SELECT access table to run queries in the mdbdev schema.


    with devusr, in SQL, I am able to run the following query

    Select wm_concat (strConcatedCountryList)
    from (select country_name as mdbdev.country_master mdbcm strConcatedCountryList
    where mdbcm.country_ship_status = < param? >
    order of country_name)



    but when I use the same procedure/function with 'select into' motion, failed to compile with error * "table or view does not exist."


    FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS NUMBER)
    RETURN VARCHAR2
    IS
    var2CountryList VARCHAR2 (1000);
    BEGIN
    Select wm_concat INTO var2CountryList (strConcatedCountryList)
    from (select country_name as mdbdev.country_master mdbcm strConcatedCountryList
    where mdbcm.country_ship_status = value < SHIP_STATUS >
    order of country_name);
    Return var2CountryList;
    END;


    Please advise/help/suggestion :)

    You don't have to ask for the DBA, you can run a query to find out:

    select *
    from  all_tab_privs_recd
    where owner = 'MDBDEV'
    and table_name = 'COUNTRY_MASTER'
    

    What give you?

  • Function numbers for dynamically on average over the last 30 cells

    I am a trader and I have several months of data. I currently have a percentage of the sum of all the victories and defeats by currency pair. I want to create a function that retrieves the last 30 cells of data and creates a percentage I can compare it to the percentage of total victory.

    The cells are empty, unless I have add data in either to the upper or lower row. 1 win and - 1 are losses. 0 means not configured.

    Here's a full month with 20 data cells (cells max per month are 22) of trading days:

    This is the current month:

    I have 16 months of data with percentages of victory for all my data. As you see, I also have winning monthly winning percentages easily in the examples above (with a small division). I really, really want to compile data from the last 30 cells with data to create a winning percentage. It would be necessary to sometimes include 3 different lines of different months of data to create 30 cells with a number inside.

    A friend used the COUNTIF command but I do not have it works for me.

    If there is a different website to request this detail of the question please share that too.

    Thanks in advance,

    B

    Hi Braddon,

    It would be a pretty easy task if the data to be summed up in two columns from a single table and had no gaps, but that doesn't seem to be the case.

    Screenshots of two isolated sets of cells containing two rows (railway of) the data to be summarized, but give no indication where these data will be found in the document does not provide sufficient information to start to find a solution.

    Where are the data stored? You say "data for each month." "Every month" is recorded on another table?... on a pair of rows of the same table different?

    In the image (very vague) I, the factors of complications will gather data from a subset of continually changing several tables on multiple sheets and which specific cell contains the 30 most recent reference and is the one to start the harvest.

    While a few details and clarifications.

    Kind regards

    Barry

  • Scanner HP M277 function seems to arbitrarily arrest

    Since the Mac OS upgrade, I have a strange problem. The function scanner built into the provided Apple, HP M277 printer driver seems to stop arbitrarily. When the button "scan" in the print queue window will be gray. If I go into the preferences system-> printers and Scanners and select the printer M277c6 there and click on the "Scan" button, then open Scanner it will try to open the window of the scanner, but it stall and never finish.

    When I restart the computer scanner function seems to be restored and everything works as it should. Someone has an idea of what's going on here?

    I go on the HP website and downloaded their software HP Easy Start and completely re - configure the printer with it, but still the same problem.

    Also, I reinstalled the Apple HP (19,13) v5.0 driver. But always after a certain period of time, the scanner is therefore more accessible. I was not able to point of pin code if another program is the cause. Any suggestions?

    There was an Apple update to restore scanning for some HP printers earlier today. Did you check App Store updates?

  • I have an iPhone 6 more, an official version of China, it shows a battery indicator when I turn off support, is this normal? I can depulicate this function to another iPhone? I know how?

    I have an iPhone 6 more, an official version of China, it shows a battery indicator when I turn off support, is this normal? I can depulicate this function to another iPhone? I know how?

    I remember reading somewhere on the Apple site in recent years on some models of Chinese iPhone with this capability. No other iPhones display this and there is no way to enable it. I can't find the article which includes this information.

  • In Keynote is regularly lost function undo

    Hello! I have a problem. In Keynote is regularly lost undo function. This happens randomly, and I don't understand why. Maybe it happens in some other iwork apps, but I have not tried yet used. He arrived in the Sierra of macOS. Аnyone have this happen?

    We have no problem with cancellations in any application on any of our Macs. I heard not only reports of one having this problem.

    Perform this procedure for Foundation repair;   Remove the application Keynote, empty the trash, restart the Mac and then re - install Keynote from the Mac App Store.

  • Apple Watch S2 handwritten function in 'Message' App is in Chinese and I can't change it!

    Just today got the Apple Watch S2. The handwritten function in the application 'Message' is in Chinese. I changed the language to English on the Apple Watch app on my iPhone 7 but nothing helped. You can see from the image below, the predefined answers are all in Chinese too.

    Hello

    To use the Freehand drawing, the language for a given conversation must be a language supported for freehand drawing.

    Currently these are English, simplified Chinese and traditional Chinese.

    To change the language for a conversation, press on answer and firmly press the screen.

    More information:

    Drawing freehand on your Apple Watch - Apple Support

  • Function of more limited rotation on imac than the iphone!

    I just realized that the edit > function of rotation is more limited on Photos/imac compared on my iphone.

    It is surely not good! On my 27 inch screen it only allows me to rotate 90 degrees, but on the iphone I can adjust to any angle that I wish, and it also gives a grid to help align things.

    Maybe it's a setting I'm missing - otherwise I find it's a huge gap for not being able to properly rotate the photos on my imac.

    In Photos on my Mac 2.0,.

    -I select the picture

    -Click the button to reveal the editing tools (top right photo window, to the left of the Details button)

    -then right click on the first symbol third with two arrows dotted ("crop" in French...)

    -then click, hold down and up and down

  • Are aware that even if the rotation function is no longer available on the new trackpad, it is always presented on their Apple tutorial. Please discuss!

    Are aware that even if the rotation function is no longer available on the new trackpad, it is always presented on their Apple tutorial. Please discuss!

    Hello

    Read this article to support > gestures multitouch for use on your Mac - Apple supported

  • How the batch of photos of change in Version 2.0 of Photos... impossible to find the function.

    How the batch of photos of change in Version 2.0 of Photos... impossible to find the function.  If it has been deleted to "improve" the Photo experience?

    Lot, what exactly will change?

    Titles, Descriptions and capture date - Yes.

    Select the images you want to change the title or the description and to set-up the info (command-i) pane.  Enter the title or the description in the appropriate field and he will be assigned to all selected pictures.

    If you want to batch, change the title with sequential use attached many Applescripts provided by users in the Photos for Mac user tips section.

    Batch change/correction of dates is provided by the Image ➙ setting Date and time menu option:

  • Repeat functions

    I have a function A and I stated that this function.

    I would like this feature to repeat itself

    For example,.

    I have 2 buttons called B and C

    When the user clicks on B A c and when the user click on do A and C

    I want to just write the code for the function once

    the code I want to see her like this

    A = {1 + 2-3 * 4}

    When you click on do A B

    When the user clicks on the C c A

    Instead

    When you click B do {1 + 2-3 * 4}

    When the user clicks on the C {1 + 2-3 * 4}

    Problem is solved

Maybe you are looking for