sql
sql
ELSE 'Low'
END AS SalaryLevel
FROM Employees;
39. What are scalar functions in SQL?
Scalar functions operate on individual values and return a single value as a
result. They are often used for formatting or converting data. Common
examples include:
LEN(): Returns the length of a string.
ROUND(): Rounds a numeric value.
CONVERT(): Converts a value from one data type to another.
Example:
SELECT LEN('Example') AS StringLength;
40. What is the purpose of the COALESCE function?
The COALESCE function returns the first non-NULL value from a list of
expressions. It’s commonly used to provide default values or handle
missing data gracefully.
Example:
SELECT COALESCE(NULL, NULL, 'Default Value') AS Result;
41. What are the differences between SQL’s COUNT() and
SUM() functions?
1. COUNT(): Counts the number of rows or non-NULL values in a column.
Example:
SELECT COUNT(*) FROM Orders;
2. SUM(): Adds up all numeric values in a column.
Example:
SELECT SUM(TotalAmount) FROM Orders;
42. What is the difference between the NVL and NVL2
functions?
NVL(): Replaces a NULL value with a specified replacement
value. Example: NVL(Salary, 0) will replace NULL with 0.
NVL2(): Evaluates two arguments:
o If the first argument is NOT NULL, returns the second
argument.
o If the first argument is NULL, returns the third argument.
Example:
SELECT NVL(Salary, 0) AS AdjustedSalary FROM Employees; --
Replaces NULL with 0
Comment
More info
Advertise with us
Similar Reads
Data is growing every day, and it plays a big part in making important
PL/SQL (Procedural Language for SQL) is one of the most widely used
common SQLite interview questions that can help you showcase your