Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Select Count off tables.

Re: Select Count off tables.

From: Jason Filby <jason.filby_at_orafocus.com>
Date: 27 Jul 2001 06:46:04 GMT
Message-ID: <996216289.434111@proxy.storm.co.za>

Use dynamic SQL. The code I've included uses htp.p for web output but you can replace it with anything else.

create or replace procedure example_code is cursor curs is
  select distinct table_name from all_tab_columns   where owner = 'SYS'
  order by 1;
  cs number;
  ret number;
  tab_count number;
begin
  cs:=dbms_sql.open_cursor;

  for i in curs loop
    dbms_sql.parse(cs, 'select count(*) from '||i.table_name, DBMS_SQL.NATIVE);
    dbms_sql.define_column(cs, 1, tab_count);

    ret:=dbms_sql.execute(cs);
    ret:=dbms_sql.fetch_rows(cs);

    dbms_sql.column_value(cs, 1, tab_count);     htp.p(tab_count||', '||i.table_name||'<br>');   end loop;

  dbms_sql.close_cursor(cs);

  exception when others then htp.p(sqlerrm); end example_code;
/
show err;

Posted via www.orafocus.com - Focusing on the World of Oracle Received on Fri Jul 27 2001 - 01:46:04 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US