[알티베이스] 프로시저(PROCEDURE) 사용 방법
* 프로시저(PROCEDURE) 사용 방법
안녕하세요 송군함대입니다~!^-^/
간만에 포스팅을 하게 되었네요..ㅎㅎ(요즘 너무 게을러진 듯..)
오늘 포스팅할 내용은 알티베이스에서 프로시저를 사용하는 방법에 대해서 알아볼까 합니다.
[프로시저 문법] CREATE OR REPLACE PROCEDURE [프로시저명] IS BEGIN declare cursor [커서명] is [select 문] [변수명] [변수타입]; begin open [커서명]; loop fetch [커서명] into [변수명]; exit when [커서명]%notfound; [SQL문] end loop; end; END; / |
[프로시저 예제] : test_song 테이블에서 t_num 을 조회하여 t_num_list 에 담고, test_song_1 테이블에서 해당 t_num 과 동일한 데이터의 t_flag 값을 'N'으로 업데이트 하는 프로시저 CREATE OR REPLACE PROCEDURE test_song_prc IS BEGIN declare cursor t_num_list is select t_num from test_song; n_t_num number(5); begin open t_num_list; loop fetch t_num_list into n_t_num; exit when t_num_list%notfound; update test_song_1 set t_flag = 'N' where t_num = n_t_num; end loop; end; END; / |