Solved

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

Posted on 2008-10-21
1
907 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
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.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

756 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