Skip to Main Content
  • Questions
  • Executing OS commands from PLSQL code

Breadcrumb

more

Connor and Chris don't just spend all day on AskTOM. You can also catch regular content via Connor's blog and Chris's blog. Or if video is more your thing, check out Connor's latest video and Chris's latest video from their Youtube channels. And of course, keep up to date with AskTOM via the official twitter account.

Question and Answer

Chris Saxon

Thanks for the question, Ik.

Asked: February 28, 2017 - 8:11 am UTC

Answered by: Chris Saxon - Last updated: February 28, 2017 - 5:14 pm UTC

Category: Database - Version: 12.1.0.2

Viewed 10K+ times! This question is

Whilst you are here, check out some content from the AskTom team: Apex patch for 5.1

You Asked

Hi,

Is there a native Oracle solution to execute OS commands via PLSQL or SQL? I searched on the web and do not find an easy or straight forward technique. Can you please help?

Assuming OS is Linux and the command to execute is any executable or a tool, say srvctl.

thanks
Ik

and we said...

There are a few ways you can achieve this. You could write a Java stored procedure to accept and run commands:

https://oracle-base.com/articles/8i/shell-commands-from-plsql

Or use DBMS_pipe to send commands to a daemon running on the server:

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:16212348050

Or use DBMS_scheduler to run OS commands (10g and up):

https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:16212348050#39092679158568

Whichever approach you take, be careful. Ensure you can't run commands like "rm -rf *" as a privileged OS user from PL/SQL!

Is this answer out of date? If it is, please let us know via a Review

More to Explore

DBMS_PIPE

More on PL/SQL routine DBMS_PIPE here