• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 26
  • Last Modified:

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?
0
anumoses
Asked:
anumoses
  • 6
  • 3
  • 2
  • +1
3 Solutions
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
awking00Commented:
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
 
awking00Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now