1z0-082 Exam QuestionsBrowse all questions from this exam

1z0-082 Exam - Question 71


The CUSTOMERS table has a CUST_CREDIT_LIMIT column of data type NUMBER.

Which two queries execute successfully? (Choose two.)

Show Answer
Correct Answer: CE

To determine which queries will execute successfully, we need to consider the use of the NVL, NVL2, and TO_CHAR functions. The NVL function requires the second argument to be of the same data type as the first argument. In the case of the column cust_credit_limit, which is of type NUMBER, NVL(cust_credit_limit * .15, 'Not Available') is incorrect because 'Not Available' is a string, not a number. However, converting the result of the multiplication to a string with TO_CHAR makes it valid: NVL(TO_CHAR(cust_credit_limit * .15), 'Not Available'). For NVL2, the function expects three arguments: the first is checked for NULL, the second is returned if the first is NOT NULL, and the third is returned if the first is NULL. In NVL2(cust_credit_limit, TO_CHAR(cust_credit_limit * .15), 'Not Available'), this is correctly applied, as TO_CHAR(cust_credit_limit * .15) converts the numeric result to a string when cust_credit_limit is not NULL. Therefore, the two correct queries are the ones using NVL and NVL2 with TO_CHAR.

Discussion

6 comments
Sign in to comment
you1234Options: CE
Jul 18, 2020

A) SELECT NVL(cust_credit_limit * .15, 'Not Available') FROM customers; B) SELECT NVL2(cust_credit_limit * .15, 'Not Available') FROM customers; C) SELECT NVL(TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; D) SELECT TO_CHAR(NVL(cust_credit_limit * .15, 'Not Available')) FROM customers; E) SELECT NVL2(cust_credit_limit, TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; Correct C & E.

ama
Jul 30, 2020

YES C & E

Ekos
Nov 14, 2020

correct, C & E

amaOptions: CD
Jul 3, 2020

C , D are corrects!

amorimleandro
Jul 13, 2020

Nope, C, E are correct. You cannot convert all the function NVL in D, because its result is an error. But, in E, we have a similar situation as in C.

LrnsTgh
Aug 25, 2021

D has no different with A. they aren't correct.

XhostSIOptions: CE
Feb 23, 2022

Adopted to HR Schema: SELECT NVL(TO_CHAR(commission_pct * .15), 'Not Available') FROM employees; SELECT NVL2(commission_pct, TO_CHAR(commission_pct * .15), 'Not Available') FROM employees; Correct answers: C, E

j_tw
Apr 18, 2023

I don't know why not A ?

auwia
Jul 4, 2023

Implicit cast is never easy to understand on fly, so oracle (and many others) recommend to try to avoid them.

valiantvimal
Apr 29, 2024

C, E are correct. Reason why A is not correct is NVL function expects the cust_credit_limit column to be of same datatype as Replacement value ('Not Available' here). So it has to be converted to string (TO CHAR) to achieve it.

valiantvimal
Apr 29, 2024

Result will be like: SQL> SELECT NVL(cust_credit_limit * .15, 'Not Available') FROM customers; SELECT NVL(cust_credit_limit * .15, 'Not Available') FROM customers * ERROR at line 1: ORA-01722: invalid number SQL> SELECT NVL(TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; NVL(TO_CHAR(CUST_CREDIT_LIMIT*.15),'NOTA ---------------------------------------- 150 750.0375 Not Available SQL> SELECT NVL2(cust_credit_limit, TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; NVL2(CUST_CREDIT_LIMIT,TO_CHAR(CUST_CRED ---------------------------------------- 150 750.0375 Not Available

valiantvimal
Apr 29, 2024

You can see that in the First Query given below that 'Not Available' is not accepted as a Replacement for the Column with Number Datatype. So once Number Datatype is converted into CHAR, the 'Not Available' string gets displayed. If the Replacement Value is a Number instead of 'Not Available', NVL will accept it since the cust_credit_limit column's datatype is Number.

Lalala8Options: CE
Oct 2, 2023

C. SELECT NVL(TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; This query will return the value of the cust_credit_limit column multiplied by 0.15, converted to a character value, if the cust_credit_limit column is not null. Otherwise, it will return the string 'Not Available'. E. SELECT NVL2(cust_credit_limit, TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; This query will return the value of the cust_credit_limit column if it is not null. Otherwise, it will return the value of the expression TO_CHAR(cust_credit_limit * .15), converted to a character value. If the expression TO_CHAR(cust_credit_limit * .15) is null, the NVL2() function will return the string 'Not Available'.

valiantvimalOptions: CE
Apr 29, 2024

C, E are correct. Reason why A is not correct is NVL function expects the cust_credit_limit column to be of same datatype as Replacement value ('Not Available' here). So it has to be converted to string (TO CHAR) to achieve it.

valiantvimal
Apr 29, 2024

If the Replacement Value is a Number instead of 'Not Available', NVL will accept it since the cust_credit_limit column's datatype is Number.

valiantvimal
Apr 29, 2024

Result will be like: SQL> SELECT NVL(cust_credit_limit * .15, 'Not Available') FROM customers; SELECT NVL(cust_credit_limit * .15, 'Not Available') FROM customers * ERROR at line 1: ORA-01722: invalid number SQL> SELECT NVL(TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; NVL(TO_CHAR(CUST_CREDIT_LIMIT*.15),'NOTA ---------------------------------------- 150 750.0375 Not Available SQL> SELECT NVL2(cust_credit_limit, TO_CHAR(cust_credit_limit * .15), 'Not Available') FROM customers; NVL2(CUST_CREDIT_LIMIT,TO_CHAR(CUST_CRED ---------------------------------------- 150 750.0375 Not Available You can see that in the First Query 'Not Available' is not accepted as a Replacement for the Column with Number Datatype. So once Number Datatype is converted into CHAR, the 'Not Available' string gets displayed.