Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > checking for period in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-10-08, 12:59
nandinir nandinir is offline
Registered User
 
Join Date: Jul 2005
Posts: 234
checking for period in a table

Quote:
FOR REC IN (SELECT PERIOD FROM tab1)
LOOP
IF acct_prd <> REC.PERIOD
THEN
RAISE e_NO_DATA_ERROR;
END IF;
END LOOP;
SELECT PERIOD FROM tab1;

PERIOD
------

2001
2002
2003
2004
2005

acct_prd is the IN parameter.
Record above has about 5 rows and when acct_prd=2003, it should not throw an error but
when I say rec.period it encounters 2001 first and as acct_prd <> 2001, its throwing an exception.
Any better way of writing this?
Reply With Quote
  #2 (permalink)  
Old 10-10-08, 14:06
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 1,951
Talking One way:

One way is:
Code:
SELECT count(*) INTO my_cnt FROM tab1 WHERE PERIOD = acct_prd; IF my_cnt = 0 THEN RAISE e_NO_DATA_ERROR; END IF;
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 10-10-08, 14:10
nandinir nandinir is offline
Registered User
 
Join Date: Jul 2005
Posts: 234
Great!!! Thanks so much!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On