4

我需要将 FIRST/ SECOND /THIRD /FOURTH /FIFITH .... 转换为 1 2 3 4 5 .... oracle 中是否有函数。其他方式如下,但我想要相反

SELECT TO_CHAR(to_date(3,'J'), 'fmJSPTH') FROM dual;
4

1 回答 1

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

小提琴

于 2013-03-07T23:01:59.873 回答