暂无图片
大量的sql语句转换工具
我来答
分享
暂无图片 匿名用户
大量的sql语句转换工具

需求如下: 有一个报表查询系统,里面的报表都是oracle的语法;现在因为迁移并且选择了mysql的数据库,有没有成熟的工具用来批量转换 sql语句;

我来答
添加附件
收藏
分享
问题补充
3条回答
默认
最新
董大威

PowerDesigner软件可以转换。

暂无图片 评论
暂无图片 有用 4
打赏 0
EricOmer

1. 数据库结构转换

Toolkit等。

2. 数据转换

在进行数据转换时,需要注意Oracle和MySQL的数据类型不完全一致。在进行数据转换时,需要进行数据类型映射。比如Oracle中的NUMBER类型可以映射为MySQL中的INT或DOUBLE类型。

3. 存储过程和触发器转换

Oracle和MySQL的存储过程和触发器语法也有所不同。需要根据语法规则进行转换。可以使用一些工具进行自动转换,比如SQLWays。

4. 数据库函数和视图转换

Oracle和MySQL的函数和视图语法也有所不同。需要进行语法转换。同样可以使用一些工具进行自动转换,比如SQLWays。

将Oracle数据库转换为MySQL需要进行结构转换、数据转换、存储过程和触发器转换、数据库函数和视图转换等。需要特别注意不同数据库之间的差异,避免数据丢失或转换失败。可以使用一些工具进行自动转换,但最好还是手动校验一遍,以确保数据的准确性。

暂无图片 评论
暂无图片 有用 0
打赏 0
EricOmer

我写了一个转换器:

create or replace function fnc_table_to_mysql(i_owner in string,
i_table_name in string,
i_number_default_type in string := 'decimal',
i_auto_incretment_column_name in string := '%ID')
/*
功能:ORACLE表生成MYSQL建表DDL
作者:cys 2016-05-18
参数说明:
i_owner:表空间
i_table_name:表名
i_number_default_type:NUMBER默认转换的类型,缺省是decimal
i_auto_incretment_column_name:自增属性字段名称规则,默认是%ID

执行的sql:select fnc_table_to_mysql('LOSSMS','SU_STAFF','','') from dual;

已知问题:
1.不支持分区
2.不支持函数索引,位图索引等特殊索引定义
3.不支持自定义数据类型,不支持ROWID,RAW等特殊数据类型
4.不支持外键
5.不支持自定义约束
6.不支持与空间、事务相关属性
7.DATE与TIMESTAMP转换成datetime,需注意精度
8.超大NUMBER直接转换为bigint,需注意精度
9.auto incretment 是根据字段名规则加一些判断,设置不一定准确,需检查
*/
return clob is
Result clob;
cnt number;
data_type varchar2(128);
column_str varchar2(4000);
pk_str varchar2(4000);
table_comments varchar2(4000);
is_pk_column number := 0;
begin
select count(*)
into cnt
from all_tables
where owner = i_owner
and table_name = i_table_name;
if (cnt = 0) then
RAISE_APPLICATION_ERROR(-20000,'can''t found table,please check input!');
else
Result := 'CREATE TABLE `' || lower(i_table_name) || '`(';
--column
for c in (select a.column_name,
a.data_type,
a.data_length,
a.data_precision,
a.data_scale,
a.nullable,
a.data_default,
b.COMMENTS
from all_tab_cols a, all_col_comments b
where a.owner = i_owner
and a.table_name = i_table_name
and a.HIDDEN_COLUMN = 'NO'
and a.owner = b.OWNER
and a.TABLE_NAME = b.TABLE_NAME
and a.COLUMN_NAME = b.COLUMN_NAME
order by a.column_id) loop
if (c.data_type = 'VARCHAR2' or c.data_type = 'NVARCHAR2') then
data_type := 'varchar(' || c.data_length || ')';
elsif (c.data_type = 'CHAR' or c.data_type = 'NCHAR') then
data_type := 'char(' || c.data_length || ')';
elsif (c.data_type = 'NUMBER') then
if (c.column_name like '%ID' and c.data_scale is null) then
data_type := 'bigint';
elsif (c.data_precision<3 and c.data_scale = 0) then
data_type := 'tinyint';
elsif (c.data_precision<5 and c.data_scale = 0) then
data_type := 'smallint';
elsif (c.data_precision<10 and c.data_scale = 0) then
data_type := 'int';
elsif (c.data_precision is not null and c.data_scale = 0) then
data_type := 'bigint';
elsif (c.data_precision is not null and c.data_scale is not null) then
data_type := 'decimal(' || c.data_precision || ',' ||
c.data_scale || ')';
else
data_type := i_number_default_type;
end if;
elsif (c.data_type = 'DATE' or c.data_type like 'TIMESTAMP%') then
data_type := 'datetime';
elsif (c.data_type = 'CLOB' or c.data_type = 'NCLOB' or
c.data_type = 'LONG') then
data_type := 'text';
elsif (c.data_type = 'BLOB' or c.data_type = 'LONG RAW') then
data_type := 'blob';
elsif (c.data_type = 'BINARY_FLOAT') then
data_type := 'float';
elsif (c.data_type = 'BINARY_DOUBLE') then
data_type := 'double';
else
data_type := c.data_type;
end if;
column_str := ' `' || lower(c.column_name) || '` ' || data_type;
if (c.column_name like i_auto_incretment_column_name and
(c.data_scale is null or c.data_scale = 0)) then
select count(*)
into is_pk_column
from all_constraints a, all_cons_columns b
where a.owner = i_owner
and a.table_name = i_table_name
and a.constraint_type = 'P'
and a.OWNER = b.OWNER
and a.TABLE_NAME = b.TABLE_NAME
and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
and b.COLUMN_NAME = c.column_name;
if is_pk_column > 0 then
column_str := column_str || ' AUTO_INCREMENT';
end if;
end if;
if c.nullable = 'NO' then
column_str := column_str || ' NOT NULL';
end if;
if (trim(c.data_default) is not null) then
column_str := column_str || ' DEFAULT ' ||
trim(replace(replace(c.data_default, chr(13), ''),
chr(10),
''));
end if;
if c.comments is not null then
column_str := column_str || ' COMMENT ''' || c.comments || '''';
end if;
Result := Result || chr(10) || column_str || ',';
end loop;
--pk
for c in (select a.constraint_name, wm_concat(a.column_name) pk_columns
from (select a.CONSTRAINT_NAME,
'`' || b.COLUMN_NAME || '`' column_name
from all_constraints a, all_cons_columns b
where a.owner = i_owner
and a.table_name = i_table_name
and a.constraint_type = 'P'
and a.OWNER = b.OWNER
and a.TABLE_NAME = b.TABLE_NAME
and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
order by b.POSITION) a
group by a.constraint_name) loop
Result := Result || chr(10) || ' PRIMARY KEY (' ||
lower(c.pk_columns) || '),';
end loop;
--unique
for c in (select a.constraint_name, wm_concat(a.column_name) uk_columns
from (select a.CONSTRAINT_NAME,
'`' || b.COLUMN_NAME || '`' column_name
from all_constraints a, all_cons_columns b
where a.owner = i_owner
and a.table_name = i_table_name
and a.constraint_type = 'U'
and a.OWNER = b.OWNER
and a.TABLE_NAME = b.TABLE_NAME
and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
order by b.POSITION) a
group by a.constraint_name) loop
Result := Result || chr(10) || ' UNIQUE KEY `' ||
lower(c.constraint_name) || '`(' || lower(c.uk_columns) || '),';
end loop;
-- index
for c in (select a.index_name, wm_concat(a.column_name) ind_columns
from (select a.index_name,
'`' || a.COLUMN_NAME || '`' column_name
from all_ind_columns a
where a.table_owner = i_owner
and a.TABLE_NAME = i_table_name
and not exists
(select index_name
from all_constraints b
where a.TABLE_OWNER = b.owner
and a.TABLE_NAME = b.TABLE_NAME
and a.INDEX_NAME = b.INDEX_NAME)
order by a.COLUMN_POSITION) a
group by a.index_name) loop
Result := Result || chr(10) || ' KEY `' || lower(c.index_name) || '`(' ||
lower(c.ind_columns) || '),';
end loop;
Result := substr(Result, 1, length(result) - 1) || chr(10) || ')';
--table comments
select max(a.COMMENTS)
into table_comments
from all_tab_comments a
where owner = i_owner
and table_name = i_table_name;
if (table_comments is not null) then
Result := Result || 'COMMENT=''' || table_comments || '''';
end if;
Result := Result || ';';
end if;
return(Result);
end fnc_table_to_mysql;

暂无图片 评论
暂无图片 有用 1
打赏 0
回答交流
Markdown


请输入正文
提交
相关推荐
Oracle EBS 可以自己修改某一个页面,增加一些内容么?
回答 1
当然可以
设置cursor_sharing=force后,导致substr函数索引无法被使用,有什么好的办法吗?
回答 1
已采纳
请楼主看下这个帖子:https://www.cnblogs.com/muzisanshi/p/15637546.html
Oracle 查表结构:desc tablename 这个语句没用吗?
回答 1
已采纳
DESCtablenameSELECTDBMSMETADATA.GETDDL(‘TABLE’,‘数据表名’)FROMDUAL;怀疑你是user没找对
有人知道按键精灵,怎么用懒人插件连接mysql么?或者其他按键精灵连接mysql的方式。求告知,求指导
回答 1
可参考:MySql服务器地址"192.168.1.166"用户名"root"密码"123"数据库名"bookshop"端口号"3306"MySql句柄Plugin.SuperMySQL.mysqlco
MySQL迁移Neo4j的时候时区怎么操作?
回答 1
这种情况?
ORACLE19c安装时如何实现每个表空间最大值能到达64T?烦请各位大神解惑
回答 2
谢谢大神
单节点ADG环境v$managed_standby中thread#=0和thread#=1的区别及用途是什么?
回答 7
升级问题到:一般问题
SQL的聚集函数COUNT、SUM、AVG、MAX、MIN不允许出现在查询语句的什么子句之中
回答 2
已采纳
D.WHERE
Oracle什么时候不应该使用索引聚簇表?
回答 2
已采纳
有四种情况不能使用索引聚簇表。如果预料到聚簇中的表会有大量修改:索引聚簇会对DML的性能产生一些负面影响,特别是INSERT语句,管理聚簇中的数据需要做更多的工作。由于要非常小心地存储数据,因此存储数
在维护oracle过程中,一般怎么分库分表呢?
回答 2
已采纳
在维护oracle过程中,一般怎么在Oracle中,分库分表是一种常见的解决方案,可以提高系统性能和管理大量数据。以下是一些常见的分库分表方法:水平分区:将表根据数据划分为多个分区,每个分区存储一定范