【发布时间】:2019-09-08 09:40:23
【问题描述】:
表格中有一个特定的列,工作人员在其中叙述付款或收据的性质。
写一些类似'PAYMENT OF SALARIES FOR THE MONTH OF NOVEMBER 2018'的东西。我希望能够有代码(ORACLE SQL),可以从这些叙述中挑选月份。
【问题讨论】:
-
请在您的问题中添加一些代码和数据,以使其完整。
表格中有一个特定的列,工作人员在其中叙述付款或收据的性质。
写一些类似'PAYMENT OF SALARIES FOR THE MONTH OF NOVEMBER 2018'的东西。我希望能够有代码(ORACLE SQL),可以从这些叙述中挑选月份。
【问题讨论】:
您可以连续使用基于正则表达式的函数 (_replace,_substr,_count) 来提取月份名称,假设所有数据具有相同的格式模型以“月年”组合结尾
with t(str) as
(
select 'PAYMENT OF SALARIES FOR THE MONTH OF NOVEMBER 2018' from dual
), t2 as
(
select rtrim(str,regexp_replace(str,'(\D)')) as str
from t
), t3 as
(
select regexp_substr(str,'[^ ]+',1,level) as str,
regexp_count(str,'[^ ]+') as cnt,
level as lvl
from t2
connect by level <= regexp_count(str,'[^ ]+')
)
select str
from t3
where lvl = cnt;
STR
--------
NOVEMBER
【讨论】:
2018
即使您指定的文本格式相同,这也会起作用:
select * from (select rownum, regexp_substr("column1",'[^ ]+', 1, level) from Table1
connect by regexp_substr("column1", '[^ ]+', 1, level) is not null) where rownum<=8
minus
select * from (select rownum, regexp_substr("column1",'[^ ]+', 1, level) from Table1
connect by regexp_substr("column1", '[^ ]+', 1, level) is not null) where rownum<8;
【讨论】:
where
Date >= to_date(substr(:from_date ,1,10),'YYYY/MM/DD')
and
Date <= to_date(substr(:last_date,1,10),'YYYY/MM/DD')
【讨论】: