Oracle query nvl issue

 IF (v_old_loc_id_stored is not NULL OR v_loc_id is not NULL) THEN  

               v_whse := GET_WHMNT_ID(nvl(v_old_loc_id_stored,v_loc_id), v_div_no); 
End If;

Open in new window


If either of the variables is not null then I get warehouse using the get_whmnt_id function.
I think nvl is not correct. My problem is if v_old_loc_id_stored is null my nvl will work. How to handle if v_loc_id is null?
LVL 6
anumosesAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark GeerlingsDatabase AdministratorCommented:
Do you mean: "How to handle it if both v_loc_id and v_old_loc_id are null?

Your logic should work fine if either of these fields is null, as long as the other one has a value.  If both of these can be null, then using NVL with those two fields will not help you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anumosesAuthor Commented:
So my code is correct? If either one is null will it handle?
0
slightwv (䄆 Netminder) Commented:
To get to GET_WHMNT_ID one or both must have a value.  If v_loc_id is null then v_old_loc_id_stored  cannot.

So, the NVL will always return a value.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

anumosesAuthor Commented:
Also is there a need for nvl? In my case its OR
v_old_loc_id_stored is not null or v_loc_id  is not null
0
slightwv (䄆 Netminder) Commented:
We cannot say.  We don't know what your requirements are.

NVL says:  If the first value is null, return the second.
0
anumosesAuthor Commented:
what happens if 2nd value is null. That is the confusion for me. In my case, anyone could be null. So how to derive my warehouse by using my function so that my warehouse id is not null based on loc id.
0
anumosesAuthor Commented:
My requirement is that to check v_old_loc_id_stored  and v_loc_id

if either one is not null proceed to the next step, else exception no_data_found.
0
anumosesAuthor Commented:
Your first answer

Do you mean: "How to handle it if both v_loc_id and v_old_loc_id are null?

Your logic should work fine if either of these fields is null, as long as the other one has a value.  If both of these can be null, then using NVL with those two fields will not help you.

NO if both are null then I raise exception no_data_found and write to error table.

Your logic should work fine if either of these fields is null, as long as the other one has a value.

So I think my code will work. Will do some testing.
0
slightwv (䄆 Netminder) Commented:
>>what happens if 2nd value is null.

Based on your IF statement, if the second is null then the first cannot be so the first value is returned.

>>if either one is not null proceed to the next step, else exception no_data_found.

What you need to work out is what one do you want returned if the other is null.
0
awking00Information Technology SpecialistCommented:
You might try using the coalesce function which takes the first non-null value available.
v_whse :=  get_whse(coalsesce(v_old_loc_id_stored, v_loc_id, v_default) ==> where v_default could be a value you choose when the first two arguments are both null)

Then you could add if v_whse = v_default raise exception
0
awking00Information Technology SpecialistCommented:
I don't want to confuse the issue, but you would still need the v_div_no parameter for the get_whse function.
0
anumosesAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.