Differences

This shows you the differences between two versions of the page.

Link to this comparison view

blog:commalistofcolumns [2009/11/27 17:53] (current)
Line 1: Line 1:
 +====== Table column list ======
  
 +How to get a CSV list of columns for a table?
 +
 +<code oracle8>
 +/** Supplied with a table name return a comma separated list of its columns in ascending order.
 +*/
 +FUNCTION getColumnList (fromuser VARCHAR2, ptablename VARCHAR2) return VARCHAR2 IS
 +  columnArray dbms_utility.uncl_array;​
 +  csvLen binary_integer;​
 +  csvList varchar2(4000);​
 +BEGIN
 +  select column_name
 +  bulk collect into columnArray
 +  from all_tab_cols
 +  where table_name = ptablename
 +  and owner = fromuser
 +  and hidden_column = '​NO'​
 +  order by column_name;​
 +
 +  dbms_utility.table_to_comma(columnArray,​ csvLen, csvList);
 +
 +  return csvList;
 +END;
 +</​code>​
 +{{tag>​oracle plsql programming}}