Geeks Talk

Prepare for your Next Interview




"like" keyword in oracle..

This is a discussion on "like" keyword in oracle.. within the Oracle forums, part of the Databases category; Can anyone give a example to use the "like" keyword in select query ? Because in my search page, user can search the book by different options.. (title, author, year, publisher,..) ...


Go Back   Geeks Talk > Databases > Oracle

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-21-2006
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 76 Times in 64 Posts
psuresh1982 will become famous soon enough
"like" keyword in oracle..

Can anyone give a example to use the "like" keyword in select query ?

Because in my search page, user can search the book by different options..
(title, author, year, publisher,..) I am using textbox for all the fields...so user can type any one or more fields and then search for the book....Here i want to use the select query with like keyword...

-------------------
suresh
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-21-2006
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 28 Times in 27 Posts
kalayama is on a distinguished road
Re: "like" keyword in oracle..

select * from TABLE where TABLE.key like '%search string%'

is the general form. If you give me your table structure and keys you need and I can write the query for you.

Cheers,
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Reply With Quote
  #3 (permalink)  
Old 12-21-2006
Expert Member
 
Join Date: Jun 2006
Location: India
Posts: 411
Thanks: 15
Thanked 33 Times in 25 Posts
jamesravid is on a distinguished road
Re: "like" keyword in oracle..

Suresh,

like function is meant for diff purpose. It is used to search for a specific string/character.

select * from emp where ename like 'K%';

this query returns all the records whose employee name start with 'K'

The wild card symbols can be used along with ur search string are
% - for zero or more characters
_ - single character search.

If my understanding is right like alone is not sufficient....

just try this in ur where clause

(input_title is null
or
input_title = title
)
and
(input_author is null
or
input_author = author
)...
__________________
Cheers,
:) James:)
Reply With Quote
  #4 (permalink)  
Old 12-21-2006
Expert Member
 
Join Date: Sep 2006
Location: Bengalooru (Formerly called Bangalore), India
Posts: 486
Thanks: 2
Thanked 28 Times in 27 Posts
kalayama is on a distinguished road
Re: "like" keyword in oracle..

No James. I think like is what he needs. Whe we search for anything, we must use like clause. Fore example, let use assume there is an author named James Ravid. The user just searches for James (No RAVID) don't you think the system should list this author even though a part of his name was specified?

According to
(input_author is null
or
input_author = author
), nothing will be output! (For the example above)

I think Surech is right in using like clause.
Suresh, what exactly you have in mind?

Cheers,
Kalayama
__________________
[COLOR="Blue"][SIZE="2"]"If you are not living on the edge of your life, you are wasting space"[/SIZE][/COLOR]

Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"

Last edited by kalayama : 12-21-2006 at 04:39 AM.
Reply With Quote
  #5 (permalink)  
Old 12-21-2006
Expert Member
 
Join Date: Jun 2006
Location: India
Posts: 411
Thanks: 15
Thanked 33 Times in 25 Posts
jamesravid is on a distinguished road
Re: "like" keyword in oracle..

kalayama i understand his question in diff way.

In a search page, user can search the book by different options..
(title, author, year, publisher,..) and all of them are optional. User might enter them or leave them unentered.

so your query get either search string or null for each parameters...in such a case your where clause has to get generated dynamically based on the inputs given by the user. For instance user enter search string only for title and author. So ur query's where clause should have two conditions one for title and other for author.

This case the where clause would be like this

title like nvl(input_title, title)
and
author like nvl(input_author, author)
and
year like nvl(input_year,year)
and
publisher like nvl(input_publisher,publisher)

variables start with 'input_' inputs entered by the user in the search screen. And others are column names in the table.
The above query fetches all the records satisfying ur selection criterion irrespective of number of search options the used entered.

let me explain with an examle,
user entered Vinci in title and Dan in author screen and did not fill other text boxes.
Now,
title like nvl(input_title, title)
becomes title like input_title as input_title is not null

author like nvl(input_author, author)
becomes author like input_author

and

year like nvl(input_year,year)
becomes year like year as input_year is null and this returns 'True' to all the records

publisher like nvl(input_publisher,publisher)
becomes publisher like publisher and this condition is true to all the records.

so this query equivalent to

title like nvl(input_title, title) and
author like nvl(input_author, author)

Hence you achieve what you required in a Static query.

At first I though he has to match the exact term entered in the search screen so i said like is not required.

I will be very happy if this post helps Suresh.
__________________
Cheers,
:) James:)
Reply With Quote
  #6 (permalink)  
Old 12-22-2006
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 76 Times in 64 Posts
psuresh1982 will become famous soon enough
Re: "like" keyword in oracle..

Both Kalayam and James,

Thanks for your valuable reply ...... It's very useful to me.........

Is other any technique to solve this problem ?

------------
suresh
Reply With Quote
Reply

  Geeks Talk > Databases > Oracle


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Remove an application without "uninstall/Remove" option anushya Windows 7 10-18-2008 02:42 PM
Filling "Date Creation" field with the current day Lokesh M Test Director 1 02-27-2008 08:39 AM
does anybody explain the "novus testing framework?" pputturi Testing Frameworks 2 02-20-2008 02:30 AM
India is not a country of 100 million... Quot Mukesh Ambani Lokesh M Geeks Lounge 0 10-10-2006 04:26 AM
McAfee launches "TOTAL PROTECTION" Beta Lokesh M Geeks Lounge 0 06-22-2006 08:44 AM


All times are GMT -4. The time now is 06:21 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved