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!

converting unknown number of rows to column

776778Sep 24 2010 — edited Sep 30 2010

I am trying to use the belwo code to convert unknown number of rows to column using the below code and I am getting an error. can someone help me.

ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 7

declare
    lv_sql varchar2(32767) := null ;
begin
    lv_sql := 'SELECT Iplineno ';
    for lv_rec in (select distinct vendor from bidtabs)
    loop
        lv_sql :=   lv_sql 
                    || CHR(10) 
                    || ', MAX( DECODE( vendor, ' 
                    || chr(39) 
                    || lv_rec.vendor 
                    || CHR(39) 
                    || ', quest_response, NULL ) ) as "'
                    || lv_rec.vendor
                    || '" ' ;
    end loop;
    
    lv_sql :=   lv_sql 
                || CHR(10) 
                || 'FROM bidtabs  where rownum < 10 ' 
                || CHR(10) 
                || 'GROUP BY iplineno ;' ;
                
    dbms_output.put_line(lv_sql);            
end;
/ 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 28 2010
Added on Sep 24 2010
18 comments
1,495 views