Oracle->MySQL遇到的问题

本文详细介绍使用Navicat Premium进行数据库数据传输的方法,并特别关注从Oracle到MySQL的数据迁移过程中遇到的问题,如存储过程、函数、视图等的转换。同时,提供了在Hibernate环境下解决MySQL序列问题的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 数据库管理工具 Navicat Premium.exe

下载地址: Navicat | 产品

打开程序进行数据传输即可,注意:可以跨多个数据源进行传输。

2. 注意问题

数据传输完成后,所有的表基本是转换成功的,但是Oracle的存储过程、函数、视图、序列、自定义类型等不能自动转换,需要人工修改。

3. MySQL序列解决 (Hibernate环境下使用

(1)在MySQL新建一张存储序列的表T_SEQUENCEPK_NAME:序列名称, PK_NAME:序列值。

-- ----------------------------
-- Table structure for T_SEQUENCE
-- ----------------------------
DROP TABLE IF EXISTS `T_SEQUENCE`;
CREATE TABLE `T_SEQUENCE`  (
  `PK_NAME` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `PK_VALUE` bigint(255) NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;

-- ----------------------------
-- Records of T_SEQUENCE
-- ----------------------------
INSERT INTO `T_SEQUENCE` VALUES ('INT_SEQUENCE', 193183);

SET FOREIGN_KEY_CHECKS = 1;

(2)Hibernate 使用注解方式调用序列

@Id
@Column(name = "USER_ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_GENERATOR")
@TableGenerator(name = "ID_GENERATOR", table = "T_SEQUENCE", pkColumnName = "PK_NAME", 
pkColumnValue = "INT_SEQUENCE", valueColumnName = "PK_VALUE", allocationSize = 1, 
initialValue = 192708)
private Integer logonEntityId;
@Column(name = "USER_ID", nullable = false)

4. SQL标准化

Oracle函数对应MySQL函数
序号OracleMySQL
1to_char(date,'yyyy-MM-dd');date_format(date,'%Y-%m-%d')
2to_date(date,'yyyy-MM-dd');str_to_date(date,'%Y-%m-%d')
3trunc(date)date_format(date, '%Y-%m-%d')
4select rownumselect (@rowno := @rowno +1) as rownum
5nvl(expr1,expr2)ifnull(expr1,expr2)
6nvl2(expr1,expr2,expr3)if(expr1,expr2,expr3)
7decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)case when 条件1 then 值1 when 条件2 then 值2 ...else 值3 end

mysql> CREATE TABLE users ( -> id INT AUTO_INCREMENT PRIMARY KEY, -> username VARCHAR(255) NOT NULL, -> password VARCHAR(255) NOT NULL -> ); Query OK, 0 rows affected (0.06 sec) mysql> Welcome to the MySQL monitor. Commands end with ; or \g. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Welcom e to the MySQL monitor. Commands end with' at line 1 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or' at line 1 -> Your MySQL connection id is 54623110 -> Server version: 8.0.32 Source distribution -> Copyright (c) 2000, 2022, Oracle and/or its affiliates. -> Oracle is a registered trademark of Oracle Corporation and/or its -> affiliates. Other names may be trademarks of their respective -> owners. -> Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. -> mysql> CREATE TABLE users ( -> -> id INT AUTO_INCREMENT PRIMARY KEY, -> -> username VARCHAR(255) NOT NULL, -> -> password VARCHAR(255) NOT NULL -> -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '. Your MySQL connection id is 54623110 Server version: 8.0.32 Source distributio' at line 1 mysql> Query OK, 0 rows affected (0.06 sec) -> mysql> -> SHOW TABLES; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Query OK, 0 rows affected (0.06 sec) mysql> SHOW TABLES' at line 1 mysql>
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

再见阿飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值