oracle PL/SQL 拆分字符串,获取最后一个值?

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

PL/SQL split string, get last value?

oracleplsql

提问by SlashJ

how could one split a string in PL/SQL to get the last value if the pattern look like this? :

如果模式看起来像这样,如何在 PL/SQL 中拆分字符串以获取最后一个值?:

'1;2', in this case the value i want would be 2.

'1;2',在这种情况下,我想要的值为 2。

Note: the splitter is the character ';' and values are of different length like '1;2 or 123;45678 etc...'

注意:分隔符是字符';' 和值的长度不同,如“1;2 或 123;45678 等...”

Thanks in advance!

提前致谢!

回答by Justin Cave

SELECT SUBSTR( column_name, 
               INSTR( column_name, ';', -1 ) + 1 )
  FROM table_name

should work. Here is a SQL Fiddle example.

应该管用。这是一个SQL Fiddle 示例

回答by Egor Skriptunoff

regexp_substr(your_string, '[^;]*$')

回答by Noel

You should first find the position of ; using,

您应该首先找到 ; 使用,

instr(string,';',1,1)

Then use SUBSTRfunction to extract the value starting from one more than the value found in previous function.

然后使用SUBSTR函数从比前一个函数中找到的值多一个开始提取值。

select substr(string,instr(string,';',1,1) + 1) from table;

回答by T.S.

In your case, you can use instr with -1 start position and Substr.

在您的情况下,您可以将 instr 与 -1 起始位置和 Substr 一起使用。

pos := instr( searchIn, ';', -1, 1)
res := substr(searchIn, pos + 1)

This should work, and if not... this is has to do it

这应该有效,如果没有......这是必须的