2

I have a batch file which runs multiple sql files and passes parameters to them. The input parameters are stored in a txt file which is read by batch file.

I am trying to pass varchar values to IN clause of SQL.

For e.g.

In my input file i this entry

var1="'tommy','jim'"

In Batch file

<code to read file , assuming %1 has the var1 value>
set param=%~1

sqlplus %DBCONN% @%programFolder%\test.sql %param%

test.sql (name is varchar2)

select * from table where name in (&1);

This gives error, saying invalid number as it tries to run

select * from table where name in (tommy);


If i echo right before the sql stmt, its displays 'tommy','jim' but in sql its removing jim and the single quotes ...

Please help!


Now i edited entry in Input file as var1="'''tommy''','''jim'''"

it goes as select * from table where name in ('tommy');

But it truncates the second value

Any clue how to include comma ??

1
  • Can you share more details on how you fixed this? I have following code in place //read input file- ('pdf','csv','jpeg','png') set /P ALLOWED_TYPES=<Allowed_TYPEs.txt sqlplus %connection_DB% @SQL_CMD.txt %ALLOWED_TYPES% Commented Jun 18, 2020 at 9:54

2 Answers 2

1

Finally found a way

input file - var1=('tommy','jim')

Remove the braces from the sql file select * from table where name in &1;

This works , i have no idea why was taking a comma was such an issue, there should have been some way to pass the comma ! If anyone finds out please let me know.

Thanks

Sign up to request clarification or add additional context in comments.

Comments

0

The tilde (~) strips quotes from the variable.

Try using var1='tommy','jim' in your input file and set param=%1 in your batch script.

1 Comment

If i remove tilde, the param is separated in batch itself. echo %var1% before the sql displays only 'tommy'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.