oracle - Issues when user input data in sql command -


i have batch files when run calls sql file. sql file prompts user input data store in myperiod( accepts date input ).the output of sql file csv file. here code sql file:

prompt enter period accept myperiod prompt 'period: '  set linesize 500 feedback off trimspool on termout off head off pagesize 0 term off  spool e:\abc\test\file1_&myperiod.csv  select account || ',' || membername || ',' || group || ',' || future1  actual_v@uat1_test key=21 , period_name= '&myperiod' ; spool off exit 

my queries :

  1. when run , file gets generated in location e:\abc\test name file1_12-2012csv.lst. want csv file . if hard code file name(replace &myperiod test) file1_test.csv gets generated perfectly.why code not able create file name user has input..?

  2. the output of creates csv file , retrieves accounts db prints 2 line @ top. new query , old query. how redefine code, gets remove automatically.

appreciate guys.

substitution variables optionally terminated period separate them characters follow. if want use 1 in string well, have add termination explicitly:

spool e:\abc\test\file1_&myperiod..csv 

for 2 lines issue, add set verify off; @ moment set on (by default) shows old , new value of substitution variables use.


the way know date file name put substitution variable first:

set termout off column x_run_dt new_value y_run_dt select to_char(sysdate, 'yyyymmddhh24miss') x_run_dt dual; set termout on spool e:\abc\test\file1_&myperiod._&y_run_dt..csv 

the new_value clause lets create substitution variable, &y_run_dt in case, value queried column, x_run_dt. wrapping select generates value between set termout clauses hides normal output, when run script.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -