一个绑定变量的问题

    今天帮同学看了一个问题,属于细节问题,小记一下。

    问题:

    有个sql,放pl/sql developer里面执行没有问题,但是用myeclipse启动服务器,java代码用jdbcTemplate执行查询,就报ORA-00979: not a GROUP BY expression
的错误。
   

select
  trunc(tr.test_time, ?) time, round(avg(tr.latency), 0) latency
from
  zy_test_task_desc tk, Test_Result tr
where
  tk.agent_city = ?
  and tk.test_type = ?
  and tk.urlip = ?
  and tr.test_time >= to_date(?, 'yyyy-MM-dd hh24:mi:ss')
  and tr.test_time <= to_date(?, 'yyyy-MM-dd hh24:mi:ss')
  and tk.task_id in
  (
    select
      ct.task_id
    from
      user_auth t, customer_user cu, customer_task ct
    where
      t.password = ?
      and t.user_name = ?
      and t.user_id = cu.user_id
      and cu.customer_id = ct.customer_id
  )
  and tk.task_id = tr.task_id
GROUP BY trunc(tr.test_time, ?)

参数
DD,nj,1,219.141.104.14,2011/9/1 00:00:00,2011/9/30 23:59:59,123456,zzb1,DD

    看了半天没找到原因,后来还是同学找到根源所在。  问题出在trunc(tr.test_time, ?)上,如果不用动态参数,直接写成trunc(tr.test_time,'DD') mytime和GROUP BY trunc(tr.test_time,'DD')问题消失。这是为什么呢?


    原来,动态传递即使传递相同的参数,它也认为是不同的,导致认为查询字段和group by的字段不同故报错。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值