문제

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.

도움이 되었습니까?

해결책

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 supports any native SQL/PlSql commands. So yes, it supports DDL statements.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top