mybatis调用存储过程2

--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.




























评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值