我正在尝试使用Oracle SQL Developers SQL Tuning Advisor将日期绑定到变量,但是它将日期识别为VARCHAR2
而不是DATE
。有没有办法指定您绑定的参数的数据类型?
SQL:
SELECT * FROM Actv
WHERE ActvId = :in_UserGrpCds AND ActvTime >= :in_FromDate AND ActvTime < :in_ThruDate
OFFSET :in_CurrRecordOffset FETCH NEXT :in_NextRecordOffset ROWS ONLY;
in_ThruDate
被绑定为VARCHAR2
,它无法运行曲调。
Bind Variables :
1 - (NUMBER):1091
2 - (NUMBER):0
3 - (VARCHAR2):07-21-2018
4 - (NUMBER):50000
5 - (VARCHAR2):08-21-2018
-------------------------------------------------------------------------------
ERRORS SECTION
-------------------------------------------------------------------------------
- ORA-00932: inconsistent datatypes: expected DATE got NUMBER
-------------------------------------------------------------------------------
答案 0 :(得分:4)
我们仅绑定字符串/数字/空值,因此请调整您的SQL以包含to_date:
SELECT * FROM Actv
WHERE ActvId = :in_UserGrpCds
AND ActvTime >= to_date(:in_FromDate ,'MM-DD-YYYY')
AND ActvTime < to_date(:in_ThruDate ,'MM-DD-YYYY')
OFFSET :in_CurrRecordOffset FETCH NEXT :in_NextRecordOffset ROWS ONLY;