Home » SQL & PL/SQL » SQL & PL/SQL » Sql Query (Oracle 10g , Windows XP)
Sql Query [message #311965] Mon, 07 April 2008 09:57 Go to next message
mansoorakthar
Messages: 4
Registered: April 2008
Junior Member
Hi All

I have a column Country in the database table. It has a value United States Of America.

I need to wirte a SQL query as follows

Select * from region where country = ?

The placeholder ? can be one of the following

United
States
of
America
United States Of America

I should be able to get the entire row matching the value United States Of America for the above values.

Thank You
Mansoor
Re: Sql Query [message #311966 is a reply to message #311965] Mon, 07 April 2008 10:04 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
SQL Experts
Advanced Oracle SQL questions - Complex queries, DML and DDL statements. Newbies should not post to this forum!
Re: Sql Query [message #311967 is a reply to message #311965] Mon, 07 April 2008 10:05 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
This is NOT an expert question. Lookup the syntax for Wildcards and the LIKE operator in the Oracle documentation.
Re: Sql Query [message #311980 is a reply to message #311965] Mon, 07 April 2008 10:52 Go to previous messageGo to next message
mansoorakthar
Messages: 4
Registered: April 2008
Junior Member
Hi

Can u give me the query for the above operation.....



Thank You
Mansoor.
Re: Sql Query [message #311983 is a reply to message #311980] Mon, 07 April 2008 10:59 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Welcome to OraFAQ.

Here at OraFAQ, we do not believe in giving people simple queries. We try to make you learn how to write those yourself.
So, show us what you tried, where you went wrong. While you're at it, take a look at the sticky, a link to it can be found in the yellow bar at the top of the forum-page.
Re: Sql Query [message #311985 is a reply to message #311965] Mon, 07 April 2008 11:09 Go to previous messageGo to next message
mansoorakthar
Messages: 4
Registered: April 2008
Junior Member
Hi All

The query cna be written as

Select * from region where country like 'United%'

or

Select * from region where country like '%States%'

or

Select * from region where country like '%America'

But i need to write a single query which fits all the criteria mentioned in the question.







Thank You
Mansoor
Re: Sql Query [message #311987 is a reply to message #311965] Mon, 07 April 2008 11:15 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
That looks good to me.
use multiple LIKE joined by OR
Re: Sql Query [message #311991 is a reply to message #311965] Mon, 07 April 2008 11:47 Go to previous messageGo to next message
mansoorakthar
Messages: 4
Registered: April 2008
Junior Member
The column has values like

United States of America
United Kingdom
United Arab Emirates

So if I select United then all the three countries should be be present in the resultset

If i select States then only United States of America should be present in the resultset.

Re: Sql Query [message #311996 is a reply to message #311991] Mon, 07 April 2008 12:03 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
So use AND, OR, NOT and so on to express your conditions.

Regards
Michel
Re: Sql Query [message #312027 is a reply to message #311965] Mon, 07 April 2008 19:00 Go to previous messageGo to next message
Kevin Meade
Messages: 2101
Registered: December 1999
Location: Connecticut USA
Senior Member
go to your sqlplus manual (book or online) and read up on INSTR function, or just google ORACLE INSTR.

Once you figure this out, sit down and read about sql functions in Oracle. Boring, but ever so needed by you at the moment. I did it when I first started out 23 years ago with Oracle. Better hury, they keep making the manual set bigger every year.

UNITED
STATES
OF
AMERICA

UNITED STATES
STATES UNITED

what should you get if two words are supplied?

Good luck, Kevin
Re: Sql Query [message #312043 is a reply to message #311965] Mon, 07 April 2008 20:11 Go to previous messageGo to next message
bibsdash
Messages: 47
Registered: April 2008
Member
You should try this as well

Select * from region where country like 'Union%States%America%'
Re: Sql Query [message #312046 is a reply to message #311965] Mon, 07 April 2008 20:15 Go to previous messageGo to next message
BlackSwan
Messages: 25036
Registered: January 2009
Location: SoCal
Senior Member
>Select * from region where country like 'Union%States%America%'

No rows returned


Keep in mind that 'Case Matters'!
Re: Sql Query [message #312049 is a reply to message #312046] Mon, 07 April 2008 20:19 Go to previous message
bibsdash
Messages: 47
Registered: April 2008
Member
Good catch,anacedent,

Yes, case is important above all.
Look into that too.

Previous Topic: error handling
Next Topic: Is tuning needed for this SQL ?
Goto Forum:
  


Current Time: Sun Dec 04 10:59:32 CST 2016

Total time taken to generate the page: 0.11442 seconds