Reputation: 11028
I have a table with name Shipment
which has columns HAWB, MAWB
. How can I check that these two columns are having null value or not ?.
Upvotes: 1
Views: 7903
Reputation: 5654
Create a code block and create a cursor this will hold the data you need.
Declare
Cursor MyCursor IS
SELECT HAWB, MAWB FROM Shipment WHERE ......... (you can select multiple rows or a single row it depends on what you put in the where clause)
BEGIN
For eachRecord IN MyCursor LOOP
--You can do any kind of processing in here
-- access the data in the cursor using eachRecord.HAWB OR eachRecord.MAWB
--This will print all the values stored in the column HAWB if there is only one record then only one value will be printed
DBMS_OUTPUT.PUT_LINE(eachRecord.HAWB);
--same happens here
DBMS_OUTPUT.PUT_LINE(eachRecord.MAWB);
--****************************
--check if the first value of HAWB or MAWB IS NULL
IF eachRecord.HAWB IS NULL THEN
--Do your processing here
ELSIF eachRecord.MAWB IS NULL THEN
--Do your processing here
END IF;
LOOP;
END;
The data will remain in the cursor kinda like an array and you can do whatever you want with it in the code block. You can also look at FETCHING the data from the cursor instead of using a LOOP to process it
Upvotes: 0
Reputation: 15473
If you want to learn pl/sql, you can start here.
Happy coding!
BTW, that same link has the answer to your question (and more)
Upvotes: 1
Reputation: 13218
In SQL you can check the values of a column are null
or not by using IS NULL
keyword.
To check if the value is NOT NULL
you can use the keywords IS NOT NULL
Eg:
Select * from tableName where columnName IS NULL
Select * from tableName where columnName IS NOT NULL
Alternatively in Java, you can get the value of this column and check for its value appropriately.
Hope this helps.
Upvotes: 1
Reputation: 24722
Just use HAWB is null and MAWB is null
or is not null
for reverse.
Upvotes: 2
Reputation: 162811
To find the rows where HAWB
is null:
SELECT * FROM Shipment WHERE HAWB IS NULL;
To find the rows where MAWB
is null:
SELECT * FROM Shipment WHERE MAWB IS NULL;
If you want to find the rows where HAWB
isn't null:
SELECT * FROM Shipment WHERE HAWB IS NOT NULL;
And finally, if you want to find the rows where MAWB
isn't null:
SELECT * FROM Shipment WHERE MAWB IS NOT NULL;
Upvotes: 6