Home » SQL & PL/SQL » SQL & PL/SQL » Like in Order by (Oracle 11g)
Like in Order by [message #640031] Tue, 21 July 2015 08:29 Go to next message
Xandot
Messages: 235
Registered: January 2014
Location: India
Senior Member
Hi All,

I want to order by like '%abc%'. Please help me out.

Query:

with t as 
( select 'demo staging1 abc' a from dual
union 
select 'demo staging2 abc' a from dual
union 
select 'demo staging3 abc' a from dual
union 
select 'demo staging efg' a from dual
union 
select 'demo staging ijk' a from dual
union 
select 'demo staging lmn' a from dual)
select * from t;


Thanks,
Xandot

[Updated on: Tue, 21 July 2015 08:34]

Report message to a moderator

Re: Like in Order by [message #640033 is a reply to message #640031] Tue, 21 July 2015 08:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>I wnt to order by like '%abc%'.
what does above mean?

what is expected/desired results from your test data & why?
Re: Like in Order by [message #640034 is a reply to message #640031] Tue, 21 July 2015 08:31 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Quote:
I wnt to order by like '%abc%'.


What does that mean?
What should be the result for your data?

Re: Like in Order by [message #640035 is a reply to message #640031] Tue, 21 July 2015 08:31 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
And the expected output is?
Re: Like in Order by [message #640036 is a reply to message #640035] Tue, 21 July 2015 08:35 Go to previous messageGo to next message
Xandot
Messages: 235
Registered: January 2014
Location: India
Senior Member
Row which contains string like 'abc' should be come at top like:

Expected Output:

demo staging1 abc
demo staging2 abc
demo staging3 abc
demo staging efg
demo staging ijk
demo staging lmn
Re: Like in Order by [message #640037 is a reply to message #640036] Tue, 21 July 2015 08:39 Go to previous messageGo to next message
Michel Cadot
Messages: 68776
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

SQL> with t as
  2  ( select 'demo staging1 abc' a from dual
  3  union
  4  select 'demo staging2 abc' a from dual
  5  union
  6  select 'demo staging3 abc' a from dual
  7  union
  8  select 'demo staging efg' a from dual
  9  union
 10  select 'demo staging ijk' a from dual
 11  union
 12  select 'demo staging lmn' a from dual)
 13  select * from t
 14  order by sign(instr(a,'abc')) desc, a
 15  /
A
-----------------
demo staging1 abc
demo staging2 abc
demo staging3 abc
demo staging efg
demo staging ijk
demo staging lmn

Re: Like in Order by [message #640043 is a reply to message #640037] Tue, 21 July 2015 08:54 Go to previous messageGo to next message
Xandot
Messages: 235
Registered: January 2014
Location: India
Senior Member
Thanks a lot Michel Cadot .
Re: Like in Order by [message #640126 is a reply to message #640043] Wed, 22 July 2015 13:59 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Like is used in the where clause only.
Previous Topic: Covert unique string to unique number
Next Topic: how to clear the output data using utl_file?
Goto Forum:
  


Current Time: Thu Aug 06 22:31:41 CDT 2026