//第一种方式,博客侧边栏公告

mybatis 动态创建表、主键、索引、注释

1.xxxMapper.xml文件

<!--创建日志表-->
   <update id="createTablelog">
       <![CDATA[ 
        DECLARE lsql varchar2(4000); 
             pk varchar2(50) := '主键';
        BEGIN lsql := ' 
            CREATE TABLE ${tableName} ( 
              ID VARCHAR(32) DEFAULT SYS_GUID(),
              TS_ID           NUMBER(12),
              TABLE_NAME      VARCHAR2(200),
              PRIMARY_KEY     VARCHAR2(200),
              PRIMARY_VALUE   VARCHAR2(200),
              START_TIME      TIMESTAMP,
              END_TIME        TIMESTAMP,
              LOG_TYPE        CHAR(1),
              STATE           CHAR(1),
              MSG              VARCHAR2(4000),
              CONSTRAINT ${primaryKey} PRIMARY KEY (ID) USING INDEX)'; 
        EXECUTE IMMEDIATE lsql; 
        
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'ID'|| ' IS ''' || '主键' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'TS_ID'|| ' IS ''' || '归集任务表主键' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'TABLE_NAME'|| ' IS ''' || '归集任务源表英文名称(即归集库中的表英文名称)' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'PRIMARY_KEY'|| ' IS ''' || '资源表主键,多个以英文逗号隔开' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'PRIMARY_VALUE'|| ' IS ''' || '资源表主键值,多个以英文逗号隔开' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'START_TIME'|| ' IS ''' || '归集开始时间' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'END_TIME'|| ' IS ''' || '归集结束时间' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'LOG_TYPE'|| ' IS ''' || '1、前置机归集,2、文件归集,3、API接口归集' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'STATE'|| ' IS ''' || '归集状态,A成功,X失败' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON COLUMN ' || '${tableName}' ||'.'||'MSG'|| ' IS ''' || '归集信息' || ''''; 
         EXECUTE IMMEDIATE 'COMMENT ON TABLE ' || '${tableName}' || ' IS ''' || '归集日志表' || ''''; 
         
        lsql := 'create index ${indexNameTs} on ${tableName} (TS_ID)';
        EXECUTE IMMEDIATE lsql;
        lsql := 'create index ${indexNameTab} on ${tableName} (TABLE_NAME)';
        EXECUTE IMMEDIATE lsql; END; ]]>
   </update>

 

posted @ 2021-07-14 19:46  zhoupan  阅读(2451)  评论(0编辑  收藏  举报