Calling stored procedures with in-out parameters in Sqlplus and Java

Source: Internet
Author: User
Tags sqlplus

First, Sqlplus

For example, I have the following stored procedure in my database, how can I call the stored procedure and get the return value?

CREATE OR REPLACE

PROCEDURE test_procedure1

(

PARAM1 in VARCHAR2,

PARAM2 in Out varchar2,
   PARAM3 in Out number)

is

BEGIN

PARAM2: = ' 88888 ';

PARAM3: = ' 0 ';

End Test_procedure1;

A general call to a stored procedure or function will think of calls or execute, but the problem is that the stored procedure has in-out parameters and should not use the above two commands.

So I was thinking of writing an anonymous pl/sql block to make the call. The code looks like this:

DECLARE

PARAM1 VARCHAR2 (ten);

PARAM2 VARCHAR2 (a);

PARAM3 number;

BEGIN

PARAM1: = ' 810 ';

PARAM2: = ' 1 ';

PARAM3: =1;

Test_procedure1 (PARAM1, PARAM2, PARAM3);

Dbms_output.  Put_Line (PARAM2);

Dbms_output. Put_Line (PARAM3);

End;

Pl/sql Novice, if who has a better way please enlighten me.

Second, using Java calls

Conn: general JDBC Connection, Java Invoke main code as follows

CallableStatement call = Conn.preparecall ("{Call Test_procedure1 (?,?,?)}");

Call.setstring (1, "810");//incoming parameter 1

call.setstring (2, "1");//Pass in Parameter 2 (outgoing parameter 1)

Call.setint (3, 1);//Pass in Parameter 3 (pass Out parameter 2)

Call.registeroutparameter (2, Java.sql.Types.VARCHAR);//Outgoing parameter 1

call.registeroutparameter (3, JA        Va.sql.Types.NUMERIC);//Outgoing parameter 2

call.execute ();

System.out.println (call.getstring (2));

System.out.println (Call.getint (3));
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.