可能是一个愚蠢的错误,但我自己无法弄清楚。当我在Oracle 11g中运行此查询时。
如果这个问题在SO中得到了回答,请让我知道链接。
with LAST_BUSINESS_DAY as (select DECODE(to_char(last_day(to_date('29-mar-2013')), 'D'),
, '7', to_char((last_day('29-mar-2013') - 1), 'DD-MON-YYYY')
, '1', to_char((last_day('29-mar-2013') - 2), 'DD-MON-YYYY')
, to_char(last_day('29-apr-2013'), 'DD-MON-YYYY')) as LAST_BD from dual),
HOLIDAYS as (select distinct rpt_day
from rpt_days rpt left join
calendars cal on rpt.calendar_id = cal.calendar_id
where rpt.type = 2
and cal.group = 4)
select case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D')
, '6', LAST_BD
, '2', LAST_BD
, LAST_BD)
end as LAST_BD_OF_MONTH
from LAST_BUSINESS_DAY LBD
inner join HOLIDAYS H on LBD.LAST_BD = H.rpt_day
我得到的结果是
LAST_BD_OF_MONTH
===================
29-MAR-2013
现在,当我试图在最后一天添加一天时,它抛出了一个错误。
with LAST_BUSINESS_DAY as (select DECODE(to_char(last_day(to_date('29-mar-2013')), 'D'),
, '7', to_char((last_day('29-mar-2013') - 1), 'DD-MON-YYYY')
, '1', to_char((last_day('29-mar-2013') - 2), 'DD-MON-YYYY')
, to_char(last_day('29-apr-2013'), 'DD-MON-YYYY')) as LAST_BD from dual),
HOLIDAYS as (select distinct rpt_day
from rpt_days rpt left join
calendars cal on rpt.calendar_id = cal.calendar_id
where rpt.type = 2
and cal.group = 4)
select case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D') -- line 35
, '6', LAST_BD - 1 -- CHANGED THIS
, '2', LAST_BD + 1 -- CHANGED THIS
, LAST_BD)
end as LAST_BD_OF_MONTH
from LAST_BUSINESS_DAY LBD
inner join HOLIDAYS H on LBD.LAST_BD = H.rpt_day
错误消息
ORA-00932:不一致的数据类型:应为CHAR get NUMBER
00932。00000-“不一致的数据类型:预期%s得到%s”*原因:
*操作:第35行错误列:20
正如我所说,这可能是我方面的一个简单疏忽。我尝试将最后一个BD转换为日期,但没有成功。
我试着如下更改解码
case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D')
, '6', to_date(LAST_BD, 'DD-MON-YYYY') - 1
, '2', LAST_BD + 1 -- line 37
, LAST_BD)
end as LAST_BD_OF_MONTH
得到了这个错误:
ORA-00932:不一致的数据类型:预期日期得到编号
00932. 00000-"不一致的数据类型:预期%s得到%s"*原因:
*操作:第37行错误列:42
所以,我把第37行
改成了这个,
case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D')
, '6', to_date(LAST_BD, 'DD-MON-YYYY') - 1
, '2', to_date(LAST_BD, 'DD-MON-YYYY') + 1
, LAST_BD)
end as LAST_BD_OF_MONTH
这一次是另一个信息。
ORA-00932:不一致的数据类型:预期CHAR得到日期
00932. 00000-"不一致的数据类型:预期%s得到%s"*原因:
*操作:第35行错误列:20
非常感谢任何帮助纠正这一点。
答案:
with LAST_BUSINESS_DAY as (select DECODE(to_char(last_day(to_date('29-mar-2013')), 'D'),
, '7', to_char((last_day('29-mar-2013') - 1), 'DD-MON-YYYY')
, '1', to_char((last_day('29-mar-2013') - 2), 'DD-MON-YYYY')
, to_char(last_day('29-apr-2013'), 'DD-MON-YYYY')) as LAST_BD from dual),
HOLIDAYS as (select distinct rpt_day
from rpt_days rpt left join
calendars cal on rpt.calendar_id = cal.calendar_id
where rpt.type = 2
and cal.group = 4)
select case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D')
, '6', to_char (to_date(LAST_BD, 'DD-MON-YYYY') - 1, 'DD-MON-YYYY')
, '2', to_char (to_date(LAST_BD, 'DD-MON-YYYY') + 1, 'DD-MON-YYYY')
, LAST_BD)
end as LAST_BD_OF_MONTH
from LAST_BUSINESS_DAY LBD
inner join HOLIDAYS H on LBD.LAST_BD = H.rpt_day
Oracle似乎要求case结构的all-then表达式的类型与first-then之后的表达式的类型一致<不执行类型转换。
问题是,DECODE需要某种类型的CHAR参数,甚至是TO\u DATE(LAST\u BD…分别返回一个数字和一个日期。
下面的SQL Fiddle演示了如何修复此问题。
http://sqlfiddle.com/#!4/8ac4a3/9
以下是查询:
with LAST_BUSINESS_DAY as (select DECODE(to_char(last_day(to_date('29-mar-2013')), 'D')
, '7', to_char((last_day('29-mar-2013') - 1), 'DD-MON-YYYY')
, '1', to_char((last_day('29-mar-2013') - 2), 'DD-MON-YYYY')
, to_char(last_day('29-apr-2013'), 'DD-MON-YYYY')) as LAST_BD from dual),
HOLIDAYS as (select distinct reporting_day
from tbm_reporting_days trdy left join
tbm_calendars tcal on trdy.calendar_id = tcal.calendar_id
where trdy.type = 2
and tcal.site_id = 4)
select case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D')
, '6', TO_CHAR(
(TO_DATE(LAST_BD, 'DD-MON-YYYY') - 1), 'D')
, '2', TO_CHAR(
(TO_DATE(LAST_BD, 'DD-MON-YYYY') - 1), 'D')
, LAST_BD)
end as LAST_BD_OF_MONTH
from LAST_BUSINESS_DAY LBD
inner join HOLIDAYS H on LBD.LAST_BD = H.reporting_day
您必须将数字或日期转换回具有TO_CHAR的CHAR。
所以我看得对吗,你把VARCHAR2转换成DATE(由于):
to_date(LAST_BD, 'DD-MON-YYYY')
在第二个查询中,您尝试从这个VARCHAR2中减去1:
LAST_BD - 1
这行不通。因此,您会得到错误:
ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
可能起作用的是,如果您将其转换为DATE
,添加1
并将其转换回VARCHAR2
with LAST_BUSINESS_DAY as (select DECODE(to_char(last_day(to_date('29-mar-2013')), 'D'),
, '7', to_char((last_day('29-mar-2013') - 1), 'DD-MON-YYYY')
, '1', to_char((last_day('29-mar-2013') - 2), 'DD-MON-YYYY')
, to_char(last_day('29-apr-2013'), 'DD-MON-YYYY')) as LAST_BD from dual),
HOLIDAYS as (select distinct rpt_day
from rpt_days rpt left join
calendars cal on rpt.calendar_id = cal.calendar_id
where rpt.type = 2
and cal.group = 4)
select case when to_char(to_date(LAST_BD, 'DD-MON-YYYY'), 'D') is null
then LAST_BD
else DECODE(to_char(to_date(LAST_BD, 'DD-MON-YYYY') , 'D') -- line 35
, '6', to_char (to_date(LAST_BD, 'DD-MON-YYYY') - 1, 'DD-MON-YYYY')
, '2', to_char (to_date(LAST_BD, 'DD-MON-YYYY') + 1, 'DD-MON-YYYY')
, LAST_BD)
end as LAST_BD_OF_MONTH
from LAST_BUSINESS_DAY LBD
inner join HOLIDAYS H on LBD.LAST_BD = H.rpt_day
请注意,需要转换回VARCHAR2
,因为DECODE
只允许一种类型的值。
我有这个查询我试图运行,但我一直遇到这个错误。我正在尝试执行一个子句,将数据(BLOB列)与:var2(这是一个blob对象)进行比较。 这是我的密码。 对于为什么我会得到这个错误有什么建议吗? 我正在将与进行比较,这不是很好吗? 谢谢
我正在user_views上运行一个查询。“TEXT”列是LONG数据类型的。所以,当我在where子句中使用该列时,我得到了预期的错误。 错误:ORA-00932:不一致的数据类型:预期数过长 查询是 这个怎么解决?
思维方式 逻辑是,如果订单被取消,则返回0,否则返回欠款-支付价值 小查询 获取错误 ORA-00932:不一致的数据类型:预期的字符数为00932。00000-“不一致的数据类型:预期的%s得到了%s”*原因: *操作:第25行错误列:58
我正在使用。NET中的Oracle数据访问,我的查询如下 我得到以下错误“ORA-00932:不一致的数据类型:预期的日期得到的数字”
我在ubuntu 14.04LTS上使用oracle 11g。我有一个名为成员的表,我由以下sql创建, 后来我更新了这个表格, 现在,当我运行“DESC members”时,它会显示结果, 最后,我运行了这样的插入sql, 它显示了错误, 第1行错误:ORA-00932:数据类型不一致:预期数字为二进制 有人能帮我解决问题吗?而且我也不确定在这个过程中我是否可以添加图像或路径的二进制文件。有人能