is there such thing in oracle like listunagg function? For example, if I have a data like:
------------------------------------------------------------
| user_id | degree_fi | degree_en | degree_sv |
--------------------------------------------------------------
| 3601464 | 3700 | 1600 | 2200 |
| 1020 | 100 | 0 | 0 |
| 3600520 | 100,3200,400 | 1300, 800, 3000 | 1400, 600, 1500 |
| 3600882 | 0 | 100 | 200 |
--------------------------------------------------------------
and I'd like to show data like this:
-----------------------------------------------
| user_id | degree_fi | degree_en | degree_sv |
-----------------------------------------------
| 3601464 | 3700 | 1600 | 2200 |
| 1020 | 100 | 0 | 0 |
| 3600520 | 100 | 1300 | 1400 |
| 3600882 | 0 | 100 | 200 |
| 3600520 | 3200 | 800 | 600 |
| 3600520 | 400 | 3000 | 1500 |
-----------------------------------------------
I tried to find some function like opposite of listagg but couldn't find any. Thanks in advance :-)
There is
listunagg
function provided by OraOpenSource Utils package set. It also works well.To unagg a list consider what Tom has to say at Oracle's "Ask Tom" see http://www.oracle.com/technetwork/issue-archive/2007/07-mar/o27asktom-084983.html Code Listing 3 or 4.
My preferred option that Tom doesn't discuss is good for short strings (<34 characters). I use the Oracle DBMS_UTILITY.comma_to_table function. Example:
As @be here now has already noted in the comment Oracle doesn't provide such a function. So as a quick workaround you could write similar query:
Result: