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

Home -> Community -> Usenet -> c.d.o.server -> Re: SQL STATEMENT

Re: SQL STATEMENT

From: <dejaron_at_my-dejanews.com>
Date: Tue, 01 Sep 1998 17:37:02 GMT
Message-ID: <6shbbu$tqs$1@nnrp1.dejanews.com>


Couldn't you do something like this...

> >Select field1,field2,field3
> >from mytable
> >where field1 like '%'||myinput1||'%' and
> > field2 like '%'||myinput2||'%' and
> > field3 like '%'||myinput3||'%';
> >------------------------------------------

If the input is null, you'll get all values for the corresponding field. If you enter something, you'll get only that value.

It's probably not the most efficient way, but I think it'll work.

Ron.

In article <35eb5eb4.164778969_at_news.earthlink.net>,   beverett_at_remove_this.usa.net (Brian Everett) wrote:
>
> Thanks a lot people. One of the first things I tried was the NVL
> function but it doesn't always work. It sounded good to me a first.
>
> Thanks again.
>
> On Sat, 29 Aug 1998 13:09:26 GMT, Mujeeb_ur_Rehman_at_hotmail.com wrote:
>
> >Hi :)
> >
> >The function which will help u out is NVL. Do like this.
> >
> >------------------------------------------
> >Select field1,field2,field3
> >from mytable
> >where field1 = nvl(myinput1,field1) and
> > field2 = nvl(myinput2,field2) and
> > field3 = nvl(myinput3,field3)
> >------------------------------------------
> >
> >Now what will happen is that when the input vairable is null then field will
> >be matched with field and if the input vairable is not null then field will
> >be matched with input varaible.
> >
> >Hope this gets u started.
> >
>
>===============================================================================
> >In article <35e4b4d6.88482811_at_news.earthlink.net>,
> > beverett_at_remove_this.usa.net (Brian Everett) wrote:
> >>
> >> Greetings All.
> >>
> >> I have a table of zip codes and a web form that attempts to query
> >> the table based on three fields on the form. The user can provide as
> >> little or as much information in these three fields as they would
> >> like. Problem: I do not know in advance which fields will be entered.
> >> How do I structure the select statement (cursor (Oracle)) so that
> >> fields not entered will not restrict the returned records but field
> >> which are entered will restrict the output. I've tried a number of
> >> approaches and some work well but not in every scenario. Since
> >> there are three fields then there are 8 possible ways inputs can be
> >> anticipated. I hope I haven't confused anyone. I used to do something
> >> in Access like this...
> >> ...where myfield = myinput or myfield is null;
> >>
> >> Oracle needs something else it would appear.
> >>
> >> Thanks
> >> Brian
> >>
> >> Good Luck! Brian_RestonVA
> >>
> >>
> >
> >-----== Posted via Deja News, The Leader in Internet Discussion ==-----
> >http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
>
> Good Luck! Brian_RestonVA
>
>

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum Received on Tue Sep 01 1998 - 12:37:02 CDT

Original text of this message

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