Procedure to look up null values for 2 columns, if true, then use the some values from those rows to perform something

StackOverflow https://stackoverflow.com/questions/23496937

  •  16-07-2023
  •  | 
  •  

Question

I have a table that might have null values for two columns. I need to find any rows that might contain null values for those two columns. If null values are found within those two columns, then I need to use certain key values from those rows to perform something.

So If null found, then..else Any idea is greatly appreciated. Will be better if you can give examples. Thanks

Edited: I have a table Tab1 that stores the procedure execution info. For example, the time the load starts, ends, and if it completed. My new procedure will check if the End and Completed column is empty, if true then let's just say I want to truncate table Tab2. I don't want to change anything on Tab1.

Sorry if it's confusing.

Was it helpful?

Solution

Here is a generic example:

CREATE TABLE tab1
(
   v1   NUMBER,
   v2   NUMBER,
   v3   NUMBER,
   v4   NUMBER
);

CREATE TABLE tab2
(
   v1   NUMBER,
   v2   NUMBER
);

INSERT INTO tab1
     VALUES (1, 1, 1, 1);

INSERT INTO tab1
     VALUES (2, 2, 2, 2);

INSERT INTO tab2
     VALUES (2, 2);


INSERT INTO tab1
     VALUES (3, 3, NULL, NULL);

INSERT INTO tab2
     VALUES (3, 3);

select * from tab2;
select * from tab1;

    V1         V2

     2          2
     3          3

2 rows selected.

    V1         V2         V3         V4

     1          1          1          1
     2          2          2          2
     3          3     

DELETE FROM tab2
      WHERE (v1, v2) IN (SELECT v1, v2
                           FROM tab1
                          WHERE v3 IS NULL AND v4 IS NULL);


select * from tab2;

    V1         V2

     2          2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top