JDBC 공통 조작 방법 (6): 저장 프로세스

1627 단어
자세히 보기
저장 프로세스
 
CREATE OR REPLACE PROCEDURE P_ADD_EMP(ENO         IN NUMBER,
                                      EMPNAME     IN VARCHAR2,
                                      EMPJOB      IN VARCHAR2,
                                      EMPMGR      IN NUMBER,
                                      EMPHIREDATE IN DATE,
                                      EMPSAL      IN NUMBER,
                                      EMPCOMM     IN NUMBER,
                                      EDEPTNO     IN NUMBER,
                                      RCODE       OUT NUMBER) IS
  V_CODE NUMBER(1) := -1;
  V_SQL  VARCHAR2(200);

BEGIN
  IF ENO IS NULL THEN
    RCODE := -1;
    RETURN;
  END IF;
  --                empno
  SELECT COUNT(EMPNO) INTO V_CODE FROM EMP WHERE EMPNO = ENO;
  IF V_CODE > 0 THEN
    --          empno
    RCODE := 1;
  ELSE
    --            deptno
    SELECT COUNT(DEPTNO) INTO V_CODE FROM DEPT WHERE DEPTNO = EDEPTNO;
    IF V_CODE > 0 THEN
      --       deptno,     emp  
      INSERT INTO EMP E
      VALUES
        (ENO,
         EMPNAME,
         EMPJOB,
         EMPMGR,
         EMPHIREDATE,
         EMPSAL,
         EMPCOMM,
         EDEPTNO);
      RCODE := 0;
      COMMIT;
    ELSE
      RCODE := 2;
    END IF;
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    RCODE := 3;
    ROLLBACK;
END P_ADD_EMP;
/

좋은 웹페이지 즐겨찾기