Multiple choice technology databases

The output of the query " Select length(substr('SQL Functions',-10,12)) from dual; " is

  1. 12

  2. 10

  3. 13

  4. error

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Oracle SQL, substr('SQL Functions', -10, 12) extracts a substring starting 10 characters from the end (' Functions') with a length of 12. Since only 10 characters remain, it returns ' Functions'. The length of this string is 10, making 10 the correct output.

AI explanation

To answer this question, let's break down the query step by step:

The query is:

Select length(substr('SQL Functions',-10,12)) from dual;
  1. The substr function is used to extract a substring from the given string 'SQL Functions'. The parameters are (string, start_position, length).
  2. In this case, substr('SQL Functions',-10,12) will extract a substring starting from the 10th position from the end (-10) and with a length of 12 characters. So, the extracted substring is ' Functions'.
  3. The length function is then applied to the extracted substring ' Functions', which returns the length of the string.
  4. Finally, the result of the query is the length of the extracted substring, which is 10.

Therefore, the correct answer is B) 10.