1.将表中时间类型的字段更改类型,比如CREATE_TIME,UPDATE_TIME
代码语言:javascript复制ALTER TABLE ZFTJ_HALF MODIFY CREATE_TIME TIMESTAMP WITH LOCAL TIME ZONE;
2.在需要转换的数据库页面点击左上方的工具按钮,选择数据传输,选择好数据源和目标数据库
点击开始,进行表转换
3.修改mysql中时间类型的字段,比如CREATE_TIME,UPDATE_TIME更改成datetime,长度设为0或者为空
4.mysql实现oracle序列
4.1创建序列
代码语言:javascript复制##创建序列
CREATE TABLE
IF NOT EXISTS `sequence` (
`name` VARCHAR (50) NOT NULL,
`current_value` INT (11) NOT NULL,
`increment` INT (11) NOT NULL DEFAULT '1'
);
4.2实现currval
代码语言:javascript复制##当前值
DROP FUNCTION IF EXISTS `currval`;
CREATE FUNCTION `currval` (seq_name VARCHAR(50)) RETURNS INT (11)
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE VALUE INTEGER ;
SET VALUE = 0 ;
SELECT current_value INTO VALUE FROM sequence WHERE NAME = seq_name ;
RETURN VALUE;
END ;
4.3实现nextval
代码语言:javascript复制##下一值
DROP FUNCTION IF EXISTS `nextval`;
CREATE FUNCTION `nextval`(seq_name VARCHAR(50)) RETURNS int(11)
DETERMINISTIC
BEGIN
UPDATE sequence SET current_value = current_value increment WHERE NAME = seq_name;
RETURN currval(seq_name);
END;
4.4插入序列
代码语言:javascript复制##插入序列
INSERT INTO `sequence` (
`name`,
`current_value`,
`increment`
)
VALUES
('ZFTJ_HALF_SEQ', 0, 1);
4.5测试
代码语言:javascript复制SELECT currval('ZFTJ_HALF_SEQ');
SELECT nextval('ZFTJ_HALF_SEQ');
4.6实战
对于其他表,在转换成mysql后,确认一下表中数据id的最大值,将最大值 1作为新表序列的current_value。然后自定义序列名,最好与原序列名称保持一致,执行步骤4.4。将原sql中的SELECT ZFTJ_SEQ.nextval AS id FROM DUAL
替换为新序列的nextvalSELECT nextval('ZFTJ_HALF_SEQ') AS ID
4.7完整sql
代码语言:javascript复制##创建序列
CREATE TABLE
IF NOT EXISTS `sequence` (
`name` VARCHAR (50) NOT NULL,
`current_value` INT (11) NOT NULL,
`increment` INT (11) NOT NULL DEFAULT '1'
);
##插入序列
INSERT INTO `sequence` (
`name`,
`current_value`,
`increment`
)
VALUES
('ZFTJ_HALF_SEQ', 0, 1);
##当前值
DROP FUNCTION IF EXISTS `currval`;
CREATE FUNCTION `currval` (seq_name VARCHAR(50)) RETURNS INT (11)
READS SQL DATA
DETERMINISTIC
BEGIN
DECLARE VALUE INTEGER ;
SET VALUE = 0 ;
SELECT current_value INTO VALUE FROM sequence WHERE NAME = seq_name ;
RETURN VALUE;
END ;
##下一值
DROP FUNCTION IF EXISTS `nextval`;
CREATE FUNCTION `nextval`(seq_name VARCHAR(50)) RETURNS int(11)
DETERMINISTIC
BEGIN
UPDATE sequence SET current_value = current_value increment WHERE NAME = seq_name;
RETURN currval(seq_name);
END;
SELECT currval('ZFTJ_HALF_SEQ');
SELECT nextval('ZFTJ_HALF_SEQ');