为什么此查询因ORA-1722失败(数字无效)

时间:2014-09-21 13:09:27

标签: sql oracle

在包

中执行时,以下查询因ORA-1722而失败
sQ:='Select * 
       from baan.TTDSLS031010  
      where t$cuno = :cuno
        and trim(t$cpgs) = Trim(:cpgs) 
        and to_char(t$tdat,:dfmt) >= to_char(:stdt,:dfmt)
        and to_char(t$stdt,:dfmt) = to_char( (select max(t$stdt) 
                                                from baan.TTDSLS031010 
                                               where t$cuno = :cuno 
                                                 and trim(t$cpgs) = trim(:cpgs))
                                           ,:dfmt )';      
 execute immediate sq 
    into r31 
   using cuno,cpgs,dfmt,stdt,dfmt,dfmt,cuno,cpgs,dfmt;

但作为匿名阻止执行是成功的。

set serveroutput on

Declare sq varchar2(3000);
  R31  BAAN.TTDSLS031010%rowtype;
  cuno varchar2(6) := '000120';
  cpgs varchar2(6) := '1AB00';
  stdt date := '2014-09-22';
  dfmt varchar2(15) := 'YYYY-MM-DD';
Begin
  sQ:='Select * 
         from baan.TTDSLS031010  
        where t$cuno = :cuno
          and trim(t$cpgs) = Trim(:cpgs) 
          and to_char(t$tdat,:dfmt) >= to_char(:stdt,:dfmt)
          and to_char(t$stdt,:dfmt) = to_char( (select max(t$stdt)
                                                  from baan.TTDSLS031010
                                                 where t$cuno = :cuno 
                                                   and trim(t$cpgs) = trim(:cpgs))
                                              ,:dfmt)';      
   execute immediate sq 
      into r31 
     using cuno,cpgs,dfmt,stdt,dfmt,dfmt,cuno,cpgs,dfmt;

   dbms_output.put_line('R31.cuno='||r31.t$cuno);
end; 

可能出现什么问题?

0 个答案:

没有答案