Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top