17,086
社区成员
发帖
与我相关
我的任务
分享
with t1(bond_period) as
(
select '10年' bond_period from dual union all
select '5月' bond_period from dual union all
select '91日' bond_period from dual union all
select '3年4月' bond_period from dual union all
select '6年182日' bond_period from dual union all
select '6月23日' bond_period from dual union all
select '7年' bond_period from dual union all
select '1年' bond_period from dual union all
select '15月' bond_period from dual union all
select '20年' bond_period from dual union all
select '273日45' bond_period from dual union all
select '3月12' bond_period from dual union all
select '5年' bond_period from dual union all
select '30年' bond_period from dual union all
select '8年' bond_period from dual union all
select '50年123' bond_period from dual
)
, t2 as(
select bond_period, replace(replace(replace(bond_period,'年', '*365+'), '月', '*30+'), '日', '+') c1 from t1
)
select bond_period, c1, dbms_aw.eval_number(case when c1 like '%+' then substr(c1, 1, length(c1)-1) else c1 end) c2 from t2
--1.创建测试表
create table tmp as
select '10年' bond_period from dual union all
select '2年' bond_period from dual union all
select '91日14' bond_period from dual union all
select '3年15' bond_period from dual union all
select '182日' bond_period from dual union all
select '6月' bond_period from dual union all
select '7年' bond_period from dual union all
select '1年' bond_period from dual union all
select '15年' bond_period from dual union all
select '20年' bond_period from dual union all
select '273日' bond_period from dual union all
select '3月' bond_period from dual union all
select '5年' bond_period from dual union all
select '30年' bond_period from dual union all
select '8年' bond_period from dual union all
select '50年' bond_period from dual;
--2.sql实现
select bond_period,
decode(str,'年',num * 360 ,'月',num * 30,num) days
from(select bond_period,
regexp_substr(bond_period,'[0-9]+') num,
regexp_substr(bond_period,'[^0-9]+') str
from tmp
)
order by days