select count(*) in PL/SQL
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: select count(*) in PL/SQL

  1. #1
    Join Date
    Feb 2000
    Location
    CA, USA
    Posts
    3
    I was trying to do "select count(*) from tables" in PL/SQL similar to the folowing:

    declare
    cursor cur is select table_name from user_tables;
    v_tabname varchar2(100);
    v_count number;
    begin
    for v_tabname in cur
    loop
    select count(*) into v_count from v_tabname;
    /* process v_coutn */
    end loop;
    end;

    But I got 'V_TABNAME' must be declared error message. Can anyone point out where I made mistakes?

    Thanks!

  2. #2
    Join Date
    May 2000
    Location
    Richardson, Texas, USA
    Posts
    39
    You will need to use dynamic SQL to do this sort of stuff.

    Thanks.

    Syed

  3. #3
    Join Date
    Oct 2000
    Posts
    3
    If you are pre 8i you need to use DBMS_SQL package. In 8i (and maybe 8) you can use the statement EXECUTE IMMEDIATE like this:

    EXECUTE IMMEDIATE 'select count(*) from ' || v_tabl_name INTO v_count;

    Give it a shot

  4. #4
    Join Date
    Feb 2000
    Location
    CA, USA
    Posts
    3
    Thanks. It works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width