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


Question and Answer

Chris Saxon

Thanks for the question, Ik.

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

Last updated: February 28, 2017 - 5:14 pm UTC


Viewed 10K+ times! This question is

You Asked


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.


and Chris said...

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

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

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

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 Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library