dbTalk Databases Forums  

Re: Rookie Question

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


Discuss Re: Rookie Question in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dirk Tschentscher
 
Posts: n/a

Default Re: Rookie Question - 07-10-2003 , 08:51 AM






Hi Rüdiger

you can do it with "execute immediate"
execute immediate 'SELECT count(*) FROM '||r.tablename into rows;
execute immediate 'UPDATE info_tablerows SET rowcount ='|| rows ||
'WHERE tablename = '|| r.tablename ;
It's not possible with normal SQL

Rgds
Dirk
"Ruediger Tams" <ruediger.tams (AT) komtel (DOT) net> schrieb im Newsbeitrag
news:3F0D6CAF.9B59D538 (AT) komtel (DOT) net...
Quote:
Hello,
possibly it is a very simple "rookie" question but:
This statement don't work. why?

DECLARE
CURSOR c1 IS
SELECT a.tablename FROM info_tablerows a;
rows number;
BEGIN
FOR r IN c1 LOOP
SELECT count(*) INTO rows FROM r.tablename;
UPDATE info_tablerows SET rowcount = rows WHERE tablename =
r.tablename;
END LOOP;
END;
/

At "SELECT count(*) INTO rows FROM r.tablename;" the message
"identifier r.tablename must be declared" appears.
Isn't it possible to reference my tablename?

Thanks for hints.

regards ruediger




Reply With Quote
  #2  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: Rookie Question - 07-10-2003 , 11:05 AM






Dirk Tschentscher wrote:

Quote:
Hi Rüdiger

you can do it with "execute immediate"
execute immediate 'SELECT count(*) FROM '||r.tablename into rows;
execute immediate 'UPDATE info_tablerows SET rowcount ='|| rows ||
'WHERE tablename = '|| r.tablename ;
It's not possible with normal SQL

Rgds
Dirk
"Ruediger Tams" <ruediger.tams (AT) komtel (DOT) net> schrieb im Newsbeitrag
news:3F0D6CAF.9B59D538 (AT) komtel (DOT) net...
Hello,
possibly it is a very simple "rookie" question but:
This statement don't work. why?

DECLARE
CURSOR c1 IS
SELECT a.tablename FROM info_tablerows a;
rows number;
BEGIN
FOR r IN c1 LOOP
SELECT count(*) INTO rows FROM r.tablename;
UPDATE info_tablerows SET rowcount = rows WHERE tablename =
r.tablename;
END LOOP;
END;
/

At "SELECT count(*) INTO rows FROM r.tablename;" the message
"identifier r.tablename must be declared" appears.
Isn't it possible to reference my tablename?

Thanks for hints.

regards ruediger

In addition run the following SQL statement:

select keyword from v_$reserved_words
where keyword like 'RO%';

You made a remakably bad choice for a variable name.

--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)




Reply With Quote
  #3  
Old   
Rene Nyffenegger
 
Posts: n/a

Default Re: Rookie Question - 07-12-2003 , 06:53 AM




Quote:
Hello,
possibly it is a very simple "rookie" question but:
This statement don't work. why?

DECLARE
CURSOR c1 IS
SELECT a.tablename FROM info_tablerows a;
rows number;
BEGIN
FOR r IN c1 LOOP
SELECT count(*) INTO rows FROM r.tablename;
UPDATE info_tablerows SET rowcount = rows WHERE tablename =
r.tablename;
END LOOP;
END;
/

At "SELECT count(*) INTO rows FROM r.tablename;" the message
"identifier r.tablename must be declared" appears.
Isn't it possible to reference my tablename?

regards ruediger
Ruediger,

You might want to try dmbs_stats.gather_table_stats alternatively:


create table t1 (a number);

begin
for i in 100 .. 110 loop
insert into t1 values (i);
end loop;
end;
/

create table t2 (a number);

begin
for i in 1000 .. 1100 loop
insert into t2 values (i);
end loop;
end;
/

create table t3 (a number);
begin
for i in 2000 .. 2200 loop
insert into t3 values (i);
end loop;
end;
/

commit;


create table info_tablerows (
tablename varchar2(30) primary key
);

insert into info_tablerows values ('t1');
insert into info_tablerows values ('t2');
insert into info_tablerows values ('t3');

commit;

declare
cursor c is select tablename from info_tablerows;
begin
for r in c loop
dbms_output.put_line(r.tablename);
dbms_stats.gather_table_stats(user,r.tablename);
end loop;
end;
/

create view v_num_rows as
select num_rows, table_name from
user_tables u, info_tablerows i where
u.table_name = upper(i.tablename);

select * from v_num_rows;



hth
Rene Nyffenegger

--
Projektleitung und Entwicklung in Oracle/C++/C# Projekten
http://www.adp-gmbh.ch/cv.html


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.