Get the App
SLTechnology News&Howtos  ›  Database  › 

Mybatis calls oracle stored procedure

Shulou Source: shulou.com Published: 2022-06-01 14:41:04 10月20日 Update

Stored Procedures with Input and Output Parameters

Oracle stored procedure part code:

create or replace procedure PT_copy_Shipment_One_Data(

oldShipmentId in varchar ,

servprovGid in varchar ,

insertUser in varchar,

resultShipmentId out varchar

)is

newShipmentGid varchar2(50 );

newShipmentXid varchar2(50 );

newShipmentTypeGid varchar2(50 );

begin

--PLSQL body executed

commit;--commit something

Exception

When others then

Rollback;

end PT_copy_Shipment_One_Data;

Xml configuration for mybatis

Note: Although there is a return value, do not need to know the return parameter class, see the java code example below for details.

{call PT_copy_Shipment_One_Data(

#{oldShipmentId,mode=IN,jdbcType=VARCHAR},

#{servprovGid,mode=IN,jdbcType=VARCHAR},

#{insertUser,mode=IN,jdbcType=VARCHAR},

#{resultShipmentId,mode=OUT,jdbcType=VARCHAR}

)}

]]>

Dao or Service Code

Map parasMap = new HashMap();

parasMap.put("oldShipmentId", para.get( "shipmentId"));

parasMap.put( "servprovGid", para.get("skdw"));//attr12

parasMap.put( "insertUser", Users.getCurrent());

parasMap.put( "resultShipmentId", "" );

//call stored procedure

this.getSqlSessionTemplate().

selectOne("com.otm.app.entity.pojo.ShipmentCost.callCoptShipment",parasMap);

parasMap.put("shipmentId", parasMap.get("resultShipmentId" ));

return parasMap;

For example, if the code is superscript red, there is no need to set the return parameter in mybatis, and then there is no need to accept the return parameter when calling the stored procedure in java. The map parameter will automatically have. This is a strange place.

AC Technical Group No.:50567913

Tags: Parameters procedures storage code superscript things examples places technology details this is part communication input output configuration Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux Redmi OPPO Reno macOS