Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you <em>really</em> need to <code>select * from</code> <em>dynamic table name</em>, then I'd probably go with <code>dbms_sql</code> </p> <p>Type for a <em>record</em>:</p> <pre><code>create type tq84_varchar2_tab as table of varchar2(4000); / </code></pre> <p>Type for a <em>result set</em> (which is an array of <em>records</em>):</p> <pre><code>create type tq84_varchar2_tab_tab as table of tq84_varchar2_tab; / </code></pre> <p>The function that does the select and returns an instance of the <em>result set</em>:</p> <pre><code>create or replace function tq84_select_star_from_table(table_name in varchar2) return tq84_varchar2_tab_tab as stmt_txt varchar2(4000); cur number; columns_desc dbms_sql.desc_tab; column_cnt number; result_set tq84_varchar2_tab_tab; begin stmt_txt := 'select * from ' || table_name; cur := dbms_sql.open_cursor; dbms_sql.parse(cur, stmt_txt, dbms_sql.native); dbms_sql.describe_columns(cur, column_cnt, columns_desc); dbms_sql.close_cursor(cur); stmt_txt := 'select tq84_varchar2_tab('; for i in 1 .. column_cnt loop if i != 1 then stmt_txt := stmt_txt || ','; end if; stmt_txt := stmt_txt || columns_desc(i).col_name; end loop; stmt_txt := stmt_txt || ') from ' || table_name; -- dbms_output.put_line(stmt_txt); execute immediate stmt_txt bulk collect into result_set; return result_set; end tq84_select_star_from_table; </code></pre> <p>The function can then be used with something like:</p> <pre><code>declare records tq84_varchar2_tab_tab; begin records := tq84_select_star_from_table('user_objects'); for i in 1 .. records.count loop dbms_output.put_line (records(i)(5) || ': ' || records(i)(1)); end loop; end; / </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload