Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle NVL function equivalent in JavaScript/jQuery

Is there an Oracle NVL function equivalent in JavaScript/jQuery. I would be interested to see an example of how it works.

like image 548
tonyf Avatar asked Mar 02 '11 12:03

tonyf


People also ask

What is the NVL function in Oracle?

NVL lets you replace null (returned as a blank) with a string in the results of a query. If expr1 is null, then NVL returns expr2 . If expr1 is not null, then NVL returns expr1 .

Can we use NVL IN CASE statement in Oracle?

Introduction. When creating selector CASE statements, you cannot have NULL in the list of possible values. In PL/SQL the Boolean expression NULL=NULL evaluates to FALSE.

What is NVL in Java?

The NVL function lets you substitute a value when a null value is encountered. NVL replaces a null with a String. NVL returns the replacement String when the base expression is null, and the value of the base expression when it is not null.

Is there a NVL in MySQL?

The NVL( ) function is available in Oracle, and not in MySQL or SQL Server. This function is used to replace NULL value with another value. It is similar to the IFNULL Function in MySQL and the ISNULL Function in SQL Server.


1 Answers

In Javascript this can actually be handled by the || operator, that returns the first "valid" value.

var a = null;
var b = "valid value";
var c = a || b; // c == "valid value"

Just keep in mind that "falsy" values are not only null but also for example empty string '', number 0 and boolean value false. So you need to be sure that either you consider those with the same meaning as null or your variables cannot assume those values, because in those cases you will also get the second value selected:

var a = "";
var b = "valid value";
var c = a || b; // c == "valid value"
like image 97
unziberla Avatar answered Sep 28 '22 02:09

unziberla