【问题标题】:Update record with clause IN使用子句 IN 更新记录
【发布时间】:2021-11-19 15:30:01
【问题描述】:

我正在使用 Grails 4.0.12,我正在尝试使用 IN 子句进行更新,这是我的简单代码:

def rowId="100,101"
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowId])

如果我这样构建查询字符串,一切正常:

 Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in ("+ids+")")

在第一个示例中,我遇到了这个错误:

java.lang.String 无法转换为 java.lang.Long

如果我只传递一个没有 IN 子句的 Id,这似乎是合理的。

【问题讨论】:

    标签: hibernate grails grails-orm


    【解决方案1】:

    尝试通过以下方式更正您的第一个示例:

    def rowIds = [100, 101]
    Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowIds])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 2020-07-26
      相关资源
      最近更新 更多