【问题标题】:Conversion of varchar to Number and make comparasion in oracle将varchar转换为Number并在oracle中进行比较
【发布时间】:2013-06-09 19:49:39
【问题描述】:

我在表中有两列的数据类型均为 varchar2。 现在我想根据输入值获取数据,基于此我的选择查询如下所示:

    select fromtime, totime from temp_trd_shr where 
fromtime <= '08:00' and  totime >='10:00' 

从时间:varchar2(50) 时间:varchar2(50) 08:00 & 10:00 : 输入值(在字符串和甲酸盐中总是像 xx:xx 一样固定) 甲骨文11g

我尝试使用 to_number 但我无法做到这一点。

【问题讨论】:

    标签: plsql oracle11g


    【解决方案1】:
    CREATE TABLE temp_trd_shr
    (
        fromtime VARCHAR2(5)
    ,   totime   VARCHAR2(5)
    );
    
    INSERT INTO temp_trd_shr VALUES ('01:00', '18:00');
    INSERT INTO temp_trd_shr VALUES ('02:00', '17:00');
    INSERT INTO temp_trd_shr VALUES ('03:00', '16:00');
    INSERT INTO temp_trd_shr VALUES ('04:00', '15:00');
    INSERT INTO temp_trd_shr VALUES ('05:00', '14:00');
    INSERT INTO temp_trd_shr VALUES ('06:00', '13:00');
    
    INSERT INTO temp_trd_shr VALUES ('08:30', '09:30');
    INSERT INTO temp_trd_shr VALUES ('08:45', '09:45');
    
    SELECT  COUNT(*)
    FROM    temp_trd_shr;
    -- 8
    
    SELECT  *
    FROM    temp_trd_shr
    WHERE   TO_NUMBER(REPLACE(fromtime, ':')) <= TO_NUMBER(REPLACE('08:00', ':'))
    AND     TO_NUMBER(REPLACE(totime,   ':')) >= TO_NUMBER(REPLACE('10:00', ':'))
    ORDER   BY
            1
    ;
    /*
    01:00   18:00
    02:00   17:00
    03:00   16:00
    04:00   15:00
    05:00   14:00
    06:00   13:00
    */
    

    【讨论】:

      猜你喜欢
      • 2014-04-04
      • 2016-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多