Solved

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

Posted on 2008-10-21
1
910 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

738 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