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


Alternatively, you can use an exclamation mark:

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


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

SQL> !pwd



Laurent Schneider said...

host (or ho) is system independant

in unix, you could ! and in windows $

the return code is in &_RC, sometimes

Andrew Stuart Reid said...

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,