在破折号之前删除字符 [英] Removing the Character before Dash
本文介绍了在破折号之前删除字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要从破折号(-)之前和之后的字符串中提取字符.到目前为止,我可以使用下面的代码返回破折号之前的所有数字:
I am to extract characters from a string before and after the dash (-). So far, I was able to use this code below to return all the numbers before dash:
SELECT
INSTR('100-7', '-'),
SUBSTR('100-7', 1, INSTR('100-7', '-')-1)
FROM dual;
现在,我正在尝试找到一种方法,在破折号后返回所有字符.因此,如果我有一个字符串:
Now I am trying to find a way to return all the characters after dash. So if I have a string:
20-150
该查询只能返回150.无论如何,我可以这样做吗?顺便说一句,我正在使用Oracle.谢谢大家:)
THe query should only return me 150. Is there anyway I can do this? By the way, I am using Oracle. Thanks guys :)
推荐答案
这将在破折号后返回所有内容
This will return everything after the dash
SELECT SUBSTR(value, INSTR(value, '-')+1) invalue
FROM (SELECT '20-150' value FROM dual) t;
输出:
| INVALUE |
-----------
| 150 |
将两者放在一起
SELECT SUBSTR(value, 1, INSTR(value, '-') - 1) lvalue,
SUBSTR(value, INSTR(value, '-') + 1) rvalue
FROM (SELECT '20-150' value FROM dual) t;
输出:
| LVALUE | RVALUE |
-------------------
| 20 | 150 |
这篇关于在破折号之前删除字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文