I have the following query:
SELECT wm_concat(DISTINCT NAME) as Methods FROM TPM_TRAININGPLAN
JOIN TPM_DELIVERYMETHODS USING (METHODID)
WHERE PROJECTID=735 AND VERSIONID=1
ORDER BY NAME
On our production database (some uber expensive Oracle SKU that costs more than my house *), it returns:
I/OLT,ILT-WEB,OLT,QRG
However, on my local Oracle Express instance (11g) which I use for development, I get the error:
>[Error] Script lines: 13-16 ------------------------
ORA-00904: "WM_CONCAT": invalid identifier
Script line 13, statement line 1, column 7
Does Oracle Express not support this, or is there a work-around (such as can I copy the function from our production server, or run some script to “mimic” it?) Thanks!
* No seriously it actually costs more than my house.
UPDATE:
As suggested, I tried the LISTAGG function (which is indeed included in both Express 11g and the “Shall we buy an Oracle license or a second yacht” SKU. This seems to almost work, but has a few drawbacks which I can’t find a good workaround for. First, the query:
SELECT LISTAGG(NAME, ',') WITHIN GROUP (ORDER BY NAME) Methods FROM
TPM_TRAININGPLAN
JOIN TPM_DELIVERYMETHODS USING (METHODID) WHERE PROJECTID=240 AND VERSIONID=1
Will return:
COMM,COMM,ILT-F2F,ILT-F2F,ILT-F2F,ILT-F2F,ILT-F2F
However, I want to remove the dupes. Changing NAME to DISTINCT NAME will throw the error DISTINCT option not allowed for this function
Well great, we’ll just toss a CTE in there:
WITH Methods AS
(SELECT DISTINCT NAME
FROM TPM_TRAININGPLAN
JOIN TPM_DELIVERYMETHODS USING (METHODID) WHERE PROJECTID=240 AND VERSIONID=1)
SELECT LISTAGG(NAME, ',') WITHIN GROUP (ORDER BY NAME) Methods FROM Methods
This works, however I forgot to mention that I’m running this entire thing as a nested select in a larger query. It seems you can have nested selects that include a CTE, however within the query you can no longer refer to the root query, only the CTE. So now I can’t replace 240 and 1 with the appropriate values from the row I’m on.
if you are in 11GR2, you ought to be able to do listagg
I don’t have Oracle Express 11Gr2 to test this (just enterprise).
But Oracle Express does not have Java support, but you can try to implement it via custom types (once again I don’t have Express to test with!)
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:2196162600402