本文介绍了Mybatis是否支持DDL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是一个数据库中心,例如PLSQL,但用于Web浏览器.有时我需要创建或更改一个表,但是我不知道Mybatis是否支持DDL,并且我还没有找到有关此文件的任何文档.

My project is a Database center, like PLSQL but used in a web browser. Sometimes I need to create or alter a table, but I don't know if Mybatis supports DDL, and I haven't found any documents about this.

推荐答案

在大多数情况下,DDL的工作方式与使用mybatis的DML一样.一个区别是您将需要使用$ {}而不是#{}作为参数.大多数数据库不支持使用DDL准备的语句. $表示法是字符串替换,而不是预准备语句的参数.

For the most part DDL works just like DML using mybatis. The one difference is that you will need to use ${} instead of #{} for parameters. Most databases do not support prepared statements with DDL. The $ notation is a string substitution rather than a parameter for a prepared statement.

<update id="exchangePartition" parameterType="java.util.Map">
    alter table ${destinationTableName}
    exchange partition ${destinationPartitionName}
    with table ${sourceTableName}
    including indexes
    with validation
</update>

了解具有可调用的语句类型以调用存储过程的调用语法也很有帮助.

It is also helpful to know the call syntax with the statement type callable to invoke stored procedures.

<update id="gatherStatistics" statementType="CALLABLE" parameterType="Map">
    {call
        dbms_stats.gather_table_stats(
            ownname => #{tableOwner},
            tabname => #{tableName}
            <if test="partitionName != null">
                , partname => #{partitionName}
            </if>
           )
    }
</update>

这篇关于Mybatis是否支持DDL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 09:25