Oracle 스토리지 프로세스 호출(반환 매개변수)

CREATE OR REPLACE PROCEDURE test_in_out_exception (v_empno VARCHAR2,v_guess_sal NUMBER,v_true_sal OUT NUMBER)

AS

   v_exits   VARCHAR2 (20);

   v_sal     emp.sal%TYPE;

   v_raise EXCEPTION;

BEGIN

   SELECT   COUNT (1)

     INTO   v_exits

     FROM   emp t

    WHERE   t.empno = v_empno;



   IF (v_exits > 0)

   THEN

      SELECT   t.sal

        INTO   v_sal

        FROM   emp t

       WHERE   t.empno = v_empno;

       v_true_sal :=  v_sal;

      IF (v_sal > v_guess_sal)

      THEN

         DBMS_OUTPUT.Put_line (' ');

      ELSIF (v_sal < v_guess_sal)

      THEN

         DBMS_OUTPUT.Put_line (' ');

      ELSIF (v_sal = v_guess_sal)

      THEN

         DBMS_OUTPUT.Put_line (' ');

      END IF;

   ELSE

      RAISE v_raise;

   END IF;

EXCEPTION

   WHEN v_raise

   THEN

      RAISE_APPLICATION_ERROR (-20010, 'v_empno not exists!');

   WHEN NO_DATA_FOUND

   THEN

      RAISE_APPLICATION_ERROR (-20011, 'ERROR: !');

   WHEN OTHERS

   THEN

      ROLLBACK;

END;

Java 코드
        try {

            //  

            CallableStatement c = conn.prepareCall("{call test_in_out_exception(?,?,?)}");



            //  

            c.setString(1, "7369");// 7369  800    736900   

            c.setInt(2, 24);

            //  

            c.registerOutParameter(3, java.sql.Types.INTEGER);

            //  

            c.execute();

            //  

            System.out.println(c.getInt(3));

        } catch (SQLException e) {

            System.out.println("SQLState : " + e.getSQLState());

            System.out.println("ErrorCode : " + e.getErrorCode());

            System.out.println("Message : " + e.getMessage());

            System.out.println("LocalizedMessage : " + e.getLocalizedMessage());

            //e.printStackTrace();

        } finally {

            conn.close();

        }

테이블은 데이터oracle의 scott 사용자 기본 테이블입니다.

좋은 웹페이지 즐겨찾기