If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > exec a procedure and pass in a parameter

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-12, 11:00
robnye robnye is offline
Registered User
 
Join Date: Feb 2012
Posts: 1
exec a procedure and pass in a parameter

I am trying to create a procedure that will read in a param and then use that within a cursor - see code below

i am trying to read data from another database via a db_link, the db_link name is the parameter being passed in using the command

BEGIN get_disk_times('TargetDB'); END;

the error being thrown is regarding the PL/SQL: ORA-01729: database link name expected relating to the line 'CURSOR'

Create or replace PROCEDURE get_schema_sizes_SIE(thisDB IN VARCHAR) IS

CURSOR cSchemas IS SELECT TRUNC(SYSDATE)-1 timestamp1, '||thisDB||' DB, owner schema, SUM(bytes)/1024/1024 Mbytes FROM dba_segments@'||thisDB||'
GROUP BY OWNER
ORDER BY OWNER ASC;

BEGIN

FOR ThisRec IN cSchemas LOOP
BEGIN
INSERT INTO schema_sizes VALUES(ThisRec.timestamp1, ThisRec.DB, ThisRec.schema, ThisRec.Mbytes);
EXCEPTION
WHEN OTHERS THEN NULL;
END;
END LOOP;
commit;
execute immediate 'ALTER SESSION CLOSE DATABASE LINK ' || thisDB;

END get_schema_sizes_SIE;

any help would be greatly appreciated
Reply With Quote
  #2 (permalink)  
Old 02-03-12, 11:23
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
SQL statements must be static within PL/SQL procedures
or EXECUTE IMMEDIATE must be used.
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 02-03-12, 13:37
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Maybe, instead of guessing syntax of cursor for dynamic SQL, you should consult it in the documentation. Cursors (as part of PL/SQL language) are described in PL/SQL User's Guide and Reference book, which is available with other Oracle documentation books e.g. online on http://tahiti.oracle.com/
For 11gR2, the relevant chapter is placed here: http://docs.oracle.com/cd/E11882_01/...mic.htm#i13057

But, maybe a single dynamic (EXECUTE IMMEDIATE) INSERT SELECT statement may be better choice over this cursor approach.

Finally, just a note about WHEN OTHERS THEN NULL exception hiding section: it just states, that you do not bother whether the INSERT fails, its failure will be silently ignored. So, in my opinion, the whole procedure is just a waste of time, as inserting nothing is also correct (non-failing) behaviour. If you do not feel so, remove that whole EXCEPTION clause forever.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On