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

Breadcrumb

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

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