txt_sql:='select a.agentcode, a.otherno,a.paydate,a.EnterAccDate,a.paymoney,
                    a.StandPrem,substr(a.RISKCODE,3,3) from HZH.H_LJTEMPFEE a,hzh.h_laagent b,
                    hzh.h_labranchgroup c,hzh.h_ldcom d where a.paydate between ' || to_date(trandate_s,'YYYYMMDD')
                    ||'and'|| to_date(trandate_e,'YYYYMMDD') ||'and a.othernotype in (6) and a.agentcode=b.agentcode                    
                     and b.agentgroup=c.agentgroup and d.comcode=b.managecom order by d.name,c.name,a.agentcode';open cur_rp  for txt_sql;我这个语句在oracle中无法运行.请各位大侠帮忙
          

解决方案 »

  1.   

    select a.agentcode,
           a.otherno,
           a.paydate,
           a.EnterAccDate,
           a.paymoney,
           a.StandPrem,
           substr(a.RISKCODE, 3, 3)
      from HZH.H_LJTEMPFEE     a,
           hzh.h_laagent       b,
           hzh.h_labranchgroup c,
           hzh.h_ldcom         d
     where a.paydate between   to_date(trandate_s,'YYYY-MM-DD')
       
       and   to_date(trandate_e,'YYYYMMDD')  
       and a.othernotype in (6)
       and a.agentcode = b.agentcode
       and b.agentgroup = c.agentgroup
       and d.comcode = b.managecom
     order by d.name, c.name, a.agentcode
      

  2.   

    --这样
    txt_sql:='select a.agentcode, a.otherno,a.paydate,a.EnterAccDate,a.paymoney,
      a.StandPrem,substr(a.RISKCODE,3,3) from HZH.H_LJTEMPFEE a,hzh.h_laagent b,
      hzh.h_labranchgroup c,hzh.h_ldcom d where a.paydate between to_date(''' || trandate_s ||''',''YYYYMMDD'')'||
      ' and to_date('''||trandate_e||''',''YYYYMMDD'') and a.othernotype in (6) and a.agentcode=b.agentcode  
       and b.agentgroup=c.agentgroup and d.comcode=b.managecom order by d.name,c.name,a.agentcode';
      

  3.   

    --最好使用绑定变量方式,性能更好
    txt_sql:='select a.agentcode, a.otherno,a.paydate,a.EnterAccDate,a.paymoney,
      a.StandPrem,substr(a.RISKCODE,3,3) from HZH.H_LJTEMPFEE a,hzh.h_laagent b,
      hzh.h_labranchgroup c,hzh.h_ldcom d where a.paydate between to_date(:trandate_s,''YYYYMMDD'')
      and to_date(:trandate_e,''YYYYMMDD'') and a.othernotype in (6) and a.agentcode=b.agentcode  
      and b.agentgroup=c.agentgroup and d.comcode=b.managecom order by d.name,c.name,a.agentcode';open cur_rp for txt_sql using trandate_s,trandate_e;
      

  4.   

       agent_kind:='in (86230201)'; 
     trandate_0:=to_date(i_trandate,'YYYY-MM-DD');--由于直接引用传递变量不行,所以加了些变量
     if i_flag2='0' then 
         trandate_s:=to_char(trandate_0,'YYYY')*10000+to_char(trandate_0,'MM')*100+1;
         trandate_e:=to_char(trandate_0,'YYYY')*10000+to_char(trandate_0,'MM')*100+to_char(trandate_0,'DD');
     
    txt_sql:='select a.agentcode, a.otherno,a.paydate,a.EnterAccDate,a.paymoney,
      a.StandPrem,substr(a.RISKCODE,3,3) from HZH.H_LJTEMPFEE a,hzh.h_laagent b,
      hzh.h_labranchgroup c,hzh.h_ldcom d where a.paydate between to_date(:trandate_s,''YYYYMMDD'')
      and to_date(:trandate_e,''YYYYMMDD'') and a.othernotype in ("6") and a.agentcode=b.agentcode  
      and b.agentgroup=c.agentgroup and d.comcode=b.managecom and b.managecom :agent_kind order by d.name,c.name,a.agentcode';open cur_rp for txt_sql;
    我再增加一条 b.mnagecom in (86230201) 把in (86230201)换成变量b.managecom :agent_kind 就报错麻烦大家再帮我一下.多谢!
      

  5.   

    如果b.managecom like ('862302%')又如何用变量描述呢?