Page 1 of 1

passing parameters for where in clause

Posted: Wed 08 Nov 2017 20:33
by Valgardur
I have a SQL Query something like

select * from mytable where field in ('a', 'b' ,'c') where I need to send 'a', 'b' 'c' as a parameter. I tried a few variations, array, string, but either get no response or application execption.

How can I accomplish this?

As a temporary workaround I replaced the string in the query but not ideal solution...

Re: passing parameters for where in clause

Posted: Mon 13 Nov 2017 11:09
by MaximG
To pass values to the query 'a', 'b', 'c' you can use macros :

Code: Select all

...
OraQuery.SQL.Text: = 'select * from mytable where field in (&list)'; 
OraQuery.MacroByName('list').AsString := 'a'', ' + '''b'', ' + '''c';
or apply the parameter in the following way :

Code: Select all

OraQuery.SQL.Text := 'select * from mytable where InStr(:list, ''_''||field||''_'') > 0';
OraQuery.ParamByName('list').AsString := '_a_b_c_';