sql - 如何在oracle中获取给定字符串之间的字符串
问题描述
这就是我的数据的样子。
APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2
~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow
我想获取从第一个字符到第一次出现 ^^^ 的数据,以及从第一个 ^^^ 到第二个 ^^^ 的数据。
谁能帮我在oracle中得到这个?
解决方案
用于INSTR
查找分隔符的位置,然后SUBSTR
提取子字符串:
甲骨文设置:
CREATE TABLE test_data ( value ) AS
SELECT 'APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2
~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow' FROM DUAL;
查询:
SELECT SUBSTR( value, 1, first_position - 1 ) AS first_substr,
SUBSTR( value, first_position + 3, second_position - first_position - 3 ) AS second_substr
FROM (
SELECT value,
INSTR( value, '^^^', 1, 1 ) AS first_position,
INSTR( value, '^^^', 1, 2 ) AS second_position
FROM test_data
)
输出:
FIRST_SUBSTR | SECOND_SUBSTR :------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------- | :------------------------------------------------ -------------------------------------------------- -------- APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow | APP_APX_PLM_Promo~~~skola2<br>~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow
db<>在这里摆弄
推荐阅读
- c++ - 编译器错误:'::main' 必须返回 'int' C++
- mongodb - Open Shift Container 中的 Java 内存堆空间问题
- python-3.x - 在检查字符串在 Python 中是否为字谜时,哪一个在时间和空间复杂性方面更好?
- c# - 当测试行为返回 NullReferenceException 类型时,如何在 Epicor BPM 中测试 null var?
- laravel - 尽管存在于迁移中,但 Laravel 表无法识别
- python - Pygame 窗口会突然充满白色
- testing - 如何在 Azure Devops 的 TestPlans 中配置测试结果
- email - Amazon SES 可用于公司电子邮件
- c# - Intellisense 完成模式停止工作(错误?)
- r - 如何在 R 的环境中动态访问和调用函数?