There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
DOS/PDA/Other
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > DOS/PDA/Other >
batch file to write to a text file reading from the database


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
santhoshs79's Avatar
Junior Member with 1 posts.
 
Join Date: Jul 2004
Experience: Intermediate
22-Jul-2004, 03:10 PM #1
batch file to write to a text file reading from the database
Hi all,
Here is a problem I am facing .I have to admit, I am not an expert in batch file scripting.

The database is oracle, and the table is something like this.

jobname date inputfile
________________________________
job1 mm-dd-yy input1
job2 mm-dd-yy input2
...... ............ ........


my batch file has to write a text file in the following format(jobfile.txt)

****************************************************

(jobname)

input file = (inputf filename)
......
......
....

******************************************************

The criteria is system date, i.e the bat file has to get the system date, and run a query, get the roes and ten write a text file, there might be any number of jobs for a particular date, and each job has one input file for a particular date.

I tried a clumsy method......The query result is first stored as a csv file, and then from this file I tried to write the required text file, but I am facing problems in the latter part. escpecially when I am reading the data from csv to write to the jobfile.txt.


here is the code

for /f "TOKENS=2* DELIMS=/ " %%A IN ('DATE/t') DO SET MM=%%A
for /f "TOKENS=3* DELIMS=/ " %%B IN ('DATE/t') DO SET DD=%%B
for /f "TOKENS=4* DELIMS=/ " %%C IN ('DATE/t') DO SET YYYY=%%C
set mydate=%MM%/%DD%/%YYYY%%

rem echo set feedback off >>%0.txt
echo set flush off >>%0.txt
echo set heading off >>%0.txt
echo set headsep off >>%0.txt
echo set timing off >>%0.txt
echo set pagesize 0 >>%0.txt
echo set recsep off >>%0.txt
echo set termout off >>%0.txt
echo set trimspool on >>%0.txt
echo set trimout on >>%0.txt
echo set verify off >>%0.txt
echo set wrap off >>%0.txt
echo set colsep ',' >>%0.txt
rem echo set space 0 >>%0.txt
echo set pause off >>%0.txt
echo spool select.txt >>%0.txt
echo select trip(jobname),trim(inputfile) from job_table;>>%0.txt
echo spool off >>%0.txt
echo set feed on >>%0.txt

echo connect user/pword@orcl_connect_string >%0.txt
sqlplus /nolog @%0.txt
echo exit 8; >>%0.txt

del %0.txt

REM I am facing problems here.....the only the last line is getting written,....

for /f "tokens=1-2 delims=," %%a in (..\select.txt) do (set job=%%a set input=%%b
echo %job% >> jobfile.txt
echo InputFile=%input% >> jobfile.txt
)
HKOldGuy's Avatar
Junior Member with 19 posts.
 
Join Date: Jul 2003
Location: Hong Kong
26-Jul-2004, 10:57 PM #2
This simplest way is Using Oracle's UTL_FILE package and PL/SQL
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:56 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.