我需要将FIRST / SECOND / THIRD / FOURTH / FIFTH转换为1 2 3 4 5 .... 在oracle中是否有一个函数。 其他方式可以如下,但我想反向
SELECT TO_CHAR(to_date(3,'J'), 'fmJSPTH') FROM dual;
答案 0 :(得分:5)
好问题!
create table t (w varchar2(30));
insert into t values ('First');
insert into t values ('THIRD');
insert into t values ('eleventh');
insert into t values ('Twenty-eighth');
insert into t values ('two hundred fifty sixth');
select
t.w, dict.n
from t
left join (
select
level n,
regexp_replace(to_char(to_date(level,'J'),'fmJSPTH'),'[^A-Z]') w
FROM dual
connect by level <= 1000
) dict on regexp_replace(upper(t.w),'[^A-Z]')=dict.w