ORACLE 저장 프로세스의 생성

1441 단어
1. 반환값 없음
CREATE OR REPLACE PROCEDURE TESTA(paramA IN VARCHAR2,paramB in VARCHAR2)AS
BEGIN
INSERT INTO TNAME (T_id,T_name)values(paramA,paramB);
END TESTA;
java 호출 코드:
CallableStatement proc = null;
proc = conn.prepareCall("{ call TESTA(?,?) }");
proc.setString(1, "100");
proc.setString(2, "TestOne");
proc.execute();

2. 반환값 있음

CREATE OR REPLACE PROCEDURE TESTB(PARA1 IN VARCHAR2,PARA2 OUT VARCHAR2) AS
BEGIN
SELECT INTO PARA2 FROM TNAME WHERE I_ID= PARA1;
END TESTB;
java 호출 코드:
CallableStatement proc = null;
proc = conn.prepareCall("{ call TESTB(?,?) }");
proc.setString(1, "100");
proc.registerOutParameter(2, Types.VARCHAR);
proc.execute();
String testPrint = proc.getString(2);

3. 리스트로 돌아가기

--
CREATE OR REPLACE PACKAGE TESTPACKAGE AS
TYPE Test_CURSOR IS REF CURSOR;
end TESTPACKAGE;
-- , :
CREATE OR REPLACE PROCEDURE TESTC(p_CURSOR out TESTPACKAGE.Test_CURSOR) AS
BEGIN
OPEN p_CURSOR FOR SELECT * FROM TNAME;
END TESTC;
java 호출 코드:
CallableStatement proc = null;
proc = conn.prepareCall("{ call testc(?) }");
proc.registerOutParameter(1,oracle.jdbc.OracleTypes.CURSOR);
proc.execute();
rs = (ResultSet)proc.getObject(1);

좋은 웹페이지 즐겨찾기