Additional
dbCAP
AnyDAC
ThinDAC
NCOCI8
Topic: array typed parameter
array typed parameter
Posted: 2003/06/26 07:12
 
How can I pass an array typed parameter to a TOCIQuery.
I wish to use it like below:
Select *
from invoices i
where i.company_id in (aram)

i.company_id is number typed column and the parameter is:
ociquery1.params[0].AsString:='101,102,105'
There is no errors, but the result is always an empty set.
RE: array typed parameter
Posted: 2003/06/26 09:17
 
If your list has constant number of items, use this SQL:
ciquery1.SQL.Text:='Select * from invoices i where i.company_id in (1, 2, 3)';
ciquery1.parambyname('p1').Value:=101;
ciquery1.parambyname('p2').Value:=102;
ciquery1.parambyname('p3').Value:=105;
In most cases this approach is unacceptable because of variable number of items in list.
In that case use macro
ciquery1.SQL.Text:='Select * from invoices i where i.company_id in (&List)';
ciquery1.macrobyname('List').AsString:='101,102,105';
Bad thing is that your operator wil be parsed every time you run it with different value of &List. &List must never be empty, or you will get OCI error.
This best apporoach (but not always usable) is to use 'where i.company_id in (select ...)' construction.
For example: companies 101,102,105 are all the companies located in city with city_id=33. In that case your SQL will be:
ciquery1.SQL.Text:='Select * from invoices i where i.company_id in (select company_id from company where city_id=:city_id)';
ciquery1.parambyname('city_id').Value:=33;

RE: array typed parameter
Posted: 2003/06/26 09:56
 
Thanks Mur!

I found an another solution:
select *
from invoices i
where aram like '%'||to_char(i.company_id)||'%'

ociquery1.params[0].AsString:='101,102,105'

and it works!!
RE: array typed parameter
Posted: 2003/06/26 09:59
 
Thanks Mur!
I found an another solution:
select * from invoices i
where aram like '%'||to_char(i.company_id)||'%'
ociquery.params[0].value='101,102,105'
and it works