Create list string in Coldfusion is very simple. We just use ValueList function of Coldfusion. What we can do it in Oracle? As we all know, there are a lot of built-in functions in Oracle and new more functions are including whenever upgrading Oracle version. Being not DBA (database administrator), I cannot know how many built-in functions are in Oracle and how many new functions are added into each version.

Today, I need to create list string in Oracle. My first though, I would search built-in function like ValueList in Oracle. As my though, I've search again and again but have no result at all. That's why, I decided myself to create new function for creating list string as follow:

view plain print about
1CREATE FUNCTION CONCATENATE_COMMA
2RETURN VARCHAR2
3IS
4    CURSOR C_TEST IS
5    SELECT PERSON_ID FROM FROM PERSON_TABLE;
6    CON_STRING VARCHAR2(32000);
7BEGIN
8    FOR C IN C_TEST LOOP
9    CON_STRING := C.PERSON_ID||','|| CON_STRING;
10END LOOP;
11RETURN SUBSTR(CON_STRING,1, LENGTH(CON_STRING)-1);
12END;

When I rendering about code in Oracle, it 100% works and not encountered any issue. After few minutes, I found wm_concat function. I'm not sure whether it's lucky or not. And usage is very simple.

view plain print about
1SELECT WM_CONCAT(P_ID)
2INTO V_PERSON_ID
3FROM PERSON_TABLE;