sql - 如何在Oracle sql中剪切字符串并返回子字符串
问题描述
我的项目中有一个要求,我需要拆分 url 并从中提取变量,url 是其中一个表中的一列。网址看起来像这样
输入行
"http://example.com/wps/myportal/example/viewer?mstrContentType=Report& mstrId=15F4AC9C4453E5F75456438F732F7B8C&contentName=7.++CTI+Session+Order+Counts&proj=System+Xr+-+DMDR/CW&workspaceName=&woId=&vendorId=Microstrategy"
我需要 o/p 如下与目标列进行比较如下
ContentType=Report
mstrId=15F4AC9C4453E5F75456438F732F7B8C
contentName=7.++CTI+Session+Order+Counts
etc...
我只能使用 Oracle ,不应该使用编程语言。
谢谢。
解决方案
这里所有你需要使用的,如下所示的 REGEXP_SUBSTR。
create table test1(col1 varchar2(4000));
insert into test1 values(
'http://example.com/wps/myportal/example/viewer?mstrContentType=Report& mstrId=15F4AC9C4453E5F75456438F732F7B8C&contentName=7.++CTI+Session+Order+Counts&proj=System+Xr+-+DMDR/CW&workspaceName=&woId=&vendorId=Microstrategy'
);
select regexp_substr(col1,'[^?"]+',1,2) ss from test1;
select trim(regexp_substr(regexp_substr(col1,'[^?"]+',1,2),'[^&]+', 1, level)) as output_data from test1
connect by regexp_substr(regexp_substr(col1,'[^?"]+',1,2), '[^&]+', 1, level) is not null;
输出数据
mstrContentType=Report
mstrId=15F4AC9C4453E5F75456438F732F7B8C
contentName=7.++CTI+Session+Order+Counts
proj=System+Xr+-+DMDR/CW
workspaceName=
woId=
vendorId=Microstrategy
推荐阅读
- c# - 向在 localhost 上运行的 bot 框架编写 http post 请求
- javascript - 使用 if / else 确定获胜者
- php - Typo3 扩展“无法确定插件”异常
- javascript - 未找到此相关模块:
- sql - 需要提高 SQL 查询的性能
- php - PHP:将多维数组转换为单数组
- mysqli - 从具有相同名称的数据库中获取所有数据
- android - 我可以在android studio中使用LanguageTool吗
- vuejs2 - Vue JS动画/过渡效果对函数调用时特定v-for项目文本的影响
- linux - 类型 = 1400 审核:avc:拒绝 { 读写 }