passing parameters for where in clause

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Valgardur
Posts: 165
Joined: Tue 24 Nov 2009 19:33

passing parameters for where in clause

Post by Valgardur » Wed 08 Nov 2017 20:33

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...

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: passing parameters for where in clause

Post by MaximG » Mon 13 Nov 2017 11:09

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_';

Post Reply