what about
Option D?: SELECT SUBSTR(join_date, 1, 2) - 10 FROM employees; This query is attempting to perform a substring operation on a DATE type, which is not valid without first converting the date to a string. Oracle does not support taking substrings directly from DATE data types. The date must be converted to a string using TO_CHAR before SUBSTR can be used. Furthermore, subtracting 10 from a substring of a date does not make sense unless the substring represents a number, which is not the case here since join_date is a date and not a string of numbers. Therefore, explicit conversion is necessary, and the query itself is somewhat nonsensical without additional context or correction. This makes Option D the most clearly incorrect and the one that certainly requires explicit data type conversion to even make sense as a SQL statement.
AC is correct.
A returns:
SELECT join_date FROM employees WHERE join_date > '10-02-2018';
SELECT join_date FROM employees WHERE join_date > '10-02-2018'
*
ERROR at line 1:
ORA-01843: not a valid month
C returns:
SQL> SELECT salary+'120.50' FROM employees;
SELECT salary+'120.50' FROM employees
*
ERROR at line 1:
ORA-01722: invalid number
Let me correct my suggestion, please. Only C is correct.
Datatype conversion in A does not make the query valid.
SQL> SELECT join_date FROM employees WHERE TO_DATE(join_date,'DD-MM-YYYY') > '10-02-2018';
SELECT join_date FROM employees WHERE TO_DATE(join_date,'DD-MM-YYYY') > '10-02-2018'
*
ERROR at line 1:
ORA-01843: not a valid month
Only altering session variable NLS_DATE_FORMAT with
ALTER SESSION SET nls_date_format='DD-MM-YY';
makes the A query to return valid response. So there´s no datatype conversion, just altering session variable, therefore A is false.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Oracle2020
3 months agopsycrotic5
7 months, 1 week agonautil2
10 months, 3 weeks agonautil2
10 months, 3 weeks agoauwia
1 year agoPivoine
1 year agoivanadj
1 year, 4 months ago