Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to remotely execute a procedure when db link is a variable in PL/SQL?

Posted on 2011-02-21
14
Medium Priority
?
806 Views
Last Modified: 2012-05-11
Two databases are linked.
IN DB2, have a procedure p1
WOULD LIKE TO EXECUTE p1 in DB1. If we put the known db link name specifically, that is OK. For example,
in DB1, in pl/sql block
p1@DB1.DOMAIN;
It runs well.

But if we make a variable,
v_dblink := 'DB1.DOMAIN';
p1@v_dblink;
It complains.
Sorry to ask the variable quetions one more time. It really stops me.
Gurus, any advice??
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
  • 2
14 Comments
 
LVL 5

Expert Comment

by:jaiminpsoni
ID: 34945238
I am not sure about the requirement, but is it possible to create synonym for the procedure on the remote DB and then execute the procedure on remote DB using synonym?

0
 

Author Comment

by:jl66
ID: 34945721
Have to connect different DB links in different envs running the same code, so this is why I need a variable there.
0
 

Author Comment

by:jl66
ID: 34945743
For example, I get the instance name from v%instace and depend on what it is about to form the db link.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jl66
ID: 34945846
I was already back one step. I tried to make the following work
if dm = 'A' then
  p1@DB1.DMA;
elsif dm = 'B' then
  p1@DB1.DMB;
elsif dm = 'C' then
....
end if;

 
0
 

Author Comment

by:jl66
ID: 34945874
I got the error:
91/4     PL/SQL: Statement ignored
91/4     PLS-00201: identifier
      'p1@DB1.DMB'   must be declared
If i was in dm = "A' env
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34945920
I don't follow that latest posts but the original question about variables: you need to use execute immediate with dymanic sql.

The latest error might be due to the compiler not being able to see db1.dmb from the database you are in.
0
 

Author Comment

by:jl66
ID: 34946123
slightwv:
2 questions for you:
1) in pl/sql block (v_sqlttext is a procedure in remote database, NOT DML or DDL), is
execute immediate v_sqltext;
still valid. It seems not. How to deal with it.

2) If 1) is hard to achieve, I have to use the way to separate the env.
if dm = 'A' then
  p1@DB1.DMA;
elsif dm = 'B' then
  p1@DB1.DMB;
elsif dm = 'C' then
....
end if;

If compiler could not see the "p1@DB1.DMB; ", how to let the compiler see it???
Greatly appreciate your help.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34946221
>>But if we make a variable,

This is where I'm confused.  Are you using variables or not?

It appears that you might have shifted the question.
0
 

Author Comment

by:jl66
ID: 34946277
Yes. Use a variable for a procedure located in a remote database.
0
 

Author Comment

by:jl66
ID: 34946285
Execute it in a pl/sql in local DB. How to do it??
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 200 total points
ID: 34946306
Use execute immediate when using variables and dynamic sql.

Where are we crossing wires?
0
 
LVL 5

Accepted Solution

by:
jaiminpsoni earned 1800 total points
ID: 34946321
You can achieve 2 using following....

proc := 'testproc;';
execute immediate('begin '||proc||' end;');

Have you tried that?

I guess this should work for 1 as well.

following may help you...

http://www.dulcian.com/Articles/Execute_Immediate.htm

0
 

Author Comment

by:jl66
ID: 34947417
jaiminpsoni: thanks a lot. It works.
0
 

Author Closing Comment

by:jl66
ID: 34947443
Very good.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question