Ibatis calls Oracle functions, Stored Procedure Methods in and out cursor

Source: Internet
Author: User

1. Use the following method to call all in-type parameter Processes (the ibatis version is 2.3)

For example:

Procedure flashback_op (v_table_owner varchar2, v_table_namevarchar2, v_flashbackscn number, v_xid varchar2, v_dbid number );

Call method:

<Parametermap id = "tabledml_recycle" class = "Java. util. Map">
<Parameter property = "owner" jdbctype = "varchar"
Javatype = "Java. Lang. String" mode = "in"/>
<Parameterproperty = "name" jdbctype = "varchar"
Javatype = "Java. Lang. String" mode = "in"/>
<Parameter property = "SCN" jdbctype = "Number"
Javatype = "Java. Math. bigdecimal" mode = "in"/>
<Parameterproperty = "dbid" jdbctype = "Number"
Javatype = "Java. Math. bigdecimal" mode = "in"/>
</Parametermap>

<Procedure id = "tabledml_zcrecycle" parametermap = "tabledml_recycle">
{Calltassetrec. flashback_op (?,?,?,?,?)}
</Procedure>

2. For a function whose return type is cursor (out), use the following method.

Function: function getfirstpagenumrows (v_where varchar2, v_dbidnumber, v_numrows varchar2, v_queryid varchar2) returnsys_refcursor;

Call method:
<Parametermap id = "searchparam" class = "Java. util. Map">
<Parameter property = "result" jdbctype = "oraclecursor" javatype = "Java. SQL. resultset" mode = "out" resultmap = "auditselect_resultlist"/>
<Parameter property = "IPaddress"
Jdbctype = "varchar" javatype = "Java. Lang. String" mode = "in"/>
<Parameter property = "dbid" jdbctype = "Number"
Javatype = "Java. Math. bigdecimal" mode = "in"/>
<Parameter property = "countnumber" jdbctype = "Number"
Javatype = "Java. Lang. Integer" mode = "in"/>
<Parameter property = "clientid" jdbctype = "varchar2"
Javatype = "Java. Lang. String" mode = "in"/>
</Parametermap>

<Procedure id = "firstpage" parametermap = "searchparam">
{? = Calltlgadmin. getfirstpagenumrows (?,?,?,?)} (Note that the return value is used before? Representative)
</Procedure>

Java code has the following values:
@ Suppresswarnings ("unchecked ")
Public listgetauditselectbypages (MAP map ){
Getsqlmapclienttemplate (). queryforlist ("firstpage", MAP); // call
Listarrylist = (arraylist) map. Get ("result"); // Value
Returnarrylist;
}

3. For functions whose return values are of the normal data type:

Function:

Function deletecommand (v_commandid number, v_commandsetidnumber default 0, v_dbid number default 0) returnnumber;

Use the following method for processing (when the return value is used as a parameter to process out ):

<Parametermap id = "commanddeletebyid" class = "Java. util. Map">
<Parameter property = "result" jdbctype = "varchar"
Javatype = "Java. Lang. String" mode = "out"/>
<Parameter property = "commandid" jdbctype = "Number"
Javatype = "Java. Lang. Integer" mode = "in"/>
<Parameter property = "commandsetid" jdbctype = "Number"
Javatype = "Java. Lang. Integer" mode = "in"/>
<Parameter property = "dbid" jdbctype = "Number"
Javatype = "Java. Math. bigdecimal" mode = "in"/>
</Parametermap>

<Procedure id = "command_deletebyid"
Parametermap = "commanddeletebyid">
{? = Call truleadmin. deletecommand (?,?,?)}
</Procedure>

Java code

This. getsqlmapclienttemplate (). Delete ("command_deletebyid", MAP );
String num = (string) map. Get ("result ");
Returnnum;

 

 

The call method is as follows:

Public String judgeidentity (string employeeno ){
Map map = new hashmap ();
Map. Put ("usercode", employeeno );
This. defaultibaitsdao. queryforobject ("storageout. getprocedure", MAP );

Return (string) map. Get ("cresult ");
}

 

Usercode is the property value of mode = "in" in parameter in the ibatis configuration file.

Cresult is the property value of mode = "out" in parameter in the ibatis configuration file.

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.