--oracle 无参数函数例子
create or replace function fun_dtime return varchar2
as
begin
return to_char(sysdate,'yyyy"年"mm"月"dd"日"');
end;
--执行
begin
dbms_output.put_line(fun_dtime);
end;
-- mybatis调用存储过程例子
CREATE OR REPLACE PROCEDURE
QUERYEMPSBYDEPTNO(adress in varchar2) is
numStr VARCHAR2(100) := 'hehe';
numStr2 number;
BEGIN
for x in (select address from dept ) loop
select instr(x.address,'8080') into numStr2 from dual;
select substr(x.address,numStr2) into numStr from dual;
UPDATE dept SET address = 'http://'||adress||':'||numStr where address = x.address;
commit;
end loop ;
END QUERYEMPSBYDEPTNO;
--数据库测试存储过程
call QUERYEMPSBYDEPTNO('localhost')
--xml层
<!-- statementType="CALLABLE" :表明调用的是存储过程; parameterType="java.util.Map"
:参数是一个map,所以在传参时需要传入一个map集合 -->
<select id="queryEmpByDeptno" statementType="CALLABLE"
parameterType="java.util.Map">
<!--传入传出参数要注明mode=IN/OUT 并要注明jdbcType,返回参数要注明对应的resultMap
注意:这里pdeptno,result都是参数map集合的key值. -->
{call QUERYEMPSBYDEPTNO(#{adress,mode=IN,jdbcType=VARCHAR})}
</select>
-- interface层
void queryEmpByDeptno(Map<String, Object> param );
--controller层
@RequestMapping(value = "getDate")
public void calltest() {
Map<String, Object> param = new HashMap<String, Object>();
//对于in参数赋值
param.put("adress","13311");
userDefinedRuleMapper.queryEmpByDeptno(param);
}
--建表
-- Create table
create table DEPT
(
pid NUMBER,
eid NUMBER,
pname VARCHAR2(500),
address VARCHAR2(500)
)
tablespace USERS
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
--表中数据
prompt PL/SQL Developer import file
prompt Created on 星期二, 2018年11月13日 by wangxue
set feedback off
set define off
prompt Disabling triggers for DEPT...
alter table DEPT disable all triggers;
prompt Loading DEPT...
insert into DEPT (pid, eid, pname, address)
values (1, 1, '设置', 'http://localhost:8080/rh/po/ist');
insert into DEPT (pid, eid, pname, address)
values (2, 1, '组', 'http://localhost:8080/gg/emps/43');
insert into DEPT (pid, eid, pname, address)
values (3, 1, '设置', 'http://localhost:8080/ll/es/de');
insert into DEPT (pid, eid, pname, address)
values (4, 1, '组设置', 'http://localhost:8080/ww/wx');
insert into DEPT (pid, eid, pname, address)
values (5, 4, '设置', 'http://localhost:8080/rr/wx');
commit;
prompt 5 records loaded
prompt Enabling triggers for DEPT...
alter table DEPT enable all triggers;
set feedback on
set define on
prompt Done.
mybatis调用存储过程2
最新推荐文章于 2023-02-14 12:36:14 发布