db2 如何在现有的Hql或SQL查询中应用“With UR”子句?我如何在Java文件中追加此子句,其中我的查询是字符串格式

yc0p9oo0  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(236)

因此,我在其中一个Java文件中包含了以下SQL查询:(我给的是样品&不是真实的的)

@Query( "Select T1.ID" +
    ", T1.CD" +
    ", T1.Date" +
    ", T1.Name" +
    " From Table1 T1" +
    " Join Table2 T2 " +
    " On T1.ID = T2.ID" +
    " Where T1.CD in 
    ("test1","test2")" +
    " And NOT EXISTS" +
    "      (Select 1 From Table2 T3" 
    +
    "       Where T3.ID = T1.ID +
    "       And T3.Name NOT 
    IN('P','Q','R')"+
    "    )")
    List<Object[]> methodToRetrieve 
    (@Param("sequence")String 
    sequence,@Param("code") code);

有人能告诉我在上面的查询中哪里可以添加“With UR”吗?

xmd2e60i

xmd2e60i1#

PSA:在你的帖子中包括你的Db2平台/版本;如果适用,还可以考虑使用特定于平台的db2标记(db2-luw或db2 i)
在文档x1c 0d1x中,isolation-clause出现在fullselect之后
因此您代码应该是

@Query( "Select T1.ID" +
    ", T1.CD" +
    ", T1.Date" +
    ", T1.Name" +
    " From Table1 T1" +
    " Join Table2 T2 " +
    " On T1.ID = T2.ID" +
    " Where T1.CD in 
    ("test1","test2")" +
    " And NOT EXISTS" +
    "      (Select 1 From Table2 T3" 
    +
    "       Where T3.ID = T1.ID +
    "       And T3.Name NOT 
    IN('P','Q','R')"+
    "    ) WITH UR")
    List<Object[]> methodToRetrieve 
    (@Param("sequence")String 
    sequence,@Param("code") code);

相关问题