/
--out, in out
--procedure 생성시 파라메터는 default in
--out param 생성시 out 명시
CREATE OR REPLACE PROCEDURE NEW_JOB_PROC
(
--param
P_JOB_ID IN JOBS.JOB_ID%TYPE,
P_JOB_TITLE IN JOBS.JOB_TITLE%TYPE,
P_MIN_SALARY IN JOBS.MIN_SALARY%TYPE,
P_MAX_SALARY IN JOBS.MAX_SALARY%TYPE,
p_return_time out date
)
IS
VN_CNT NUMBER := 0;
vn_cur_date date := sysdate;
BEGIN
--동일 job id check
SELECT COUNT(*)
into vn_cnt
FROM JOBS
WHERE JOB_ID = P_JOB_ID;
--없을시 insert
INSERT INTO JOBS
(JOB_ID, JOB_TITLE, MIN_SALARY, MAX_SALARY)
VALUES
(p_job_id, p_job_title, p_min_salary, p_max_salary);
--있을시 update
UPDATE JOBS
SET JOB_TITLE = P_JOB_TITLE,
MIN_SALARY = P_MIN_SALARY,
MAX_SALARY = P_MAX_SALARY
where job_id = p_job_id;
--return value setting
p_return_time := sysdate;
commit;
END;
/
--err check
SHOW ERR;
/
--실행
--EXEC NEW_JOB_PROC('SAMPLE1','sample2',2000,4000,NULL);
--out param 사용을 위해 익명 블록 실행 필요
/
SET SERVEROUTPUT ON;
/
DECLARE
VN_NOWTIME DATE;
BEGIN
NEW_JOB_PROC('SAMPLE1','sample2',2000,4000,VN_NOWTIME);
dbms_output.put_line(vn_nowtime);
end;
'DB' 카테고리의 다른 글
[pl/sql] procedure merge into (0) | 2020.10.20 |
---|---|
[pl/sql] procedure return (0) | 2020.10.20 |
[pl/sql] procedure default value setting (0) | 2020.10.20 |
[pl/sql] insert or update procedure (0) | 2020.10.20 |
[mysql] 게시판 조회수 업데이트 쿼리 (0) | 2019.05.28 |