oracle - 在 oracle 中修剪字符串
问题描述
我有以下字符串并且只希望输出中的状态名称,请建议我。
'State - Rajasthan,Zone - Jaipur-I,Circle - Circle-P, Jaipur,Ward - Circle-P, jaipur - Ward-2'
所需输出 - 拉贾斯坦邦
解决方案
根据该示例,您可以考虑以下几个选项:
SQL> with test (col) as
2 (select 'State - Rajasthan,Zone - Jaipur-I,Circle - Circle-P, Jaipur,Ward - Circle-P, jaipur - Ward-2'
3 from dual
4 )
5 select substr(col, instr(col, ' ', 1, 2) + 1,
6 instr(col, ',') - instr(col, ' ', 1, 2) - 1
7 ) state,
8 --
9 replace(substr(col, 1, instr(col, ',') - 1), 'State - ', '') state2,
10 --
11 regexp_substr(col, '\w+', 1, 2) state3
12 from test;
STATE STATE2 STATE3
--------- --------- ---------
Rajasthan Rajasthan Rajasthan
SQL>
推荐阅读
- amazon-web-services - AWS 控制台中的 AWS ElasticSearch 请求超时
- devexpress - 适用于 Blazor 的 DevExpress dxDataGrid -“当前电路存在未处理的异常”错误
- javascript - 如何建立一个简单的美元/欧元反应货币转换器,具有固定的转换率?
- kubernetes - 每个 Git 提交的 ImageStreamTag
- java - 简化抽象类的多个继承类(内容相同)
- reactjs - 通过 Manifest.xml 文件在 excel 功能区上使用登录选项
- java - 在清单文件中使用 -cp 选项和类路径运行 java 程序
- python - Python 子包导入
- jpa - Hibernate Envers 无法删除实体
- javascript - 无法使用 jquery-validation.js submitHandler 函数发送“multipart/form-data”表单数据