mysql创建存储过程---------[HY000][1418] This function has none of DETERMINISTIC, NO SQL

这篇博客展示了如何在MySQL中进行存储过程的创建、调用以及删除,并结合MyBatis进行查询操作。内容包括五表联查、一对多结果映射以及自定义函数的使用,详细阐述了数据库交互与ORM框架的配合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#必须设置  不然报错

set @@global.log_bin_trust_function_creators = 1;

#五表联查 并且调用存储过程
select e.empid,e.empname,e.telephone,e.entertime,e.gender,e.age,
       j.jobname,d.depname,
       c.cardno,c.gettime,c.outdate,c.cardtype,c.photo,
        c2.comname, cal_addr(c2.addrid,c2.address) detailaddr
from employees e
inner join  jobs j on e.jobid=j.jobid
inner join departments d on e.depid = d.depid
inner join company c2 on d.comid = c2.comid
left join credentials c on e.empid = c.empid;


set @@global.log_bin_trust_function_creators = 1;
#删除存储过程
drop function if exists cal_addr;
#创建存储过程
create function cal_addr(addr int,compaddr varchar(200))
returns  varchar(300)
begin
    declare cityinfo varchar(50) default "";
select concat( a1.addrname,a2.addrname,a3.addrname) into cityinfo
from address a1,address a2,address a3
where a3.addrid=addr and a3.subaddr=a2.addrid and a2.subaddr=a1.addrid;
    set cityinfo=concat(cityinfo,compaddr);
    return cityinfo;
end;

#调用存储过程
select cal_addr(20,'具体地址');

#mybaits 一对多 使用resultMap

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC
        "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kgc.towercrane.tchr.mapper.QueryHrMapper">
    <resultMap id="emp-emp" type="EmpPage">
        <result property="currentPage" column="currentpage"/>
        <result property="rowPage" column="rowPage"/>
          <collection property="datas"
                      column="{c=currentPage,r=rowPage}"
                      ofType="EmployeesVO"
                      select="findEmpByPage"/>
    </resultMap>
    <select id="findEmp" parameterType="EmpPage" resultMap="emp-emp">
        <![CDATA[
        select ceil(count(*)/#{rowPage}) total,#{rowPage} rowPage,#{currentPage} currentPage,
        if(#{currentPage}<ceil(count(*)/#{rowPage}),#{currentPage}+1,#{currentPage}) next,
        if(#{currentPage}=1,#{currentPage},#{currentPage}-1) previous,
        if(#{currentPage}<ceil(count(*)/#{rowPage}),1,0) hasNext,
        if(#{currentPage}=1,0,1) hasPrevious from employees
        ]]>
    </select>

    <select id="findEmpByPage" resultType="EmployeesVO">
            select e.empid,e.empname,e.telephone,e.entertime,e.gender,e.age,
               j.jobname,d.depname,
               c.cardno,c.gettime,c.outdate,c.cardtype,c.photo,
               c2.comname, cal_addr(c2.addrid,c2.address) detailaddr
            from employees e
            inner join  jobs j on e.jobid=j.jobid
            inner join departments d on e.depid = d.depid
            inner join company c2 on d.comid = c2.comid
            left join credentials c on e.empid = c.empid limit ${(c-1)*r},#{r}

    </select>
</mapper>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kjshuan

点个赞就好啦!!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值