This is a DOS batch file that will be run at the DOS prompt. You must supply the user, password, and the SQL query name you wish to run. For example:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvbK7JFW5_rpMtq3zOeDokxHR4O289s9n5KkhP4PCsuS2Qc7yPOYGVYz37U5HnrJEtJtEo0MFd_etd5pTxb7RwEhFPI90ifDUGQb5B72aDibJjXz3coaD8vGAVhhZTKYzlATLiaM2ybm7d/s400/dos1.png)
Since the SQL query must have an 'EXIT' statement at the end, I've actually had this batch file call a two-line query that calls the query you requested, and then exits. This batch file assumes that all your code is in a directory called 'Data', and that the output of your query can be displayed in Notepad, and that the spool file name matches the query name with an 'TXT' extension.
SqlFromDos.Bat |
---|
Rem -+--------------------------------------- Rem -| Turn off the display Rem -+---------------------------------------
@Echo Off
Rem -+--------------------------------------- Rem -| Pick up the variables typed Rem -| i.e., SqlFromDos Scott Tiger Emptest Rem -+---------------------------------------
Set User=%1 Set Pass=%2 Set Query=%3
Rem -+--------------------------------------- Rem -| Apply the variables to the login Rem -+---------------------------------------
Sqlplus %User%/%Pass% @C:\Data\RunFromDos %Query%
Rem -+--------------------------------------- Rem -| When SQL*Plus is done, return to Rem -| DOS, clear the screen, and open Rem -| Notepad to view the report Rem -+---------------------------------------
cls Notepad C:\Data\%Query%.txt |
This is called by SqlFromDos.Bat;
This is called by RunFromDos.Sql:
EmpTest.Sql |
Set Echo Off Linesize 200 Pagesize 60 Trimspool On Spool Emptest.Txt Select * From Emp; Spool Off |
No comments:
Post a Comment