Solved

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

Posted on 2008-10-21
1
892 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
Comment Utility
         EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || MYTABLES(INX) into n;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

772 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

10 Experts available now in Live!

Get 1:1 Help Now