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: G <bay_dar_at_yahoo.com>
Date: 9 Aug 2004 05:23:58 -0700
Message-ID: <cad04083.0408090423.1ab92d0f@posting.google.com>


Thanks for the help and the book recomendation, and yes the or statement works as I expected. Is that book good for beginners as well as advance users? I write programs in Java/.Net/ASP that hit Oracle DBs and would like a good book with sound examples.

G

Hans Forbrich <forbrich_at_yahoo.net> wrote in message news:<VkRQc.38724$hw6.34272_at_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 Mon Aug 09 2004 - 07:23:58 CDT

Original text of this message

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