dbTalk Databases Forums  

PL-SQL Problem

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss PL-SQL Problem in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joydeep Chakrabarty
 
Posts: n/a

Default PL-SQL Problem - 04-02-2011 , 09:03 AM






Hi,

I am using PL-SQL code to find out the number of rows in the tables in
the user XYZ.

set serveroutput on;
DECLARE
sqlstr VARCHAR2(1000);
cnt NUMBER;
BEGIN
FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER =
'XYZ') loop
sqlstr := 'select count(*) into cnt from ' || v_rec.table_name
;
-- DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;

I am getting ORA-00905 "Missing Keyword" error.
Please help. Thanks in advance,

Jaydip

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: PL-SQL Problem - 04-02-2011 , 10:21 AM






On 02-04-2011 16:03, Joydeep Chakrabarty wrote:
Quote:
set serveroutput on;
DECLARE
sqlstr VARCHAR2(1000);
cnt NUMBER;
BEGIN
FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER = 'XYZ')
loop
sqlstr := 'select count(*) into cnt from ' || v_rec.table_name ;
-- DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;

set serveroutput on;
DECLARE
cursor c1 is
SELECT table_name FROM all_tables WHERE OWNER = 'XYZ';
cnt NUMBER := 0;
BEGIN
FOR v_rec IN c1 loop
EXECUTE IMMEDIATE 'select count(*) from ' || v_rec.table_name
INTO cnt;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;


--
Luuk

Reply With Quote
  #3  
Old   
Joydeep Chakrabarty
 
Posts: n/a

Default Re: PL-SQL Problem - 04-02-2011 , 11:44 AM



Luuk wrote :
Quote:
On 02-04-2011 16:03, Joydeep Chakrabarty wrote:
set serveroutput on;
DECLARE
sqlstr VARCHAR2(1000);
cnt NUMBER;
BEGIN
FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER = 'XYZ')
loop
sqlstr := 'select count(*) into cnt from ' || v_rec.table_name ;
-- DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;


set serveroutput on;
DECLARE
cursor c1 is
SELECT table_name FROM all_tables WHERE OWNER = 'XYZ';
cnt NUMBER := 0;
BEGIN
FOR v_rec IN c1 loop
EXECUTE IMMEDIATE 'select count(*) from ' || v_rec.table_name
INTO cnt;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;
It's not displaying any output.

Thanks,
Jaydip

Reply With Quote
  #4  
Old   
Luuk
 
Posts: n/a

Default Re: PL-SQL Problem - 04-02-2011 , 12:31 PM



On 02-04-2011 18:44, Joydeep Chakrabarty wrote:
Quote:
Luuk wrote :
On 02-04-2011 16:03, Joydeep Chakrabarty wrote:
set serveroutput on;
DECLARE
sqlstr VARCHAR2(1000);
cnt NUMBER;
BEGIN
FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER = 'XYZ')
loop
sqlstr := 'select count(*) into cnt from ' || v_rec.table_name ;
-- DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;


set serveroutput on;
DECLARE
cursor c1 is
SELECT table_name FROM all_tables WHERE OWNER = 'XYZ';
cnt NUMBER := 0;
BEGIN
FOR v_rec IN c1 loop
EXECUTE IMMEDIATE 'select count(*) from ' || v_rec.table_name
INTO cnt;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;

It's not displaying any output.

Thanks,
Jaydip


And did it give any errors?

If not, than probably you forgot to change line 3
"WHERE OWNER = 'XYZ';"
to the correct owner?

I did test this on the HR [1] database (10g XE) using Oracle SQL
Developer 2.1.1.64

[1]:
http://download.oracle.com/docs/cd/B...scripts003.htm
--
Luuk

Reply With Quote
  #5  
Old   
Mark D Powell
 
Posts: n/a

Default Re: PL-SQL Problem - 04-02-2011 , 12:45 PM



On Apr 2, 12:44*pm, Joydeep Chakrabarty <c.joyd... (AT) gmail (DOT) com> wrote:
Quote:
Luuk wrote :





On 02-04-2011 16:03, Joydeep Chakrabarty wrote:
set serveroutput on;
DECLARE
* *sqlstr * *VARCHAR2(1000);
* *cnt * * * *NUMBER;
BEGIN
* *FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER ='XYZ')
loop
* * * *sqlstr := 'select count(*) into cnt from ' || v_rec.table_name ;
-- * * *DBMS_OUTPUT.PUT_LINE(sqlstr);
* * * *EXECUTE IMMEDIATE sqlstr;
* * * *DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
* *END LOOP;
END;

set serveroutput on;
DECLARE
* *cursor c1 is
* * * SELECT table_name FROM all_tables WHERE OWNER = 'XYZ';
* *cnt * * * *NUMBER := 0;
BEGIN
* *FOR v_rec IN c1 loop
* * * * EXECUTE IMMEDIATE 'select count(*) from ' || v_rec.table_name
INTO cnt;
* * * *DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
* *END LOOP;
END;

It's not displaying any output.

Thanks,
Jaydip- Hide quoted text -

- Show quoted text -
Jaydip, by any chance did you miss having the "serveroutput on"
statement when you tested Luuk's code?

Here is another example of using execute into:

Is there a simple way to produce a report of all tables in the
database with current number of rows ?
http://www.jlcomp.demon.co.uk/faq/count_all_rows.html

HTH -- Mark D Powell --

Reply With Quote
  #6  
Old   
Joydeep Chakrabarty
 
Posts: n/a

Default Re: PL-SQL Problem - 04-02-2011 , 01:08 PM



After serious thinking Luuk wrote :
Quote:
On 02-04-2011 18:44, Joydeep Chakrabarty wrote:
Luuk wrote :
On 02-04-2011 16:03, Joydeep Chakrabarty wrote:
set serveroutput on;
DECLARE
sqlstr VARCHAR2(1000);
cnt NUMBER;
BEGIN
FOR v_rec IN (SELECT table_name FROM all_tables WHERE OWNER = 'XYZ')
loop
sqlstr := 'select count(*) into cnt from ' || v_rec.table_name ;
-- DBMS_OUTPUT.PUT_LINE(sqlstr);
EXECUTE IMMEDIATE sqlstr;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;


set serveroutput on;
DECLARE
cursor c1 is
SELECT table_name FROM all_tables WHERE OWNER = 'XYZ';
cnt NUMBER := 0;
BEGIN
FOR v_rec IN c1 loop
EXECUTE IMMEDIATE 'select count(*) from ' || v_rec.table_name
INTO cnt;
DBMS_OUTPUT.PUT_LINE(v_rec.table_name ||',' || cnt);
END LOOP;
END;

It's not displaying any output.

Thanks,
Jaydip



And did it give any errors?

If not, than probably you forgot to change line 3
"WHERE OWNER = 'XYZ';"
to the correct owner?

I did test this on the HR [1] database (10g XE) using Oracle SQL
Developer 2.1.1.64

[1]:
http://download.oracle.com/docs/cd/B...scripts003.htm
Thanks ! It worked.

Thanks,
Jaydip

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.