将mysql的脚本语句转oracle,达梦sql
package com.audaque.web.action;
/**
* @Auther:
* @Date: 2021/4/19 16:19
* @Description:
*/
public class sqlCreate {
public static void main(String[] args) {
String sql="DROP TABLE IF EXISTS `security_org_department`;\n" +
"CREATE TABLE `security_org_department` (\n" +
"  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',\n" +
"  `create_user` int(11) DEFAULT NULL COMMENT '创建⼈',\n" +
"  `create_time` datetime DEFAULT NULL COMMENT '创建时间',\n" +
"  `update_user` int(11) DEFAULT NULL COMMENT '修改⼈',\n" +
"  `update_time` datetime DEFAULT NULL COMMENT '修改时间',\n" +
"  `delete_user` int(11) DEFAULT NULL COMMENT '删除⼈',\n" +
"  `delete_time` datetime DEFAULT NULL COMMENT '删除时间',\n" +
"  `data_version` int(11) DEFAULT NULL COMMENT '数据版本',\n" +
"  `data_state` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '数据的逻辑状态(1:有效,⾮1:⽆效)',\n" +
"  `tenant_id` int(11) DEFAULT NULL COMMENT '租户id',\n" +
lenovo怎么恢复出厂设置"  `name` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '部门名称',\n" +
"  `pid` int(11) DEFAULT NULL COMMENT '⽗id',\n" +
"  `dept_type` int(11) DEFAULT NULL COMMENT '部门类型,1:实体组织,2:区划,3:虚拟组织,4:部门/团队',\n" +
"  `dept_code` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '编码',\n" +
"  `industry_category` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '⾏业分类',\n" +
"  `credit_code` varchar(50) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '统⼀社会信⽤代码',\n" +
"  `dept_level` int(11) DEFAULT NULL COMMENT '级别(根节点算做1级)',\n" +
"  `custom_order` int(11) DEFAULT NULL COMMENT '⾃定义顺序',\n" +
"  `remark` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '备注',\n" +
"  `id_path` varchar(190) COLLATE utf8mb4_bin DEFAULT NULL COMMENT 'id的路径,⽤于树结构
检索,不包含⾃⼰,举例:/1/2/3/',\n" +            "  `name_path` varchar(190) COLLATE utf8mb4_bin DEFAULT NULL COMMENT '名称的路径,包含⾃⼰,结尾不包含分隔符',\n" +
"  `inside_id` int(11) DEFAULT NULL COMMENT '内部id,⽤于区分不同租户下的同⼀部门',\n" +
"  `children_num` int(11) DEFAULT NULL COMMENT '当前部门的⼦部门数量',\n" +
"  `current_user_num` int(11) DEFAULT NULL COMMENT '当前部门的⽤户数',\n" +
"  `recursion_user_num` int(11) DEFAULT NULL COMMENT '递归所有⼦部门的⽤户数,包含当前部门',\n" +
"  `recursion_distinct_user_num` int(11) DEFAULT NULL COMMENT '递归所有⼦部门去重后的⽤户数,包含当前部门',\n" +
"  `level1` int(11) DEFAULT NULL COMMENT '⼀级部门的id',\n" +
mysql语句转oracle
"  `level2` int(11) DEFAULT NULL COMMENT '⼆级部门的id',\n" +
"  `level3` int(11) DEFAULT NULL COMMENT '三级部门的id',\n" +
"  `level4` int(11) DEFAULT NULL COMMENT '四级部门的id',\n" +
"  `level5` int(11) DEFAULT NULL COMMENT '五级部门的id',\n" +
"  `level6` int(11) DEFAULT NULL COMMENT '六级部门的id',\n" +
"  `level7` int(11) DEFAULT NULL COMMENT '七级部门的id',\n" +
"  `level8` int(11) DEFAULT NULL COMMENT '⼋级部门的id',\n" +
"  `level9` int(11) DEFAULT NULL COMMENT '九级部门的id',\n" +
"  `level10` int(11) DEFAULT NULL COMMENT '⼗级部门的id',\n" +
"  PRIMARY KEY (`id`),\n" +
"  UNIQUE KEY `security_org_department_1` (`pid`,`name`,`data_state`,`tenant_id`),\n" +
"  KEY `security_org_department_2` (`id_path`),\n" +
"  KEY `security_org_department_3` (`level1`),\n" +
"  KEY `security_org_department_4` (`level2`),\n" +
"  KEY `security_org_department_5` (`level3`),\n" +
"  KEY `security_org_department_6` (`level4`),\n" +
"  KEY `security_org_department_7` (`level5`),\n" +
"  KEY `security_org_department_8` (`level6`),\n" +
"  KEY `security_org_department_9` (`level7`),\n" +
"  KEY `security_org_department_10` (`level8`),\n" +
"  KEY `security_org_department_11` (`level9`),\n" +
"  KEY `security_org_department_12` (`level10`)\n" +
") ENGINE=InnoDB AUTO_INCREMENT=10017 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='组织结构的部门';\n" +            "\n" ;
"\n" ;
String [] sqls=sql.split("\n");
boolean isStart=false;
boolean isEnd=false;
String newSql=null;
String tableName=null;
String colName=null;
String rebark="";
int lenth=0;
for (String s:sqls){
if (s.startsWith("DROP TABLE ")){
newSql="";
rebark="";
isEnd=false;
java程序培训哪里好
isStart=false;
// System.out.println(s);
}else if(s.startsWith("CREATE TABLE ")){
isStart=true;
lenth=s.split("CREATE TABLE ")[1].length();
tableName=s.split("CREATE TABLE ")[1].substring(0,lenth-2).replaceAll("`","");
//  System.out.println(tableName);
placeAll("`","");
}else{
biography可数吗
if (isStart){
if (s.startsWith("  PRIMARY KEY ")||s.startsWith("  UNIQUE KEY ")||s.startsWith("  KEY ")){
continue;
}
placeAll("int\\(11\\)","decimal(11)").replaceAll("bigint\\(20\\)","decimal(11)").replaceAll("tinyint\\(4\\)","decimal(11)").replaceAll("tinyint\\(1\\)","deci
if (s.indexOf("AUTO_INCREMENT")>0){
vb编程交流placeAll("AUTO_INCREMENT","identity(1,1) primary key");
}
if (s.indexOf("COMMENT")>0&&s.indexOf("ENGINE=InnoDB")<1){
lenth=s.split("COMMENT")[1].length();
rebark=rebark+"COMMENT on column "+tableName+"."+s.split("\\s+")[1]+ " is "+s.split("COMMENT")[1].substring(0,lenth-1)+";"+"\n";;
s=s.split("COMMENT")[0]+",";
}
if (s.indexOf("ENGINE=InnoDB")>0){
if (s.indexOf("COMMENT")>0){
lenth= s.split("COMMENT")[1].length();
rebark=rebark+"COMMENT on table "+tableName+" is"+ s.split("COMMENT=")[1].substring(0,lenth-1);
}
服装管理系统isEnd=true;
lenth=newSql.length();
newSql=newSql.substring(0,lenth-2);
newSql=newSql+");";
System.out.println(newSql);
System.out.println(rebark);
}else{
newSql=newSql+s+"\n";
}
}
}
}
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。