Oracle – Quick Tip – Run OS Commands Within SQL*Plus

There are occasions when you might have the need to run Operating System commands inside SQL*Plus either as part of a script or as an individual command.

If you have something simple to run as part of your .sql file that makes your script, just run them as follows:

host <OS command>

Here is an example that ran DIR command within SQL*Plus

SQL> host dir
Volume in drive C has no label.
Volume Serial Number is FCCE-BEB9

Directory of c:\_dblog\QDS

09/11/2012  10:14 AM    <DIR>          .
09/11/2012  10:14 AM    <DIR>          ..
08/30/2012  11:22 AM             1,308 add_index-rollback.sql
08/30/2012  11:21 AM             1,677 add_index_.sql
09/07/2012  10:04 AM             1,919 EXTERN_ddl.sql
08/30/2012  02:01 PM             1,952 update-rollback.sql
08/30/2012  01:13 PM             3,326 update.sql
09/07/2012  10:04 AM             6,880 alter_ddl.sql
08/30/2012  02:01 PM             6,367 alter_ddl_rollback.sql
08/30/2012  01:11 PM             1,396 alter_ddl-rollback.sql
08/23/2012  10:19 AM             1,709 alter_ddl.sql
08/31/2012  06:32 AM             5,178 clone_user.sql
08/14/2012  01:17 PM             1,598 DO_HIERARCHY_SL_UPLOAD.sql
08/14/2012  01:17 PM             2,826 DO_UPLOAD.sql
08/30/2012  02:01 PM             2,203 DO_UPLOAD_rollback.sql
08/22/2012  06:59 AM             2,991 drop_qds_user.sql
08/31/2012  06:24 AM               943 fd_dir_grant_ddl.sql
08/31/2012  06:24 AM             1,514 fd_dir_grant_rollback.sql
08/30/2012  02:01 PM             3,788 CODEBACK_HIERARCHY_ARC_ddl.sql
08/22/2012  04:52 AM             4,178 CODEBACK_HIERARCHY_SL_ARC_ddl.sql
09/07/2012  10:04 AM             1,882 HIERARCHY_SL_UPLOADER_EXTERN_ddl.sql
09/07/2012  10:04 AM             2,105 UPLOADER_EXTERN_ddl.sql
08/22/2012  04:52 AM            12,995 OB_FIX-rollback.sql
08/07/2012  12:16 PM             1,474 OB_FIX.sql
08/14/2012  01:17 PM            35,674 pkgArchive-rollback.sql
08/30/2012  02:01 PM            37,468 pkgArchive.sql
08/14/2012  01:17 PM             1,450 process_archive.sql
08/31/2012  06:32 AM             1,948 role_grants_ddl.sql
09/07/2012  10:33 AM             2,213 super_deploy.SQL
08/30/2012  02:01 PM             1,713 super_rollback.sql
08/22/2012  06:59 AM             2,766 user_role_grants_ddl.sql
08/22/2012  06:59 AM             1,588 it_users_role_ddl.sql
08/22/2012  06:59 AM             1,568 it_users_role_rollback.sql
08/28/2012  10:44 AM             2,093 service_user_ddl.sql
08/28/2012  10:44 AM             1,732 service_user_rollback.sql
              33 File(s)        160,422 bytes
               2 Dir(s)   6,569,340,928 bytes free

SQL>

Uses:

If you had a OS process you needed to kick off pre/post-implementation of your scripts, this is a good way to dot it!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s