Solved

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

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
null value 15 102
history tablespace temp usage 2 42
ORA-00972: identifier is too long from Unix but not from Windows in SQLPLUS 17 69
PL/SQL Two changes 7 27
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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 shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

770 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