An Oracle stored procedure

Source: Internet
Author: User

Open Plsql, create a new stored procedure in the Packages folder

Run the following statement in the SQL window

Create or Replace package SY_USER_PKG1 is

TYPE MyCursor is REF CURSOR;

--Write your own test stored procedure
PROCEDURE T_chcode1
(
V_phone in VARCHAR2,
V_usertype in number,
V_type in number,
V_err_code out number
);
End Sy_user_pkg1;

The stored procedure tag appears under the Packages folder, which is equivalent to an interface in Java!

Then: write the specific stored procedure, it is equivalent to the Java Interface Implementation Class bar

Create or Replace package body SY_USER_PKG1 is


PROCEDURE T_chcode1
(
V_phone in VARCHAR2,
V_usertype in number,
V_type in number,
V_err_code out number
)
Is
V_usercount number;
BEGIN

IF V_type=1 Then
SELECT COUNT (1) into V_usercount from T_user_register_info A WHERE A.account=v_phone and A.user_type_id=v_usertype;
IF V_usercount=1 Then
V_err_code:=1;
Else
v_err_code:=0;
END IF;
End If;

IF v_type=2 Then
SELECT COUNT (1) into V_usercount from T_user_register_info A WHERE A.account=v_phone and A.user_type_id=v_usertype;
IF V_usercount=0 Then
v_err_code:=2;
Else
v_err_code:=0;
END IF;
END IF;


End T_chcode1;
End Sy_user_pkg1;

After this code is run by F8, this will appear under the Packages Bodyies folder.

This is a complete stored procedure, there are interfaces, there are implementations

Now let's test it.

Right-click, there will be test options

Fill in parameters, such as, F8 run, results such as

You can see that you've got the returned result value 0

It can then be called in the Java code, as in the mapper configuration file:

<insert id= "Chcode" parametertype= "Java.util.Map" statementtype= "callable" >
<! [cdata[
{Call SY_USER_PKG1. T_chcode1 (

#{v_phone,mode=in,jdbctype=nvarchar},
#{v_usertype,mode=in,jdbctype=numeric},
#{v_type,mode=in,jdbctype=numeric},
#{v_err_code,mode=out,jdbctype=numeric}
)
}

]]>


</insert>

Called directly in the service implementation class

Ocode is the return value you get.

At this point, the process of invoking a stored procedure is over!

An Oracle stored procedure

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.