KnowledgeBoat Logo
|

Informatics Practices

Consider the given SQL string :

"12#All the Best!"

Write suitable SQL queries for the following :

(i) Returns the position of the first occurrence of the substring "the" in the given string.

(ii) To extract last five characters from the string.

SQL Queries

3 Likes

Answer

(i)

SELECT INSTR("12#All the Best!", 'the') AS the_position;
Output
+--------------+
| the_position |
+--------------+
|            8 |
+--------------+

(ii)

SELECT SUBSTR("12#All the Best!", -5) AS last_five;
Output
+-----------+
| last_five |
+-----------+
| Best!     |
+-----------+

Answered By

1 Like


Related Questions