<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.keyware.shandan.datasource.mapper.DBTableColumnMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.keyware.shandan.datasource.entity.DBTableColumnVo">
        <result column="OWNER" property="owner"/>
        <result column="TABLE_NAME" property="tableName"/>
        <result column="COLUMN_NAME" property="columnName"/>
        <result column="DATA_TYPE" property="dataType"/>
        <result column="DATA_LENGTH" property="dataLength"/>
        <result column="DATA_PRECISION" property="dataPrecision"/>
        <result column="DATA_SCALE" property="dataScale"/>
        <result column="NULLABLE" property="nullAble"/>
        <result column="DATA_DEFAULT" property="dataDefault"/>
        <result column="COMMENTS" property="comment"/>
    </resultMap>

    <select id="selectColumnsByTableName" resultMap="BaseResultMap">
        select TAB.OWNER, TAB.TABLE_NAME, TAB.TABLESPACE_NAME, COL.COLUMN_NAME, COL.DATA_TYPE, COL.DATA_LENGTH, COL.DATA_PRECISION, COL.DATA_SCALE, COL.NULLABLE, COL.DATA_DEFAULT, COMM.COMMENTS
        from DBA_TABLES TAB
                 left join DBA_TAB_COLUMNS COL on TAB.TABLE_NAME = COL.TABLE_NAME and TAB.OWNER = COl.OWNER
                 left join DBA_COL_COMMENTS COMM on COL.COLUMN_NAME = COMM.COLUMN_NAME and COMM.OWNER = TAB.OWNER and COL.TABLE_NAME = COMM.TABLE_NAME
        where TAB.STATUS = 'VALID' and TAB.TABLE_NAME = #{tableName}
    </select>

    <select id="selectColumnsByTableNameAndOwner" resultMap="BaseResultMap">
        select TAB.OWNER, TAB.TABLE_NAME, TAB.TABLESPACE_NAME, COL.COLUMN_NAME, COL.DATA_TYPE, COL.DATA_LENGTH, COL.DATA_PRECISION, COL.DATA_SCALE, COL.NULLABLE, COL.DATA_DEFAULT, COMM.COMMENTS
        from DBA_TABLES TAB
        left join DBA_TAB_COLUMNS COL on TAB.TABLE_NAME = COL.TABLE_NAME and TAB.OWNER = COl.OWNER
        left join DBA_COL_COMMENTS COMM on COL.COLUMN_NAME = COMM.COLUMN_NAME and COMM.OWNER = TAB.OWNER and COL.TABLE_NAME = COMM.TABLE_NAME
        where TAB.STATUS = 'VALID' and TAB.TABLE_NAME = #{tableName} and TAB.OWNER = #{owner}
    </select>
</mapper>
