oracle 如何从oracle中的字符串中获取4个字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4496617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:15:29  来源:igfitidea点击:

How to fetch 4 characters from a string in oracle?

sqldatabaseoracle

提问by MAS1

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.

通过使用以下查询,我能够获取特定字符串。现在该输出字符串包含字母数字字符。egabcd123、pqrs542356。现在我只想获取这个字符串的前 4 个字符,这些字符将始终是 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.

此查询返回输出为 egabcd1234,pqrs145423。我再次想从这个查询输出中只获取前 4 个字符。有人可以帮助我吗。

回答by GolezTrol

You can use substr (like you already do):

您可以使用 substr (就像您已经做的那样):

SUBSTR(value, 1, 4)

回答by zerkms

Here it is:

这里是:

SUBSTR(field, 0, 4)

回答by Thilo

select substr(x, 1, 4) from
   ( select x from .....  )