DB

ORACLE MYSQL 더미데이터 (dummy data) 생성 방법

Adev 2023. 1. 22. 00:01

1. 재귀복사 - 2배씩 늘리기

 

ex)

Oracle

insert into tbl_board (bno, title, content)
(select seq_board.nextval, title, content from tbl_board);

commit;

 

MySQL

insert into boards(boardtitle, boardcontent, boardwriter)(select boardtitle, boardcontent, boardwriter from boards);

 

 

2. 프로시저 반복문 활용하기


ex)

Oracle

BEGIN
    FOR i IN 1..500 LOOP
    INSERT INTO TB_BOARD(IDX, TITLE, HIT_CNT, DEL_GB, CREA_DTM, CREA_ID) 
    VALUES(SEQ_TB_BOARD_IDX.NEXTVAL, '제목 '||i, 0, 'N', SYSDATE, 'Admin');
    END LOOP;
END;

commit;

 

MySQL

DELIMITER $$

DROP PROCEDURE IF EXISTS loopInsert$$

CREATE PROCEDURE loopInsert()
BEGIN
    DECLARE i INT DEFAULT 1;
        
    WHILE i <= 500 DO
        INSERT INTO boards(boardtitle, boardcontent, boardwriter)
          VALUES(concat('제목',i), concat('내용',i), concat('작성자',i));
        SET i = i + 1;
    END WHILE;
END$$

DELIMITER $$

CALL loopInsert;