很复杂,你的数据也太不规范了吧。
select max(substr(fieldName,length(fieldName),1) + lpad(substr(fieldName,1,length(fieldName) - 1),'0') )
不知道to_date能不能做到。

解决方案 »

  1.   


    select to_date(substr(dtcol,1,length(dtcol)-1,'hh:mi')+decode(substr(dtcol,length(dt_col)),'P',12,0)/24 from tbname;
      

  2.   

    稍微处理一下
    select to_date(substr(dtcol,1,length(dtcol)-1,'hh:mi')+decode(substr(dtcol,length(dt_col)),'P',0.5,0) from tbname;
      

  3.   

    如果数据库的语言环境是中文,这样做
    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
      

  4.   

    如果是英文环境则更简单些
    select c1 from (select c1 from t_test order by to_date(c1||'M','hh:miAM') desc) where rownum=1;
      

  5.   

    select col from
    (select col,rownum rn from t_test
    order by substr(col,length(col)-1,1) desc,length(col) desc,col desc)
    where rn=1
      

  6.   

    不能这么比较,12:00P 是上午12点。
    还是bobfang(匆匆过客)的好些,不然要在加层判断
      

  7.   

    select to_date('10:20AM','hh:miAM') from test_table;
    -----错误
    ora-01855:AM/A.M. or PM/P.M. required
      

  8.   

    select to_date('10:20上午','hh:miAM') from test_table;
      

  9.   

    天纳,那不是更麻烦,我要把A,转换成上午,p转换成下午,再转回来?
    ====
    前面的,不好意思,我们不考虑长度因素统一为’03:00a’之类,也不考虑12:00p的情况该怎么最方便的实现转换呢?to_char(Max(to_date(..)))?该怎么写呢?
      

  10.   

    bobfang(匆匆过客) 就可以
    我的方法也可以试一下
      

  11.   

    我不希望用select 而是用函数实现啊,因为这是个复杂查询的一部分,我以前直接用MAX后来发现11:00A>02:00P
      

  12.   

    try:
    select max(substr(colname)||lpad(colname,'0',4)) from ...
      

  13.   

    select max(substr(colname)||lpad(colname,'0',4)) from ...
    左边填充0?
    能解释以下吗?
    max(substr(colname)||lpad(colname,'0',4))
    参数不够
      

  14.   

    sorry漏掉了max(substr(colname,length(colname))||lpad(colname,'0',4))
      

  15.   

    不好意思,我还是没明白lpad(colname,'0',4))有什么用?
    怎么区分a,p
      

  16.   

    你不考虑12:00P就用我的撒
    难道还不成?====
    我不希望用select 而是用函数实现啊,因为这是个复杂查询的一部分,我以前直接用MAX后来发现11:00A>02:00P