很复杂,你的数据也太不规范了吧。
select max(substr(fieldName,length(fieldName),1) + lpad(substr(fieldName,1,length(fieldName) - 1),'0') )
不知道to_date能不能做到。
select max(substr(fieldName,length(fieldName),1) + lpad(substr(fieldName,1,length(fieldName) - 1),'0') )
不知道to_date能不能做到。
select to_date(substr(dtcol,1,length(dtcol)-1,'hh:mi')+decode(substr(dtcol,length(dt_col)),'P',12,0)/24 from tbname;
select to_date(substr(dtcol,1,length(dtcol)-1,'hh:mi')+decode(substr(dtcol,length(dt_col)),'P',0.5,0) from tbname;
SQL> select * from t_test;C1
----------
2:00A
11:40A
11:30P
3:00PSQL> select c1 from (select c1 from t_test order by to_date(replace(replace(c1,'P','下午'),'A','上午'),'hh:miAM') desc) where rownum=1;C1
----------
11:30P
select c1 from (select c1 from t_test order by to_date(c1||'M','hh:miAM') desc) where rownum=1;
(select col,rownum rn from t_test
order by substr(col,length(col)-1,1) desc,length(col) desc,col desc)
where rn=1
还是bobfang(匆匆过客)的好些,不然要在加层判断
-----错误
ora-01855:AM/A.M. or PM/P.M. required
====
前面的,不好意思,我们不考虑长度因素统一为’03:00a’之类,也不考虑12:00p的情况该怎么最方便的实现转换呢?to_char(Max(to_date(..)))?该怎么写呢?
我的方法也可以试一下
select max(substr(colname)||lpad(colname,'0',4)) from ...
左边填充0?
能解释以下吗?
max(substr(colname)||lpad(colname,'0',4))
参数不够
怎么区分a,p
难道还不成?====
我不希望用select 而是用函数实现啊,因为这是个复杂查询的一部分,我以前直接用MAX后来发现11:00A>02:00P