Does Mybatis support DDL?

假装没事ソ 提交于 2020-01-04 04:35:29

问题


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.


回答1:


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>



回答2:


MyBatis supports any native SQL/PlSql commands. So yes, it supports DDL statements.



来源:https://stackoverflow.com/questions/18786560/does-mybatis-support-ddl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!