Db2

 View Only
Expand all | Collapse all

Creating a function similar to listagg function.

  • 1.  Creating a function similar to listagg function.

    Posted Wed May 24, 2023 11:00 AM

    Hi guys!

    I am required to create a function similar to the listagg function with a different name. The function should take the "," as the separator by default and also need to be able to use the distinct clause just like the listagg. For an example, 

    The output of the statement 

    SELECT AGG_FUNC(DISTINCT COL1) FROM TABLE1

    Should be in the form of "record1,record2,record3"

    I tried user-defined aggregate functions and creating the function using the listagg function as the source but I am not able to get the required results so far.


    Thanks!



    ------------------------------
    Sahan Mendis
    ------------------------------


  • 2.  RE: Creating a function similar to listagg function.

    Posted Thu May 25, 2023 12:03 AM

    [SOLVED!] I was able to perform this task by creating the function as the listagg function as the source, and ',' as the default separator.

    Thanks!



    ------------------------------
    Sahan Mendis
    ------------------------------