Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

length issue with listagg

user021Oct 30 2017 — edited Nov 14 2017

Dear,

Listtag function is giving an error, might be column contain more value then defined in list tag. However, i tried to make dynamic function similar to listtag but still that one is also giving an error.

ORA-01489: result of string concatenation is too long

CREATE OR REPLACE function getlistagg(p_where varchar2,p_col_name varchar2,p_table varchar2)  RETURN varchar2 IS

    TYPE cur_typ IS REF CURSOR;

    c cur_typ;

    query_str VARCHAR2(200);

    inv_num NUMBER;

    v_col_val VARCHAR2(100);

    v_listtag VARCHAR2(4000);

BEGIN

    query_str := 'SELECT '||p_col_name||' FROM '||p_table||'  where '||p_where;

     

    OPEN c FOR query_str;

    LOOP

        FETCH c INTO v_col_val;

        EXIT WHEN c%NOTFOUND;

        v_listtag := v_listtag||v_col_val;

    END LOOP;

    CLOSE c; 

    return v_listtag;

END;

select getlistagg(' where deptno = 10','ename','ename') from dual

This post has been answered by New Roots on Oct 30 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2017
Added on Oct 30 2017
13 comments
3,125 views