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

x
?
Solved

Can I log in another database in Oracle PL/SQL block?

Posted on 2011-02-19
9
Medium Priority
?
922 Views
Last Modified: 2012-08-13
Have a need to log in another database to do something like truncate a table, etc, then come back to continue process in a PL/SQL procedure. Is that possible and how?
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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34934913
I'm not sure if you can truncate or not an am on mobile right now so I can't test it but you should be able to as least delete using database links.

I've never tried truncate across a link.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34934961
Another possibility: create a procedure in the remote database that does everything you need and execute it remotely across the link.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 34935019
You can't do that (change connection) in midst of a block. You can do that in SQL*Plus, e.g. by using the SQL*Plus CONNECT command - but that will not "return", you will have to disconnect and connect back to the original connection. Or spawn another sqlplus with the host command, doing whatever you want to do remotely. Returning from that sqlplus will continue execution in the original connection.

TRUNCATE is considered as being a DDL command, and those cannot be executed via dblink.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:jl66
ID: 34935157
Thanks for Gurus' inputs. Have to truncate table. Delete would take a few hours.
Could slightwv pls give a a bit detail on how to do it via a remote procedure? For example, invoke the remote procedure via a dblink. Is it possible?
 
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1400 total points
ID: 34935191
Still on mobile so cannot test.

Create a procedure in the remote database using dynamic sql something like:

Create or replace procedure myproc
Is
Begin
Execute immediate 'truncate table mytab';
End;
/

Then across the link should go like(on mobile and can't test):
Begin
 Remote_proc@remotedb(param);
End;
/
0
 
LVL 18

Assisted Solution

by:sventhan
sventhan earned 200 total points
ID: 34935265

Hmmm.... interesting...

I do not think truncate is allowed via DB link.

02021, 00000, "DDL operations are not allowed on a remote database"
// *Cause: An attempt was made to use a DDL operation on a remote database.
// For example, "CREATE TABLE tablename@remotedbname ...".
// *Action: To alter the remote database structure, you must connect to the
// remote database with the appropriate privileges.
0
 
LVL 18

Expert Comment

by:sventhan
ID: 34935273
Sorry! It was already covered by Qlemo and I did not read his comments when I posted mine.
0
 

Author Comment

by:jl66
ID: 34935521
Actually I got the following error when I tried to execute the truncate statement.:

"ORA-00942: table or view does not exist"
The reason for that is that when executing "truncate table table_name", the pl/sql engine expects table_name is not a variable. Can any trick overcome it?
0
 

Author Closing Comment

by:jl66
ID: 34936079
Very helpful. Thanks a lot.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

636 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