W3. SQL Null Functions Flashcards

1
Q

Q: What do SQL functions like IFNULL(), ISNULL(), COALESCE(), and NVL() do?

A

A: They allow you to return an alternative value when an expression is NULL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Why would you use functions like IFNULL() in a SQL query?

A

A: To replace NULL values with an alternative value, avoiding NULL results in calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: Write a query using IFNULL() in MySQL to replace NULL in UnitsOnOrder with 0.

A

SELECT ProductName, UnitPrice * (UnitsInStock + IFNULL(UnitsOnOrder, 0))
FROM Products;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How does the COALESCE() function work, and is it database-specific?

A

A: COALESCE() returns the first non-NULL value from a list, and it is compatible across multiple databases (MySQL, SQL Server, Oracle).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: Write a query using COALESCE() to replace NULL in UnitsOnOrder with 0.

A

SELECT ProductName, UnitPrice * (UnitsInStock + COALESCE(UnitsOnOrder, 0))
FROM Products;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: Which function does SQL Server use to handle NULL values similarly to IFNULL()?

A

A: ISNULL()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Write a query using ISNULL() in SQL Server to replace NULL in UnitsOnOrder with 0.

A

SELECT ProductName, UnitPrice * (UnitsInStock + ISNULL(UnitsOnOrder, 0))
FROM Products;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: How does the IsNull() function work in MS Access?

A

A: It returns TRUE (-1) if the expression is NULL, and FALSE (0) otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: Write a query using IIF() and IsNull() in MS Access to replace NULL in UnitsOnOrder with 0.

A

SELECT ProductName, UnitPrice * (UnitsInStock + IIF(IsNull(UnitsOnOrder), 0, UnitsOnOrder))
FROM Products;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What function does Oracle use to handle NULL values, similar to IFNULL()?

A

A: NVL()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: Write a query using NVL() in Oracle to replace NULL in UnitsOnOrder with 0.

A

SELECT ProductName, UnitPrice * (UnitsInStock + NVL(UnitsOnOrder, 0))
FROM Products;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly