ref cursor column names

on
declare
 l_ref sys_refcursor;
 l_cur integer;
 l_exe integer;
 l_sql varchar2(100) := 'select * from <>';
 l_tab dbms_sql.desc_tab;
 l_cnt integer;
 l_val varchar2(4000);
 l_num number;
 l_dat date;
begin
 l_cur := dbms_sql.open_cursor;
 open l_ref for l_sql;
 dbms_sql.parse(l_cur, l_sql, dbms_sql.native);
 dbms_sql.describe_columns(l_cur,l_cnt,l_tab);
 
 for i in 1..l_cnt
 loop
 
 dbms_output.put_line(i||' '||l_tab(i).col_name||' '||l_val);
 -- dbms_output.put_line('|- type : '||l_tab(i).col_type);
 -- dbms_output.put_line('|- max_len : '||l_tab(i).col_max_len); 
 -- dbms_output.put_line('|- precision : '||l_tab(i).col_precision); 
 -- dbms_output.put_line('|- scale : '||l_tab(i).col_scale);
 -- dbms_output.put_line('|- > : '||'['|| case l_tab(i).col_type when 1 then 'varchar2('||l_tab(i).col_max_len||')' when 2 then 'number('||l_tab(i).col_precision||','||l_tab(i).col_scale||')' when 12 then 'date' end ||']');
 case l_tab(i).col_type 
 when 2 then dbms_sql.define_column(l_cur, i, l_num);
 when 12 then dbms_sql.define_column(l_cur, i, l_dat);
 else dbms_sql.define_column(l_cur, i, l_tab(i).col_name,l_tab(i).col_max_len);
 end case;

 end loop;
 
 l_exe := dbms_sql.execute(l_cur);
 
 loop
 if dbms_sql.fetch_rows(l_cur) = 0 then
 exit;
 end if; 

 for j in 1..l_cnt loop
 case l_tab(j).col_type
 when 2 then 
 dbms_sql.column_value(l_cur, j, l_num); 
 l_val := l_num;
 when 12 then 
 dbms_sql.column_value(l_cur, j, l_dat);
 l_val := to_char(l_dat,'dd-mm-yyyy hh24:mi:ss');
 else 
 dbms_sql.column_value(l_cur, j, l_val);
 end case; 
 dbms_output.put_line(rpad(l_tab(j).col_name,32)||l_val); 
 end loop;
 end loop;
 
end;