简体   繁体   English

如何查看myBatis真正使用的SQL查询?

[英]How can I look at the SQL query really used by myBatis?

The query, created by myBatis, falls with the cause ORA-00933, "SQL command not properly ended".该查询由 myBatis 创建,其原因为 ORA-00933,“SQL 命令未正确结束”。

All advice that I found on the net, says that there is some error in the SQL syntax.我在网上找到的所有建议都说 SQL 语法中存在一些错误。 On the other hand, if I make the SQL by hand, Oracle SQL developer takes it as a correct one.另一方面,如果我手工制作 SQL,Oracle SQL 开发人员会将其视为正确的。

Obviously, I am making it by hand differently that myBatis does.显然,我手工制作的方式与 myBatis 不同。 And I need to check it.我需要检查一下。 But how can I check the SQL query really sent by myBatis to the DB?但是如何检查myBatis真正发送给数据库的SQL查询呢?

The MyBatis version used: 3.0使用的 MyBatis 版本:3.0


I am interested much more in the possibility to look for problems myself than to look for help with every problem.我对自己寻找问题的可能性更感兴趣,而不是为每个问题寻求帮助。 But some people here think that the question must contain the code, so here it is.但是这里有些人认为问题一定包含代码,所以在这里。 (mapper.xml) (mapper.xml)

<sql id="pracovisteSql">
    /* pozor, pracuje pouze do max 3 vrstev v cis_pracovist */
    cis_pracoviste A
        join cis_pracoviste B
            on (A.stupen_rizeni in (0,1) and B.kod_nadrizeneho = A.kod_pracoviste) or
                (A.stupen_rizeni = 2 and A.kod_pracoviste = B.kod_pracoviste)
        join cis_pracoviste C
            on (B.stupen_rizeni = 1 and C.kod_nadrizeneho = B.kod_pracoviste) or
                (B.stupen_rizeni = 2 and C.kod_pracoviste = B.kod_pracoviste)
</sql>
<sql id="organizaceSql">
    WITH organizace
    AS (
        SELECT a.kod_pracoviste as AKP, a.nazev as ANZ, a.stupen_rizeni as AST, a.kod_nadrizeneho as ANR,
                b.kod_pracoviste as BKP, b.nazev as BNZ, b.stupen_rizeni as BST, b.kod_nadrizeneho as BNR,
                c.kod_pracoviste as CKP, c.nazev as CNZ, c.stupen_rizeni as CST, c.kod_nadrizeneho as CNR
            from
            <include refid="pracovisteSql"/>
    )
</sql>
<sql id="zahajeniOdDo">
    (r01.dat_zahajeni between to_date(#{mesicRokOd}, 'MMYYYY') and to_date(#{mesicRokDo, 'MMYYYY'))
</sql>
<select id="getReportSR02Sql1"
        parameterType="amcssz.spr.srv.main.dto.reports.ReportSR02QueryDTO"
        resultType="amcssz.spr.srv.main.dto.reports.ReportSR02Sql1DTO">
    <include refid="organizaceSql"/>
    SELECT Count(Distinct (r01.id_r01_rizeni)) as pocetVRSP     
        From organizace
            Left join r01_rizeni r01
                on organizace.ckp = r01.kod_pracoviste and
                    r01.je_stornovano = 0 and
                    <include refid="zahajeniOdDo"/> and
                    r01.kod_skup_rizeni = 'VRSP'                  /* r01.kod_rizeni in ('VRSPUC', 'VRSPSR', 'VRSPPE', 'VRSPJI') */
            Join r02_stavrizeni r02
                on R01.ID_R01_RIZENI = R02.ID_R01_RIZENI and      /* Změna 17.1.2020 */
                R02.JE_AKTUALNI = '1' and
                R02.KOD_STAV_RIZENI != 'STR'
            Join r08_ukon r08
                on R01.ID_R01_RIZENI = R08.ID_R01_RIZENI and      /* Změna 17.1.2020 */
                R08.KOD_UKON IN ('1','14','23','32') and          
                R08.JE_STORNOVAN = '0'
            Join d02_obalka d02
                on R08.ID_R08_UKON = D02.ID_R08_UKON and          
                d02.dat_doruceni   IS NOT NULL                    
        Where organizace.AKP = #{kodPracoviste} and
            r01.kod_skup_rizeni is Not Null
        Group by r01.kod_skup_rizeni
        Order by 1;
</select>

You can configure your log4j level to show the mybatis logging like log4j.logger.org.mybatis.example=DEBUG您可以配置您的 log4j 级别以显示log4j.logger.org.mybatis.example=DEBUG日志记录,例如log4j.logger.org.mybatis.example=DEBUG

Full documentation will be found here这里可以找到完整的文档

如果你使用intellij idea,尝试添加一个插件mybatis-log-plugin ,执行的SQL会在控制台输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM