Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Will an SQL where statement with an OR clause work?

Re: Will an SQL where statement with an OR clause work?

From: Hans Forbrich <forbrich_at_yahoo.net>
Date: Fri, 06 Aug 2004 19:53:25 GMT
Message-ID: <VkRQc.38724$hw6.34272@edtnps84>


G wrote:

> I'm hitting an Oracle 9.2 DB. Will an SQL where statement with an OR
> clause properly work?
>
> For example:
>
> Select * from mytable where mfield = corn or myfield = oats
>
> I would also appreciate any help with the syntax
>
> Thanks.
>
> G

Yes, it will work 'properly'. However, your interpretation of 'properly' may not be the same as the database's definition <g>

SELECT *
  FROM mytable
 WHERE mfield = 'corn'

    OR myfield = 'oats'

will select all rows where column _mfield_ contains lower case 'oats' and all rows where column _myfield_ contains lower case 'corn'

Comments:
- character data literals must be in single-quotes and are case sensitive. - use functions as described in the SQL Language Reference manual

   (manuals are found at http://docs.oracle.com) - consider 'IN' or 'EXISTS' for lists

    myfield IN ('CORN', 'OATS')

- use OR when selecting from different columns
- use parenthesis '()' to prioritize and group 
- recognize that OR is generally slower than AND
- create some sort of statement layout standard (see my example)

    occasionally helps identify typos

O'Reilly's book 'Mastering Oracle SQL' is a great, and inexpensive, treatise on the language. It shows so many tricks that the average programmer gets 100% ROI withing a few weeks.

/Hans Received on Fri Aug 06 2004 - 14:53:25 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US