SunQuest
           Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old June 24th, 2004, 12:15 PM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
Question Selecting All Items When Variable is Null

I am writing a script which recieves inquiry values from a form and then executes based on the information. In one category, I am providing a query for state, where the user can select a specific state to search or can select "ALL STATES" where the query checks all accounts with any state. Being new to the whole Oracle thing, I was wondering how I can get this done. I have heard that using wildcards could help me out, but I am still lost.

Here is my inquiry code where all variables named search_+something are the user defined parameters.

OPEN output_cur FOR
SELECT
e_mail,
pat_firstname,
pat_lastname
FROM
ops_arw.member_pin M,
ops_arw.subscriber S,
ops_arw.address A
WHERE
A.CITY = search_CITY AND
A.ZIP_CODE = search_ZIP_CODE AND
A.STATE = search_STATE AND
M.EMAIL_PREFERENCE = search_EMAIL_PREF AND
M.SRV_EMAIL_PREFERENCE = search_SRV_PREF AND
S.EFF_DATE = search_EFF_DATE AND
S.CERT_NO = M.CERT_NO AND
S.CERT_NO = A.CERT_NO AND
trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) < MAX_AGE AND
trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) > MIN_AGE;

Thanks for the help.

Reply With Quote
  #2  
Old June 24th, 2004, 01:25 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
It looks like you are using PL/SQL. Note that that comment block "/* .. */" can be in the middle of a SQL statement and not hurt anything.

try something like this:
Code:
IF search_state = 'ALL_STATES'
THEN 
        OPEN output_cur FOR
        SELECT
           e_mail,
           pat_firstname,
           pat_lastname
        FROM 
           ops_arw.member_pin M,
           ops_arw.subscriber S,
           ops_arw.address A
        WHERE
           A.CITY = search_CITY AND
           A.ZIP_CODE = search_ZIP_CODE AND
           /* I removed this --  A.STATE = search_STATE AND */
           M.EMAIL_PREFERENCE = search_EMAIL_PREF AND
           M.SRV_EMAIL_PREFERENCE = search_SRV_PREF AND
           S.EFF_DATE = search_EFF_DATE AND
           S.CERT_NO = M.CERT_NO AND
           S.CERT_NO = A.CERT_NO AND
           trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) < MAX_AGE AND
           trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) > MIN_AGE;
ELSE
        OPEN output_cur FOR
        SELECT
           e_mail,
           pat_firstname,
           pat_lastname
        FROM 
           ops_arw.member_pin M,
           ops_arw.subscriber S,
           ops_arw.address A
        WHERE
           A.CITY = search_CITY AND
           A.ZIP_CODE = search_ZIP_CODE AND
           A.STATE = search_STATE AND
           M.EMAIL_PREFERENCE = search_EMAIL_PREF AND
           M.SRV_EMAIL_PREFERENCE = search_SRV_PREF AND
           S.EFF_DATE = search_EFF_DATE AND
           S.CERT_NO = M.CERT_NO AND
           S.CERT_NO = A.CERT_NO AND
           trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) < MAX_AGE AND
           trunc(months_between(SYSDATE,M.MEM_DOB)/12,0) > MIN_AGE;

END IF;

Reply With Quote
  #3  
Old June 24th, 2004, 01:31 PM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
I can't do that because I need to do the same thing with each criteria, not just STATE. It would make the code have to be incredibly long.

Thanks for the idea though

Reply With Quote
  #4  
Old June 24th, 2004, 04:11 PM
jim mcnamara jim mcnamara is offline
......@.........
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,307 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 4 h 28 m 57 sec
Reputation Power: 48
You didn't say that to start with. Most of the guys answering on the forums are professionals and can answer better with a whole picture.

Since I imagine there are still things you've left out I'll just go with this:

decode()

It's like an if statement in Oracle SQL.

Reply With Quote
  #5  
Old June 25th, 2004, 10:40 AM
thordiddy thordiddy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 40 thordiddy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 17 m 12 sec
Reputation Power: 5
Cool

Sorry about that. If I was to use decode(), how would I implement it into my cursor? For example, I want it to yield everything if the variable CITY = NULL, but I want it to only yield people living in a certain city when CITY does not equal NULL.

Thanks for the help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Selecting All Items When Variable is Null


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway