I'm scratching my head over this Oracle error. The following query works perfectly:
SELECT
V.PROJECTID,
(SELECT WM_CONCAT(DISTINCT NAME)
FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS USING (METHODID)
WHERE PROJECTID=V.PROJECTID
AND VERSIONID=V.VERSIONID) as Methods
FROM TPM_PROJECTVERSION V
However, I want to return my concantonated list in alphabetical order because I'm picky like that. You'd think I would do:
SELECT
V.PROJECTID,
(SELECT WM_CONCAT(DISTINCT NAME)
FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS USING (METHODID)
WHERE PROJECTID=V.PROJECTID
AND VERSIONID=V.VERSIONID ORDER BY NAME) as Methods
FROM TPM_PROJECTVERSION V
However, when I try this I get the error:
[Error] Script lines: 15-19 ------------------------
ORA-00907: missing right parenthesis
I can run the query in its own SELECT statement, like so:
SELECT WM_CONCAT(DISTINCT NAME)
FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS USING (METHODID)
WHERE PROJECTID=240
AND VERSIONID=1
ORDER BY NAME
And it runs fine. My parenthesis are more balanced than a Cirque du Soleil troop. Why the error?
I think the aggregated WM_CONCAT function isn't affected by ORDER BY.
Therefor, as promised, a custom aggregation that sorts the results. Can be used in earlier versions too.
Now your query could look something like this: