Solved

Variable table name in FROM of a SELECT in PL/SQL

Posted on 2008-10-21
1
896 Views
Last Modified: 2013-12-18
Hallo all,

I want to output number of rows in 10 tables.

1) how to make the attached code work in Oracle 10? I get "ORA-00933: SQL-Befehl wurde nicht korrekt beendet" on the line "select count(*) into n from mytables(i);"
2) it there a better way to accomplish my task?

Thanks
declare

 type tables_varray is varray(10) of varchar2(100);

 mytables tables_varray := tables_varray('MPM_MITA', 'MPM_ORGA', 'MPM_VEBE', 'MPM_FUNK', 'LIS_RV', 'BVS_BV', 'BVS_BV_BESTELLUNG', 'BVS_BV_BIETER', 'BVS_KONTAKT', 'BVS_FRZGPROJ');

 n number;

begin

  FOR i in mytables.first .. mytables.last LOOP

    select count(*) into n from mytables(i); 

    dbms_output.put_line(mytables(i) || ': ' || n);

  END LOOP;

end;

Open in new window

0
Comment
Question by:igormukhin
1 Comment
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 500 total points
ID: 22765717
         EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || MYTABLES(INX) into n;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to take different types of Oracle backups using RMAN.

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now