Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

handle no data found exception with null column values

Sagar Dua-OracleMar 8 2014 — edited Mar 8 2014

Hi,

Using Enterprise version Oracle DB 11.2.0.3.0.

I have table 'STORE_TEMP' with following data:-

       VKEY VAL1            VAL2

----------- --------------- -------------

         1  (null)           Test1

         2  Working       Test2

Table DDL:-

desc STORE

Name  Null       Type

----- ----       -------------

VKEY  NOT NULL  NUMBER

VAL1            VARCHAR2(100)

VAL2  NOT NULL  VARCHAR2(100)

Now I have some 10k rows in the table with such data like null values in VAL1 column with non null values in VAL2 column.

I want to SELECT all the keys from the table, but I am getting NO DATA FOUND exception when a null value is coming for VAL1 column.

DECLARE

  t_store_val1 STORE.val1%TYPE;

  t_store_val2 STORE.val2%TYPE;

  t_store_key STORE.vkey%TYPE;

  CURSOR cur_store_val1

  IS

    SELECT val1 FROM STORE;

  CURSOR cur_store_val2

  IS

    SELECT val2 FROM STORE;

BEGIN

  OPEN cur_store_val1;

  LOOP

    FETCH cur_store_val1 INTO t_store_val1;

    EXIT

  WHEN cur_store_val1%NOTFOUND;

    BEGIN

      OPEN cur_store_val2;

      LOOP

        FETCH cur_store_val2 INTO t_store_val2;

        EXIT

      WHEN cur_store_val1%NOTFOUND;

        BEGIN

          SELECT vkey

          INTO t_store_key

          FROM STORE

          WHERE val1=t_store_val1

          AND val2  =t_store_val2;

        END;

      END LOOP;

CLOSE t_store_val2;

    END;

  END LOOP;

CLOSE t_store_val1;

END;

How can I go about fixing this ?

Thanks..

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 5 2014
Added on Mar 8 2014
5 comments
817 views