Thursday, February 16, 2012

SQL*Plus host Command

The SQL*Plus host command allows you to run operating system commands from within a SQL*Plus session:

SQL> host date
Wed Feb  8 10:56:34 GMT 2012

SQL>

Alternatively, you can use an exclamation mark:

SQL> ! echo "Andrew was here"
Andrew was here

SQL>

... and, if you do, it is not necessary to leave a space between the exclamation mark and the OS command:

SQL> !pwd
/home/oracle/examples/host

SQL>

2 comments:

  1. host (or ho) is system independant

    in unix, you could ! and in windows $

    the return code is in &_RC, sometimes

    ReplyDelete
  2. Dear Laurent,

    That's a very useful clarification. I saw a reference to using a $ in some old documentation but it didn't make it clear that it was for Windows only. I tried it out on UNIX but could not get it to work!

    Best wishes,

    Andrew

    ReplyDelete