dbTalk Databases Forums  

PL/SQL code

comp.databases.oracle comp.databases.oracle


Discuss PL/SQL code in the comp.databases.oracle forum.



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

Default PL/SQL code - 07-20-2004 , 04:25 PM






Hi,

I have a piece of code (attached bellow) that grabs the names of
several tables in my schema. I now want to grab a maximum value of one
of the columns from these tables (same column name in all the tables).
Is there any way other then spooling the output (as shown below) into
a file and running that file?

As you can see from the code I'm a beginner at this so any help will
be much appreciated.

Thanks,
Doron







Declare

CURSOR SITE_BASE_CUR IS select tdm_base_obj_id from tdm_db_site_ranges
where object_id = (select object_id from tdm_db_site where tdm_name =
(select global_name from
global_name));

site_base tdm_db_site_ranges.tdm_base_obj_id%type ;

cursor up_tab is select table_name from tdm_class where class_id in
(select class_id from tdm_last_object_id where object_id>0);

update_table tdm_class.table_name%type ;





begin


open site_base_cur;
fetch site_base_cur into site_base;

open up_tab;
loop
fetch up_tab into update_table;


exit when up_tab%notfound;
dbms_output.put_line(‘select max(column_1) from' update_table);
end loop;
end ;

Reply With Quote
  #2  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: PL/SQL code - 07-21-2004 , 01:02 PM






you probably want to use dynamic SQL -- check out EXECUTE IMMEDIATE in the
PL/SQL docs

++ mcs

"Doron" <doron_almog (AT) msn (DOT) com> wrote

Quote:
Hi,

I have a piece of code (attached bellow) that grabs the names of
several tables in my schema. I now want to grab a maximum value of one
of the columns from these tables (same column name in all the tables).
Is there any way other then spooling the output (as shown below) into
a file and running that file?

As you can see from the code I'm a beginner at this so any help will
be much appreciated.

Thanks,
Doron







Declare

CURSOR SITE_BASE_CUR IS select tdm_base_obj_id from tdm_db_site_ranges
where object_id = (select object_id from tdm_db_site where tdm_name =
(select global_name from
global_name));

site_base tdm_db_site_ranges.tdm_base_obj_id%type ;

cursor up_tab is select table_name from tdm_class where class_id in
(select class_id from tdm_last_object_id where object_id>0);

update_table tdm_class.table_name%type ;





begin


open site_base_cur;
fetch site_base_cur into site_base;

open up_tab;
loop
fetch up_tab into update_table;


exit when up_tab%notfound;
dbms_output.put_line('select max(column_1) from' update_table);
end loop;
end ;



Reply With Quote
  #3  
Old   
padmaja_kad@yahoo.com
 
Posts: n/a

Default Re: PL/SQL code - 07-25-2004 , 12:57 PM



Hi Doron,

You can use dynamic sql. It will let you build the sql statement and
execute it.
The following link has good examples.

http://www.cise.ufl.edu/help/databas...ynam.htm#13131

Padma


doron_almog (AT) msn (DOT) com (Doron) wrote in message hnews:<995517bc.0407201325.16ac4e6a (AT) posting (DOT) google.com>...
Quote:
Hi,

I have a piece of code (attached bellow) that grabs the names of
several tables in my schema. I now want to grab a maximum value of one
of the columns from these tables (same column name in all the tables).
Is there any way other then spooling the output (as shown below) into
a file and running that file?

As you can see from the code I'm a beginner at this so any help will
be much appreciated.

Thanks,
Doron







Declare

CURSOR SITE_BASE_CUR IS select tdm_base_obj_id from tdm_db_site_ranges
where object_id = (select object_id from tdm_db_site where tdm_name =
(select global_name from
global_name));

site_base tdm_db_site_ranges.tdm_base_obj_id%type ;

cursor up_tab is select table_name from tdm_class where class_id in
(select class_id from tdm_last_object_id where object_id>0);

update_table tdm_class.table_name%type ;





begin


open site_base_cur;
fetch site_base_cur into site_base;

open up_tab;
loop
fetch up_tab into update_table;


exit when up_tab%notfound;
dbms_output.put_line(?select max(column_1) from' update_table);
end loop;
end ;

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.