--default value procedure
CREATE OR REPLACE PROCEDURE JOB_PROC
(
--param
P_JOBID IN JOBS.JOB_ID%TYPE,
P_JOB_TITLE IN JOBS.JOB_TITLE%TYPE,
P_MIN_SAL IN JOBS.MIN_SALARY%TYPE := 10,
P_max_sal IN JOBS.max_salary%TYPE := 100
)
IS
VN_CNT NUMBER:= 0;
BEGIN
--동일한 job id가 있는지 확인
SELECT count(*)
into vn_cnt
FROM JOBS
WHERE JOB_ID = P_JOBID;
--없으면 insert
IF VN_CNT = 0 THEN
INSERT INTO JOBS
(
JOB_ID,
JOB_TITLE,
MIN_SALARY,
MAX_SALARY
)
VALUES
(
P_JOBID,
P_JOB_TITLE,
P_MIN_SAL,
P_MAX_SAL
);
--있으면 update
ELSE
UPDATE JOBS
SET JOB_TITLE = P_JOB_TITLE
,MIN_salary = P_MIN_SAL
,max_salary = p_max_sal
WHERE JOB_ID = P_JOBID;
end if;
commit;
END;
/
--오류 확인
SHOW ERR;
EXEC JOB_PROC('SM_JOB1','Sample JOB1');
EXEC JOB_PROC('SM_JOB1','Sample JOB1',2000);
/
SELECT * FROM JOBS
where job_id = 'SM_JOB1';
'DB' 카테고리의 다른 글
[pl/sql] procedure return (0) | 2020.10.20 |
---|---|
[pl/sql]procedure in out param (0) | 2020.10.20 |
[pl/sql] insert or update procedure (0) | 2020.10.20 |
[mysql] 게시판 조회수 업데이트 쿼리 (0) | 2019.05.28 |
[MySql] mysql mybatis 페이지네이션 쿼리 (0) | 2019.05.21 |