오라클 -> MySQL SQL 마이그레이션

Back-End/Data Base 2022. 11. 29. 22:30
728x90
반응형

1. 일부 매칭되는 문법 정리

오라클 My SQL
VARCHAR2 VARCHAR
NUMBER INT
DATE DATETIME
SYSDATE CURRENT_TIMESTAMP

 

2. 시퀀스 생성

 

오라클에서는 시퀀스를 지원하지만, MySQL에서는 시퀀스 기능이 별도로 존재하지 않기때문에, 다음과 같이 사용합니다.

 

ㄱ. 시퀀스를 사용할 테이블 생성

CREATE table SPRING.SEQUENCES
(
NAME VARCHAR(32)

 

, CURRVAL BIGINT UNSIGNED
)
 

ㄴ. 시퀀스를 생성 할 프로시저 생성

create procedure SPRING.create_sequence (in the_name text)
modifies sql data
deterministic
begin
delete from SEQUENCES where name = the_name;
insert into SEQUENCES values(the_name, 0);
end;

 

ㄷ. 생성 한 시퀀스의 다음 값을 가져오는 함수 생성

create function SPRING.nextval (the_name varchar(32))
returns bigint unsigned
modifies sql data
deterministic
begin
declare ret bigint unsigned;
update SPRING.SEQUENCES set currval = currval + 1 where name = the_name;
select currval into ret from SPRING.SEQUENCES where name = the_name limit 1;
return ret;
end

 

ㄹ. 만들어야할 시퀀스를 시퀀스 테이블에 생성

 

call SPRING.create_sequence('ADMIN_BNO');

 

 

ㅁ. Insert 문에서 시퀀스 사용 예시

 

SPRING.nextval('ADMIN_BNO') FROM DUAL 등을 사용해서 시퀀스를 사용

728x90
반응형
: