Home » SQL & PL/SQL » SQL & PL/SQL » alternate to like operator (oracle 10g)
alternate to like operator [message #579801] Fri, 15 March 2013 08:40 Go to next message
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

Hi All,

Any alternate to the following query.
select * from emp where ename like upper(NVL('%mi%',ename));


Basically I want to search based on string or null.Please help me.

Regards,
Nathan
Re: alternate to like operator [message #579802 is a reply to message #579801] Fri, 15 March 2013 08:44 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

http://www.oracle.com/technetwork/issue-archive/2010/10-sep/o50asktom-165477.html

Regards
Michel
Re: alternate to like operator [message #579803 is a reply to message #579802] Fri, 15 March 2013 08:57 Go to previous messageGo to next message
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

Thanks Sir,for nice link and I have one more doubt how to handle when a string is passed like *mi* or *mi or mi*.

Regards,
Nathan
Re: alternate to like operator [message #579804 is a reply to message #579801] Fri, 15 March 2013 08:58 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
The query is identical to
select * from emp where ename like '%MI%';

isn't it ?

[Updated on: Fri, 15 March 2013 08:58]

Report message to a moderator

Re: alternate to like operator [message #579807 is a reply to message #579804] Fri, 15 March 2013 09:23 Go to previous messageGo to next message
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

No _Jum,

for MI* select * from emp where ename like 'MI%';
for *MI* select * from emp where ename like '%MI%';
for *MI select * from emp where ename like '%MI';
for *M*I* select * from emp where ename like '%M%I%';


Regards,
Nathan
Re: alternate to like operator [message #579808 is a reply to message #579807] Fri, 15 March 2013 09:41 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
Ok it's friday, late afternoon - but I have no idea what you are talking about Shocked
Re: alternate to like operator [message #579809 is a reply to message #579808] Fri, 15 March 2013 09:45 Go to previous messageGo to next message
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

Thanks All..I changed to code like but still it's using like operator decreasing the performance.

PROCEDURE get_emp_list(
    p_ename IN VARCHAR2,
    rec_emp_list OUT sys_refcursor)
IS
  l_main_str VARCHAR2(2000):='SELECT * FROM EMP';
  l_str VARCHAR2(200);
  l_ename varchar2(20);
BEGIN
  IF p_ename   IS NOT NULL THEN
    l_ename    :=REPLACE(p_ename,'*','%');
    l_str      :=' where upper(ename) like upper('''||l_ename||''')';
    l_main_str :=l_main_str||l_str;
  END IF;
  OPEN rec_emp_list FOR l_main_str;
  dbms_output.put_line(l_main_str);
END get_emp_list;

Regards,
Nathan

[Updated on: Fri, 15 March 2013 09:46]

Report message to a moderator

Re: alternate to like operator [message #579810 is a reply to message #579809] Fri, 15 March 2013 10:15 Go to previous messageGo to next message
_jum
Messages: 577
Registered: February 2008
Senior Member
What has this procedure to do with your question?
Quote:
select * from emp where ename like upper(NVL('%mi%',ename));

BTW the whole design is decreasing the performance, not the LIKE operator.
Why do you use a PROCEDURE with a SYS_REFCURSOR as argument to do thinks, that can be done with pure SQL.
I can't see any reason in your post.
Re: alternate to like operator [message #579813 is a reply to message #579809] Fri, 15 March 2013 11:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
but still it's using like operator decreasing the performance.


If you have joker characters then you have to use LIKE.
The other solution is to use TEXT/CONTEXT option (see our "Text & interMedia" forum for examples).

Regards
Michel
Re: alternate to like operator [message #579814 is a reply to message #579810] Fri, 15 March 2013 11:31 Go to previous messageGo to next message
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

Actually _jum,The procedure is going to be called by java application.And what the cursor will return based on they will be showing there.They are not allowing direct select statement there.And it's not related with the question from what I started.I thought of using that but I changed the requirement.

And Michel,I never used Text.Why it is separate from oracle.What is the conditions to fullfill to use it.

Regards,
Nathan

[Updated on: Fri, 15 March 2013 11:35]

Report message to a moderator

Re: alternate to like operator [message #579815 is a reply to message #579814] Fri, 15 March 2013 11:38 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It is unreasonable to expect wildcard selections to be fast; since wildcard can prevent index from being used.
You have to choose between accepting the performance as it exists or change the design to better accommodate faster access.
Re: alternate to like operator [message #579816 is a reply to message #579814] Fri, 15 March 2013 12:12 Go to previous message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
It is an option that extends SQL.
As I said, have a look at the forum for examples.

Regards
Michel
Previous Topic: Melting down rows (merged)
Next Topic: Alternative of WM_CONCAT
Goto Forum:
  


Current Time: Sun Aug 10 00:25:19 CDT 2025