Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plsql oracle中varchar到数字的转换及比较_Plsql_Oracle11g - Fatal编程技术网

Plsql oracle中varchar到数字的转换及比较

Plsql oracle中varchar到数字的转换及比较,plsql,oracle11g,Plsql,Oracle11g,我在表中有两列,它们的数据类型都是varchar2。 现在,我希望根据输入值获取数据,并基于此,我的select查询如下所示: select fromtime, totime from temp_trd_shr where fromtime <= '08:00' and totime >='10:00' 时间:varchar250 totime:varchar250 08:00和10:00:字符串和格式中的输入值总是像xx:xx一样固定 甲骨文11g 我尝试使用to_

我在表中有两列,它们的数据类型都是varchar2。 现在,我希望根据输入值获取数据,并基于此,我的select查询如下所示:

    select fromtime, totime from temp_trd_shr where 
fromtime <= '08:00' and  totime >='10:00' 
时间:varchar250 totime:varchar250 08:00和10:00:字符串和格式中的输入值总是像xx:xx一样固定 甲骨文11g

我尝试使用to_号码,但我无法做到这一点

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
*/