我在oracle存储过程中有一个引起问题的查询。
Select *
from my_table
where TO_CHAR(TO_DATE(billing_date,'DD-MON-YY',NLS_DATE_LANGUAGE=English'),'YYYY-MM-DD') ='2018-06-1';我得到ORA-01861:文字不匹配格式字符串。
我的billing_date的日期类似于01-6月18日,它是一个日期类型列
我正在使用Python中的cx_Oracle执行这个存储过程。
发布于 2020-01-20 11:38:54
阅读您的代码,billing_date列的数据类型似乎是varchar2。如果是这样,这可能会有帮助:
SQL> with my_table (id, billing_date) as
2 (select 1, '20-jan-20' from dual union all
3 select 2, '16-jun-19' from dual union all
4 select 3, '01-jun-18' from dual
5 )
6 select *
7 from my_table
8 where billing_date = to_char(date '2018-06-01', 'dd-mon-yy', 'nls_date_language = english');
ID BILLING_D
---------- ---------
3 01-jun-18
SQL>另一方面,如果billing_date是date,那么它就变得更简单了:
SQL> with my_table (id, billing_date) as
2 (select 1, date '2020-01-20' from dual union all
3 select 2, date '2019-06-16' from dual union all
4 select 3, date '2018-06-01' from dual
5 )
6 select *
7 from my_table
8 where billing_date = date '2018-06-01';
ID BILLING_
---------- --------
3 01.06.18
SQL>发布于 2020-01-20 11:38:21
只需按以下方式使用日期:
Select * from my_table where billing_date = date'2018-06-01';考虑到您的billing_date是日期类型列。
干杯!!
https://stackoverflow.com/questions/59822402
复制相似问题