sql - How to get specific value from filename by substr-instr
问题描述
I have 2 file which names like abc_primary.log and abc_secondary.log and i need the output like primary and secondary only using substr and instr.
select SUBSTR(name1,(LENGTH(name1)-INSTR(REVERSE(name1), '.', 1)+2))
from
(
select
'abc_primary.log' as name1 ,
'abc_secondary.log' as name2
from dual
);
here i can get the output is 'log' which is the right-side part of the file. But i need the output will be only either primary or secondary. Can anyone here help me to get the value. Thanks
解决方案
如果你只想使用substr
然后instr
你可以这样写:
select substr(substr(name1, 1, instr(name1, '.') - 1), instr(name1, '_') + 1) n1,
substr(substr(name2, 1, instr(name2, '.') - 1), instr(name2, '_') + 1) n2
from (
select 'abc_primary.log' as name1, 'abc_secondary.log' as name2
from dual);
结果:
N1 N2
------- ---------
primary secondary
推荐阅读
- excel - 使用字典与 VBA 匹配值的问题
- java - 在Java中是否可以使用循环创建N个具有不同名称(不是大小)的数组
- asp-classic - 经典 ASP 自定义 404 重定向在 Firefox 或 IE11 中不起作用
- asp.net-core - 如何将流文件发送到 grpc 并在 .net 核心中获得响应?
- azure - 将数据写入数据湖 gen2 以进行电力双消耗
- javascript - React useEffect() 状态未更新
- javascript - Rails 应用程序未加载样式表或 js 文件
- selenium-webdriver - 在使用 Selenium 中的 POM 模式使用混合框架时更改 Chrome 中的默认下载位置
- c++ - pthread函数realloc()中的C ++堆损坏:下一个大小无效
- c - C 中的浮点、双精度和指数输出