I have the following overloaded function in a oracle (10g) package.
function fnDaysFromNowToDate(dd_mon_yyyy date) return number is days number;
--d2 varchar2(11):=to_char(sysdate,ddf);
Begin
dbms_output.put_line( 'd='|| to_date(dd_mon_yyyy,'dd-mon-yyyy'));
dbms_output.put_line( 's='|| to_date(sysdate,'dd-mon-yyyy'));
return trunc(dd_mon_yyyy-trunc(sysdate));
--return 1;
end;
--- overload for varchar
function fnDaysFromNowToDate(dd_mon_yyyy varchar2) return number is days number;
Begin
dbms_output.put_line( 'd='|| to_date(dd_mon_yyyy,'dd-mon-yyyy'));
dbms_output.put_line( 's='|| to_date(sysdate,'dd-mon-yyyy'));
return trunc(to_date(dd_mon_yyyy,'dd-mon-yyyy')-trunc(sysdate));
end;
And both of them work fine when executed within Oracle Sql Developer, like so
select t$stdt,to_char(t$tdat,'dd-Mon-YYYY') t$tdat, t$cuno,T$CPGS,T$QANP,T$DISC
from baan.ttdsls031020
where
trim(t$cuno) = '000811'
and pkgUtils.fnDaysFromNowToDate(to_char(t$tdat,'dd-Mon-YYYY')) > 1
and t$qanp = pkgPriceWorx.fndefaultQanp
and trim(t$cpgs) = '1AM00';
but when I execute same query through SQL linked server using OraOLEDB.Oracle provider
select * from openquery(hades,"
select t$stdt,to_char(t$tdat,'dd-Mon-YYYY') t$tdat, t$cuno,T$CPGS,T$QANP,T$DISC
from baan.ttdsls031020
where
trim(t$cuno) = '000811'
and pkgUtils.fnDaysFromNowToDate(to_char(t$tdat,'dd-Mon-YYYY')) > 1
and t$qanp = pkgPriceWorx.fndefaultQanp
and trim(t$cpgs) = '1AM00'
");
the following errors are thrown
OLE DB provider "OraOLEDB.Oracle" for linked server "hades" returned message
ORA-01861: literal does not match format string
ORA-06512: at "SAAP.PKGUTILS", line 29". OLE DB provider "OraOLEDB.Oracle" for linked server "hades" returned message "ORA-01861: literal does not match format string ORA-06512: at "SAAP.PKGUTILS", line 29". .Net SqlClient Data Provider: Msg 7320, Level 16, State 2, Line 3 Cannot execute the query " select t$stdt,to_char(t$tdat,'dd-Mon-YYYY') t$tdat, t$cuno,T$CPGS,T$QANP,T$DISC from baan.ttdsls031020 where trim(t$cuno) = '000811' and pkgUtils.fnDaysFromNowToDate(to_char(t$tdat,'dd-Mon-YYYY')) > 1 and t$qanp = pkgPriceWorx.fndefaultQanp and trim(t$cpgs) = '1AM00' " against OLE DB provider "OraOLEDB.Oracle" for linked server "hades".*
Any idea why this behaviour ?