目录
存储过程:它是数据库预先编译好的一个sql,可以重复调用,无需二次编译,如果不太清楚可以试着理解为在Java中写的一个方法。
1.存储过程参数
存储过程定义了三个参数:
- IN:输入参数,即外界传入的参数
- OUT:输出参数,即经过计算返回的参数
- INOUT:输入输出参数,即外界传入的参数,经过计算又返回的参数
2.IN,OUT,IN OUT演示
这里使用Oracle数据库进行编写存储过程
假如我们要求输入一个名字查询条数和目前时间,根据输入id返回其note
2.1创建储存过程
create or replace procedure count_role(p_role_name in varchar,count_totai out int,
p_id IN OUT varchar,exec_date out date) is
begin
select count(*) into count_totai from t_role where role_name like '%'||p_role_name||'%';
select a.note into p_id from t_role a where a.id like '%'||p_id||'%';
select sysdate into exec_date from dual;
end count_role;
2.2创建POJO
@Data
public class PdCountRoleParams {
private String roleName;
private int total;
private String p_id;
private Date execDate;
}
2.3创建Mapper接口
public interface PdRoleMapper {
public void countRole(PdCountRoleParams pdCountRoleParams);
public void findRole(PdFindRoleParams pdFindRoleParams);
}
2.4创建Mapper.xml文件
<select id="countRole" parameterType="mybatis04.param.PdCountRoleParams