Which SELECT statement will the result 'ello world' from the string 'Hello World'?
-
SELECT SUBSTR ('Hello',) FROM dual;
-
SELECT INITCAP (TRIM ('Hello World',1,1) FROM dual;
-
SELECT LOWER (SUBSTR ('Hello World',1,1) FROM dual
-
SELECT LOWER (SUBSTR ('Hello World',2,1) FROM dual;
-
SELECT LOWER (TRIM ('H' FROM 'Hello World')) FROM dual;
The question asks for 'ello world' from 'Hello World'. The correct approach is to remove the first character 'H' and convert the result to lowercase. Option E does exactly this: TRIM('H' FROM 'Hello World') removes 'H' from the beginning, then LOWER() converts 'ello World' to 'ello world'. The other options either don't remove the first character correctly or have syntax errors like missing parentheses.
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) SELECT SUBSTR ('Hello',) FROM dual; This option is incorrect because the SUBSTR function requires three arguments: the string, the starting position, and the length. In this case, the starting position and length are not provided.
Option B) SELECT INITCAP (TRIM ('Hello World',1,1) FROM dual; This option is incorrect because the TRIM function is used to remove specified characters from the beginning and/or end of a string. In this case, the starting position and length are not provided correctly.
Option C) SELECT LOWER (SUBSTR ('Hello World',1,1) FROM dual This option is incorrect because the SUBSTR function is used to extract a substring from a string. In this case, it is extracting the first character 'H' and converting it to lowercase using the LOWER function. It does not provide the desired result 'ello world'.
Option D) SELECT LOWER (SUBSTR ('Hello World',2,1) FROM dual; This option is incorrect because the SUBSTR function is used to extract a substring from a string. In this case, it is extracting the second character 'e' and converting it to lowercase using the LOWER function. It does not provide the desired result 'ello world'.
Option E) SELECT LOWER (TRIM ('H' FROM 'Hello World')) FROM dual; This option is correct because it uses the TRIM function to remove the letter 'H' from the string 'Hello World'. It then converts the remaining string 'ello world' to lowercase using the LOWER function. This provides the desired result 'ello world'.
The correct answer is Option E.