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!

SELECT statement initialising the 'INTO' variable into NULL values

812115Nov 10 2010 — edited Nov 10 2010
Hi,

I would like to know when Oracle initialises the variable.
We may have major problems with our code, if Oracle initialises the variable to NULL first, before trying to populate it.


We have the following type of code:


v_total_red_income := 0; /* initialisation is already done */

select sum(income1+income2+income3) INTO v_total_red_income
from incometable where clno = v_clno;
exception
when others then
null;


If no records are found, the variable v_total_red_income seems to be initialised to null;

what we want to happen is that , if no records are found, then the variable v_total_red_income should still be 0 rather than null.

Reason is that in subsequent statement, we add a variable v_dist_income which has a value to v_total_red_income to get the v_total_gross_income....

the v_total_gross_income seems to be set to NULL even though the v_dist_income has a value.

Is there a way to set the way PL/SQL runs so that when it adds a null value to a non-null variable, it will simply treat the null as a 0 ? or maybe for the SQL statement not to initialise the variable to a NULL before it finds a record ?

Is that even possible ?

Thank you very much.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 8 2010
Added on Nov 10 2010
10 comments
900 views