oracle - ORA-00932: inconsistent datatypes: expected CHAR got NUMBER while adding 1 to a date -
probably silly mistake, couldn't figure out myself. when run query in oracle 11g.
if question answered in so, please let me know link.
with last_business_day (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')) last_bd dual), holidays (select distinct rpt_day rpt_days rpt left join calendars cal on rpt.calendar_id = cal.calendar_id rpt.type = 2 , cal.group = 4) select case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null last_bd else decode(to_char(to_date(last_bd, 'dd-mon-yyyy') , 'd') , '6', last_bd , '2', last_bd , last_bd) end last_bd_of_month last_business_day lbd inner join holidays h on lbd.last_bd = h.rpt_day
i result
last_bd_of_month =================== 29-mar-2013
now, when try add day last_bd
date, throws error.
with last_business_day (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')) last_bd dual), holidays (select distinct rpt_day rpt_days rpt left join calendars cal on rpt.calendar_id = cal.calendar_id rpt.type = 2 , cal.group = 4) select case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null last_bd else decode(to_char(to_date(last_bd, 'dd-mon-yyyy') , 'd') -- line 35 , '6', last_bd - 1 -- changed , '2', last_bd + 1 -- changed , last_bd) end last_bd_of_month last_business_day lbd inner join holidays h on lbd.last_bd = h.rpt_day
error message
ora-00932: inconsistent datatypes: expected char got number
00932. 00000 - "inconsistent datatypes: expected %s got %s" *cause:
*action: error @ line: 35 column: 20
as said, might simple overlook side. tried converting last_bd
date
, didn't work.
i tried changing decode
below
case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null 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 last_bd_of_month
and got error :
ora-00932: inconsistent datatypes: expected date got number
00932. 00000 - "inconsistent datatypes: expected %s got %s" *cause:
*action: error @ line: 37 column: 42
so, changed line 37
this,
case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null 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 last_bd_of_month
and time different message.
ora-00932: inconsistent datatypes: expected char got date
00932. 00000 - "inconsistent datatypes: expected %s got %s" *cause:
*action: error @ line: 35 column: 20
any corrected appreciated.
answer :
with last_business_day (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')) last_bd dual), holidays (select distinct rpt_day rpt_days rpt left join calendars cal on rpt.calendar_id = cal.calendar_id rpt.type = 2 , cal.group = 4) select case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null 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 last_bd_of_month last_business_day lbd inner join holidays h on lbd.last_bd = h.rpt_day
so see right, converted last_bd
from varchar2
date
(due to):
to_date(last_bd, 'dd-mon-yyyy')
in second query try subtract 1
varchar2
:
last_bd - 1
this won't work. consequence error:
ora-00932: inconsistent datatypes: expected char got number
what work is, if convert date
, add 1
, convert varchar2
with last_business_day (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')) last_bd dual), holidays (select distinct rpt_day rpt_days rpt left join calendars cal on rpt.calendar_id = cal.calendar_id rpt.type = 2 , cal.group = 4) select case when to_char(to_date(last_bd, 'dd-mon-yyyy'), 'd') null 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 last_bd_of_month last_business_day lbd inner join holidays h on lbd.last_bd = h.rpt_day
note conversion varchar2
required, because decode
allows values of 1 type.
Comments
Post a Comment