0

By using following query i am able to fetch a particular string.Now this output string contains alphanumeric characters.e.g.abcd123,pqrs542356. Now i want to fetch only first 4 characters of this string which will be always alpha bates.

Query::

(SELECT SUBSTR(in_msg, INSTR( in_msg,'?', 1, 10 )+ 1, INSTR(in_msg,'?', 1, 11 ) - INSTR( in_msg,'?', 1, 10 )- 1)
 FROM emp_message 
WHERE emp_no IN (SELECT emp_no 
                   FROM main_table 
                  WHERE name like '%abcd%')

This query returns output as e.g.abcd1234,pqrs145423. Again i want to fetch only first 4 characters from this query output. Can somebody help me in this.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
MAS1
  • 1,691
  • 6
  • 19
  • 22

3 Answers3

4

You can use substr (like you already do):

SUBSTR(value, 1, 4)
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
0

Here it is:

SUBSTR(field, 0, 4)
zerkms
  • 249,484
  • 69
  • 436
  • 539
0
select substr(x, 1, 4) from
   ( select x from .....  )
Thilo
  • 257,207
  • 101
  • 511
  • 656