views:

239

answers:

1

When I try to use WMSYS.WM_CONCAT with Oracle XE 10g, I receive a compilation error: ORA-00904: "WMSYS"."WM_CONCAT": invalid identifier. Can anyone verify that this is indeed due to XE lacking this (undocumented) feature? If so, is there anyway to enable it in XE?

+1  A: 

I had found a couple reference sites, but had no luck enabling it. I ended up writing my own function to handle the concatenation.

CREATE or replace FUNCTION CONCAT_LIST( cur SYS_REFCURSOR, sep Varchar2 ) RETURN  VARCHAR2 IS
ret VARCHAR2(32000);
tmp VARCHAR2(4000);
BEGIN
loop
  fetch cur into tmp;
  exit when cur%NOTFOUND;
    if ret is null then
       ret := tmp;
    else
      ret := ret || sep || tmp;
    end if;

end loop;
RETURN ret; END;/

Then it can be called as

SELECT distinct CONCAT_LIST(CURSOR(SELECT id FROM test_table1), ',') test_table1 FROM dual

RandyB
Thanks, I'm really curious as to whether this function can be enabled. The best alternative I found was the User-defined Aggregate Function here: http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php. I renamed the function from string_agg to wm_concat since then I can share stored procedures with my co-workers who have full oracle 10g (the method given in the article allows the same syntax you would use with the real wm_concat -- as long as you are not using scripts which fully qualify wm_concat with wm_sys)
Stephen Swensen
That is pretty slick. I have a couple of large queries that I am using this function. As soon as I am back in the office I will create the new one and check performance. This has me curious. Thanks!
RandyB
Cool, I'd love to hear your performance results when you're done.
Stephen Swensen
I did some load testing on both functions, CONCAT_LIST and STRING_AGG and found I had to make one modification to my function. I forgot to close the cursor and I maxed out the allowed amount rather quickly. After making the change I created a query that grouped a set of 250 shops to their corresponding type. The CONCAT_LIST completed in 2.68 seconds and the STRING_AGG from oracle-base completed in 0.38 seconds and looks a lot cleaner. I have changed the few queries I had to reference this new function. Here I thought I could help you and you ended up helping me. THANKS!
RandyB
Hehe, sounds great, you're welcome!
Stephen Swensen