SQL Oracle 在空格前获取子字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14621357/
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-01 13:23:42  来源:igfitidea点击:

Oracle get substring before a space

sqlregexoracle

提问by Vivek

I have a string with space in between, and I need to get the first string (it can be a number) before the space.

我有一个中间有空格的字符串,我需要在空格之前获取第一个字符串(它可以是一个数字)。

 WITH test_data AS (
  SELECT '123642134  10' AS quarter_cd FROM dual UNION ALL --VALID
)

 select *
  from test_data
 where regexp_like(quarter_cd, '', 'c')

The output should be:

输出应该是:

123642134

回答by DazzaL

Substr (quarter_cd, 1,instr(quarter_cd,' ') - 1)

Should do that.

应该这样做。

回答by Bruno

SELECT Rtrim(Substr('123642134  10',1,Instr('123642134  10',' '))) AS quarter_cd FROM dual;

Uses of string function used in upper query

上查询中字符串函数的使用

  • Instr()- to get position of any character or space from the given string.
  • Substr()- to get substring from given string.
  • Rtrim()- to remove spaces from right side.
  • Instr()- 从给定的字符串中获取任何字符或空格的位置。
  • Substr()- 从给定的字符串中获取子字符串。
  • Rtrim()- 从右侧删除空格。