The SQL statementSELECT SUBSTR(‘123456789’, INSTR(‘abcabcabc’,’c’), 9) FROM EMP; prints
Question
The SQL statement
SELECT SUBSTR(‘123456789’, INSTR(‘abcabcabc’,’c’), 9) FROM EMP;
prints
Solution
The SQL statement SELECT SUBSTR('123456789', INSTR('abcabcabc','c'), 9) FROM EMP;
is using two functions: SUBSTR
and INSTR
.
-
INSTR('abcabcabc','c')
is a function that returns the position of the first occurrence of the second string in the first string. In this case, it returns the position of 'c' in 'abcabcabc', which is 3. -
SUBSTR('123456789', 3, 9)
is a function that extracts a substring from a string. It starts from the position of the second argument and extracts the number of characters specified in the third argument. In this case, it starts from the 3rd character of '123456789' and extracts 9 characters.
However, '123456789' only has 9 characters, so starting from the 3rd character, we can only extract 7 characters. Therefore, the result of SUBSTR('123456789', 3, 9)
is '3456789'.
So, the SQL statement SELECT SUBSTR('123456789', INSTR('abcabcabc','c'), 9) FROM EMP;
prints '3456789' for each row in the EMP table.
Similar Questions
What will be the output of the following query?select INSTR('Tech on the net', 'e', 1, 3) from dual;21114
What will be the output of the following query?select INSTR('Tech on the net', 'e', 1, 3) from dual;
Choose the correct answer What is the output of the following print statement print(chr(ord('c') - 1)) Options B b c A
Given the string "Software Engineering", which SQL function returns the substring "Software"?
What is the output of following?print(“abcabcab”.split(‘c’, 0))Select one:‘abcabcab’None of themError[‘abcabcab’]
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.