Notice
Recent Posts
Recent Comments
Link
스토리지
[07.13] SQL - Procedure 본문
저장 프로시저
- 여러 SQL문을 하나의 SQL문처럼 정리 하여 CALL명령어로 실행 가능하게 만들어 준다.
구분자 변경 (Delimiter)
- 명령문이 완성되지 않은 채 실행되면 안되기 때문에 구분자를 // 로 변경 하는것이다.
- 프로시저 작성을 모두 마쳤으면 구분자를 다시 ;(세미콜론)으로 되돌려 놓는다.
프로시저 기본 구문
EX) UUID를 만드는 Procedure
delimiter //
create procedure test()
begin
select uuid();
end//
delimiter ;
call test();
create procedure test() 에서 실행 해준뒤에 call test()를 호출해야 된다.
아니면 test 프로시저를 찾을 수 없음.
UUID를 만들어서 삽입
delimiter //
create procedure insert_product(category INT, name varchar(45), price INT, amount INT)
begin
declare uuid varchar(255);
set uuid = uuid();
insert into products values(uuid, category, name, price, amount);
end//
delimiter ;
call insert_product(100, '게토레이', 1500, 5);
select * from products;
insert into products values(uuid(), 100, '펩시', 1500, 5);
select * from products;
같은 줄에 주석달면 함수 인식 자체가 안된다 !
'Node.js' 카테고리의 다른 글
[07.14] MYSQL - JOIN (0) | 2021.07.14 |
---|---|
[07.14] MYSQL - View, Subquery 사용 (0) | 2021.07.14 |
[07.08] Unity 카카오 로그인 구현 2 - Unity에서 WebView로 구현하기 (0) | 2021.07.08 |
[07.08] Unity 카카오 로그인 구현 1 - 서버를 이용해서 로그인 (0) | 2021.07.08 |
[06.16] Sequelize (0) | 2021.06.16 |
Comments