4est
4est

Reputation: 3168

How to catch null vales and display comment

I have bascic query:

select col1, nvl(col1,to_number(null)) from table1 where colx = :new

UPDATE

baiscly, during upload I'm checking if :new is inside table1.colx. If yes, I want to display col1, if not null value (I can't put zero).

Upvotes: 0

Views: 70

Answers (3)

Beege
Beege

Reputation: 665

In your pl/sql, you need to handle the scenario where the result of your query returns 0 rows, which is exception handling:

BEGIN
 ...
 select col1 into my_variable from table1 where colx = :new;
 ...
EXCEPTION WHEN NO_DATA_FOUND then
 <whatever-code-when-there-is-no-data>
 ...
END;

Upvotes: 0

Ron van D.
Ron van D.

Reputation: 1

When colx = 'abcde' is not present in table1, your query will raise a no_data_found exception. It will not return a result from your query.

You can catch this exception and act upon it.

Upvotes: 0

Dina Bogdan
Dina Bogdan

Reputation: 4698

nvl(col1,to_number(null)) will return blank. You can change from that to this: nvl(col1,0).

Upvotes: 2

Related Questions