Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oracle if 0, like if null (nvl)

Tags:

oracle

oracle has a nice built in function for doing if null, however I want to do if = 0; is there a simple way to do this?

nvl(instr(substr(ovrflo_adrs_info,instr(ovrflo_adrs_info,'bldg')+5),' '), length(substr(ovrflo_adrs_info,instr(ovrflo_adrs_info,'bldg')+5))))

This is going as a parameter to a substr function.

If instr(substr(ovrflo_adrs_info,instr(ovrflo_adrs_info,'bldg')+5),' ') is != 0 then I want that value, otherwise I want the value of length(substr(ovrflo_adrs_info,instr(ovrflo_adrs_info,'bldg')+5))

is there an easy way to do this?

like image 519
kralco626 Avatar asked Jun 01 '11 17:06

kralco626


People also ask

Can NVL return null?

NVL. The NVL function allows you to replace null values with a default value. If the value in the first parameter is null, the function returns the value in the second parameter. If the first parameter is any value other than null, it is returned unchanged.

Can we compare null with null in Oracle?

Because null represents a lack of data, a null cannot be equal or unequal to any value or to another null. However, Oracle considers two nulls to be equal when evaluating a DECODE function.

Can we use NVL for number in Oracle?

The Oracle NULL Value (NVL) SQL operator is a great way to substitute NULL values with numeric values in Oracle SQL statements. As you can see, the NVL function replaces a NULL with whatever value you desire.

What is the difference between NULL value function NVL () & coalesce ()?

NVL and COALESCE are used to achieve the same functionality of providing a default value in case the column returns a NULL. The differences are: NVL accepts only 2 arguments whereas COALESCE can take multiple arguments. NVL evaluates both the arguments and COALESCE stops at first occurrence of a non-Null value.


1 Answers

You can use NVL(NULLIF(A,'0'), B)

like image 192
patricK Avatar answered Oct 11 '22 14:10

patricK