오라클 -> MySQL SQL 마이그레이션
Back-End/Data Base 2022. 11. 29. 22:301. 일부 매칭되는 문법 정리
오라클 | 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 등을 사용해서 시퀀스를 사용
'Back-End > Data Base' 카테고리의 다른 글
PostgreSQL 12버전과 13버전의 차이 (0) | 2023.08.16 |
---|---|
PostgreSQL 11버전과 12버전의 차이 (0) | 2023.08.15 |
오라클에서 발생할 수 있는 에러코드 모음 (0) | 2020.11.11 |
두 테이블을 합쳐서 중복된 항목 제거하기 (0) | 2020.03.21 |
TABLE Join (0) | 2020.01.26 |