两种方法获取返回值
1.用select
BEGIN
SELECT * from nodelist t where t.id = id;
END;
2.用out模式或者inout模式
BEGIN
END;
声明变量 datatype 为 MySQL 的数据类型
declare cid int unsigned default 40000;
declare ccs VARCHAR(255) default "";
赋值
set @tid = inParam;
set cid = cid +@tid;
if-else case-when-then while
IF @tid = 1 then
set @tid = 2;
else
set cid = 20;
end if;
case @tid
when 0 THEN
set @tid=100;
when 1 then
set @tid=200;
else
set @tid=300;
end case;
while @tid>0 do
set cid=cid+1;
set @tid = @tid-1;
end while;
mybatis调用MySQL函数和过程
<!-- mybatis xml -->
<select id="shopOrderQty" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select shopQtyCount(#{shopId}) from dual
</select>
CREATE DEFINER=`duomai_test`@`%` FUNCTION `shopQtyCount`(`shopId` int) RETURNS int(11)
BEGIN
RETURN (select count(1) from zmd_order where order_shop_id=shopId and trade_status in (4,5));
END
//输出模式为out 或者inout
@Select("call discussOrdersFun(#{param.upPrice,mode=OUT,jdbcType=DECIMAL},#{param.isReadDiscuss,mode=OUT,jdbcType=TINYINT})")
@Options(statementType = StatementType.CALLABLE)//OUT参数时需要开启CALLABLE
void discussOrdersFun(@Param("param")DiscussOrdersResponse discussOrdersResponse);
CREATE DEFINER=`duomai_test`@`%` PROCEDURE `discussOrdersFun`(OUT `upPrice` decimal,OUT `isReadDiscuss` tinyint)
BEGIN
set upPrice=1;
set isReadDiscuss=1;
END
//使用MySQL过程select输出列表
@Select("call discussOrdersFun()")
DiscussOrdersResponse discussOrdersFun();
CREATE DEFINER=`duomai_test`@`%` PROCEDURE `discussOrdersFun`()
BEGIN
select 1 as 'upPricea',2 as 'isReadDiscuss' from dual;
END
来源:oschina
链接:https://my.oschina.net/xhbl/blog/4314845