Unix Technical Forum

Need help for IN operator in Oracle

This is a discussion on Need help for IN operator in Oracle within the Oracle Miscellaneous forums, part of the Oracle Database category; --> Hi, I need some help in using the IN operator with Oracle 9i. The issue is I will get ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 11:57 AM
sangu_rao@yahoo.co.in
 
Posts: n/a
Default Need help for IN operator in Oracle

Hi,
I need some help in using the IN operator with Oracle 9i. The issue is
I will get a data in variable (Lets say the variable is "A") with this
below foramt

'var1','var2','var3'


The word is a combination of 3 words where each word enclosed in a
single quotes and seperated by a comma operator. This is how i will get
the string to my SP. Now i have to seach a table to see whether the
column content of a table matches with the any of the words ( i.e.
var1, var2 or var3) in the above string. Then my query looks like

SELECT * FROM TEMP WEHRE Col IN A;

The above query will treat the string 'var1','var2','var3' as a one
single string not as a combination of words. So my requirement won't be
solved with the above query.

I am able to retireve the data correctly in SQL Server by using the
late binding concept. The code for that

declare @b varchar(20)
declare @sql nvarchar(200)
set @b = '''var1'',''var2'',''var3'''
set @sql = 'select * from temp where a in ('+ @b +')'
exec sp_executesql @sql

My temp table contains 2 values : var1 and var2

The above query returns me var1 and var2 from Temp table.

Any idea how can get the same effect in Oracle 9i. I am very much
thankfull for your suggestion as we are nearing to release it is very
urgent for me.

Thanks in advance
Rao

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 11:57 AM
sybrandb
 
Posts: n/a
Default Re: Need help for IN operator in Oracle



On Dec 14, 2:09 pm, sangu_...@yahoo.co.in wrote:
> Hi,
> I need some help in using the IN operator with Oracle 9i. The issue is
> I will get a data in variable (Lets say the variable is "A") with this
> below foramt
>
> 'var1','var2','var3'
>
> The word is a combination of 3 words where each word enclosed in a
> single quotes and seperated by a comma operator. This is how i will get
> the string to my SP. Now i have to seach a table to see whether the
> column content of a table matches with the any of the words ( i.e.
> var1, var2 or var3) in the above string. Then my query looks like
>
> SELECT * FROM TEMP WEHRE Col IN A;
>
> The above query will treat the string 'var1','var2','var3' as a one
> single string not as a combination of words. So my requirement won't be
> solved with the above query.
>
> I am able to retireve the data correctly in SQL Server by using the
> late binding concept. The code for that
>
> declare @b varchar(20)
> declare @sql nvarchar(200)
> set @b = '''var1'',''var2'',''var3'''
> set @sql = 'select * from temp where a in ('+ @b +')'
> exec sp_executesql @sql
>
> My temp table contains 2 values : var1 and var2
>
> The above query returns me var1 and var2 from Temp table.
>
> Any idea how can get the same effect in Oracle 9i. I am very much
> thankfull for your suggestion as we are nearing to release it is very
> urgent for me.
>
> Thanks in advance
> Rao


http://asktom.oracle.com, search for 'dynamic in list'.
The above code is just another example why sqlserver is utter crap, and
people brainwashed by sqlserver should stop 'porting' their bad habits
to Oracle.
The approach above is utterly unscalable in Oracle.

--
Sybrand Bakker
Senior Oracle DBA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 11:57 AM
DA Morgan
 
Posts: n/a
Default Re: Need help for IN operator in Oracle

sangu_rao@yahoo.co.in wrote:
> Hi,
> I need some help in using the IN operator with Oracle 9i. The issue is
> I will get a data in variable (Lets say the variable is "A") with this
> below foramt
>
> 'var1','var2','var3'
>
>
> The word is a combination of 3 words where each word enclosed in a
> single quotes and seperated by a comma operator. This is how i will get
> the string to my SP. Now i have to seach a table to see whether the
> column content of a table matches with the any of the words ( i.e.
> var1, var2 or var3) in the above string. Then my query looks like
>
> SELECT * FROM TEMP WEHRE Col IN A;
>
> The above query will treat the string 'var1','var2','var3' as a one
> single string not as a combination of words. So my requirement won't be
> solved with the above query.
>
> I am able to retireve the data correctly in SQL Server by using the
> late binding concept. The code for that
>
> declare @b varchar(20)
> declare @sql nvarchar(200)
> set @b = '''var1'',''var2'',''var3'''
> set @sql = 'select * from temp where a in ('+ @b +')'
> exec sp_executesql @sql
>
> My temp table contains 2 values : var1 and var2
>
> The above query returns me var1 and var2 from Temp table.
>
> Any idea how can get the same effect in Oracle 9i. I am very much
> thankfull for your suggestion as we are nearing to release it is very
> urgent for me.
>
> Thanks in advance
> Rao


Go to Morgan's Library at www.psoug.org
click on Conditions
scroll down to COMPLEX IN DEMO.
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 11:57 AM
David Portas
 
Posts: n/a
Default Re: Need help for IN operator in Oracle

sybrandb wrote:
>
> http://asktom.oracle.com, search for 'dynamic in list'.
> The above code is just another example why sqlserver is utter crap


No. It's an example of a lame piece of code written by a SQL Server
developer who probably didn't know any better. The same poor solution
is no better or worse in Oracle than in SQL Server.

> people brainwashed by sqlserver should stop 'porting' their bad habits
> to Oracle.


I agree.

--
David Portas

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-08-2008, 11:57 AM
Thorsten Kettner
 
Posts: n/a
Default Re: Need help for IN operator in Oracle

The IN clause tells you if a value is in a list of elements.
'var1','var2','var3' is not a list of elements, but a string. So what
you actually want to know is if a value is a substring of that string:

SELECT * FROM TEMP
WHERE instr(:A,''''||Col||'''') > 0

-----------------------------------------------------

sangu_rao@yahoo.co.in wrote:

> Hi,
> I need some help in using the IN operator with Oracle 9i. The issue is
> I will get a data in variable (Lets say the variable is "A") with this
> below foramt
>
> 'var1','var2','var3'
>
>
> The word is a combination of 3 words where each word enclosed in a
> single quotes and seperated by a comma operator. This is how i will get
> the string to my SP. Now i have to seach a table to see whether the
> column content of a table matches with the any of the words ( i.e.
> var1, var2 or var3) in the above string. Then my query looks like
>
> SELECT * FROM TEMP WEHRE Col IN A;
>
> The above query will treat the string 'var1','var2','var3' as a one
> single string not as a combination of words. So my requirement won't be
> solved with the above query.

[snip]

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:45 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com