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
  • 314,254
  • 77
  • 507
  • 490
MAS1
  • 1,633
  • 6
  • 19
  • 22

3 Answers3

4

You can use substr (like you already do):

SUBSTR(value, 1, 4)
GolezTrol
  • 111,943
  • 16
  • 178
  • 202
0

Here it is:

SUBSTR(field, 0, 4)
zerkms
  • 240,587
  • 65
  • 429
  • 525
0
select substr(x, 1, 4) from
   ( select x from .....  )
Thilo
  • 250,062
  • 96
  • 490
  • 643