Home » SQL & PL/SQL » SQL & PL/SQL » alternate option for IN keyword
alternate option for IN keyword [message #112633] Mon, 28 March 2005 08:07 Go to next message
rajuakula
Messages: 63
Registered: March 2005
Member
Hi,

I have a string as ('a1','b1','c1','d1',......till 3000 values)

Now I have to pass this string in the where clause of the select query as

select * from temp where id in ('a1','b1','c1','d1',.....till 3000 values)

Heard that IN keyword does not support more than 1000 values, what shouldI use instead of IN keyword.Is there a alternate approach.I am using oracle 9i.


thanks,


Re: alternate option for IN keyword [message #112635 is a reply to message #112633] Mon, 28 March 2005 08:20 Go to previous messageGo to next message
dmitry.nikiforov
Messages: 723
Registered: March 2005
Senior Member
Certainly this reference should be placed at the top
of each section... to avoid of copy-paste each time...

http://www.williamrobertson.pwp.blueyonder.co.uk/documents/comma_separated.html

Rgds.
Re: alternate option for IN keyword [message #112641 is a reply to message #112635] Mon, 28 March 2005 09:03 Go to previous messageGo to next message
rajuakula
Messages: 63
Registered: March 2005
Member
My values may contain more than 4000 characters also and also

I dont want to use create type.How can I do it in a select query without create type option.

My IN values are ('afdfdf232','fdfd5454','cvjv88df',...till 3,000)

so they may be more than 4000 characters also.

thanks
Re: alternate option for IN keyword [message #112645 is a reply to message #112641] Mon, 28 March 2005 09:21 Go to previous messageGo to next message
JSI2001
Messages: 1016
Registered: March 2005
Location: Scotland
Senior Member
Hi
I don't know if it has the same limits, but try:
select * from temp where id = any('a1','b1','c1','d1',.....till 3000 values)

I think that there is an added bonus in that IN does not use Indexes (if a column has been indexed) whereas = ANY will utilise indexes where available.

HTH
Jim
Re: alternate option for IN keyword [message #112651 is a reply to message #112645] Mon, 28 March 2005 10:17 Go to previous messageGo to next message
dmitry.nikiforov
Messages: 723
Registered: March 2005
Senior Member
Hi,

I'm sorry, but this is wrong. IN and = ANY are the same and
are just different forms of in-list operator.

"IN does not use Indexes (if a column has been indexed) whereas = ANY will utilise indexes where available".

It's not so.

SQL> select object_id from nc_params where object_id in (1000,101,8989,829389);

OBJECT_ID
----------
101
101
101
1000
1000


Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=31 Bytes=372)
1 0 INLIST ITERATOR
2 1 INDEX (RANGE SCAN) OF 'XIF11NC_PARAMS' (NON-UNIQUE) (Cos
t=3 Card=31 Bytes=372)




SQL> select object_id from nc_params where object_id = any (1000,101,8989,829389)
2 /

OBJECT_ID
----------
101
101
101
1000
1000


Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=3 Card=31 Bytes=372)
1 0 INLIST ITERATOR
2 1 INDEX (RANGE SCAN) OF 'XIF11NC_PARAMS' (NON-UNIQUE) (Cos
t=3 Card=31 Bytes=372)


Rgds.
Re: alternate option for IN keyword [message #112652 is a reply to message #112651] Mon, 28 March 2005 10:19 Go to previous messageGo to next message
JSI2001
Messages: 1016
Registered: March 2005
Location: Scotland
Senior Member
Hi
Thanks for straightening that out for me. 'preciate it.
Cheers
Jim
Re: alternate option for IN keyword [message #112678 is a reply to message #112641] Mon, 28 March 2005 12:15 Go to previous messageGo to next message
William Robertson
Messages: 1643
Registered: August 2003
Location: London, UK
Senior Member
Quote:

I don't want to use create type

Why not? These are generic types that you will be using time and time again. In fact I would be surprised if your application does not already have an 'array of VARCHAR2' collection type already defined.

Oracle already has a few such as sys.DBMS_DEBUG_VC2COLL or sys.KU$_VCNT (though of course those might change in later releases so perhaps not such a great idea).

SQL> SELECT column_value
  2  FROM   TABLE(sys.KU$_VCNT('x','y','z'));

COLUMN_VALUE
------------------------------
x
y
z

3 rows selected.

SQL> SELECT column_value
  2  FROM   TABLE(sys.DBMS_DEBUG_VC2COLL('x','y','z'))
  3  /

COLUMN_VALUE
------------------------------
x
y
z

3 rows selected.
Re: alternate option for IN keyword [message #112703 is a reply to message #112678] Mon, 28 March 2005 19:42 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
this is the old workaround:
where (col1 in ('a1', 'a2', ... 'a1000')
    or col1 in ('a1001', 'a1002', ... 'a2000')...)


I know there was a 1000 limit, but these things do change.
Previous Topic: IN keyword problem
Next Topic: How to calculate the size of table
Goto Forum:
  


Current Time: Sun Aug 03 10:24:59 CDT 2025