Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

sql - calling a stored proc over a dblink

I am trying to call a stored procedure over a database link. The code looks something like this:

declare
       symbol_cursor  package_name.record_cursor;
       symbol_record  package_name.record_name;
begin
       symbol_cursor := package_name.function_name('argument');
loop
       fetch symbol_cursor into symbol_record;
       exit when symbol_cursor%notfound;
       -- Do something with each record here, e.g.:
       dbms_output.put_line( symbol_record.field_a );
end loop;

CLOSE symbol_cursor;

When I run this from the same DB instance and schema where package_name belongs to I am able to run it fine. However, when I run this over a database link, (with the required modification to the stored proc name, etc) I get an oracle error: ORA-24338: statement handle not executed.

The modified version of this code over a dblink looks like this:

declare
       symbol_cursor  package_name.record_cursor@db_link_name;
       symbol_record  package_name.record_name@db_link_name;
begin
       symbol_cursor := package_name.function_name@db_link_name('argument');
loop
       fetch symbol_cursor into symbol_record;
       exit when symbol_cursor%notfound;
       -- Do something with each record here, e.g.:
       dbms_output.put_line( symbol_record.field_a );
end loop;

CLOSE symbol_cursor;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From another of your questions I remember package_name.record_cursor to be a ref cursor type. A ref cursor is a memory handle only valid in the database it was created in. In other words, you cannot create a ref cursor in your remote db and try to fetch from it your local db.

If you really need to process the data in your local db and the tables have to stay in the remote db, then you could move the package "package_name" into your local db and have it execute the query on tables in your remote db via a database link.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...