Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    276

    Unanswered: checking for period in a table

    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?

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    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

  3. #3
    Join Date
    Jul 2005
    Posts
    276
    Great!!! Thanks so much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •