[英]CASE Statement in Groovy SQL
I have some Groovy code that calls the groovy Sql object: 我有一些Groovy代码来调用groovy Sql对象:
Sql sql = new Sql(dataSource)
sql.execute(insert)
It has worked fine in the past, but I now have some conditional logic that I tried to model with a CASE statement like CASE WHEN a.pick = ${somevalue} THEN ${100} ELSE 0 END CASE"
过去效果不错,但现在我有了一些条件逻辑,我尝试使用CASE语句进行建模,例如
CASE WHEN a.pick = ${somevalue} THEN ${100} ELSE 0 END CASE"
However, I get a runtime error that says it doesn't recognize a
, but I believe it to be a symptom of the fact that it doesn't recognize the CASE statement in general, as a
is recognized elsewhere in the query and is nothing new. 不过,我得到的是说,它不承认一个运行时错误
a
,但我相信这是一个事实,即它不承认在一般的CASE语句,症状为a
在查询其他地方的认可,是什么新。 How can I accomplish this? 我该怎么做? Thanks.
谢谢。
I'm guessing that this may be an issue with your mysql syntax but I can't confirm because it is not provided. 我猜想这可能与您的mysql语法有关,但由于无法提供,因此无法确认。 Alternatively but, not that elegant;
或者,但不是那么优雅; you could handle this with groovy...
您可以通过常规处理此问题...
def sqlInsert = "insert into foo (bar) values (${(foo.pick == someValue)? 100 : 0})"
However , first you should printing your failing query and run it in MySQL directly to see if it's a syntax issue first. 但是 ,首先,您应该打印失败的查询并直接在MySQL中运行它,以首先查看它是否是语法问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.