mysql存储过程例子cursor
来源:互联网 发布:翅片管换热器设计软件 编辑:程序博客网 时间:2024/06/02 03:17
CREATE DEFINER = 'test'@'%'
PROCEDURE DB.mv_parentsToContact()
begin
declare custid bigint(20);
declare name1 varchar(50);
declare mobile1 varchar(20);
declare name2 varchar(50);
declare mobile2 varchar(20);
declare tempStr varchar(200);
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR
select id from p2p_customer t1 where
not exists (
select t2.CUST_ID from p2p_cust_top_contactor t2 where t2.CUST_ID=t1.id limit 0,1
)
and exists (
select t3.CUST_ID from p2p_cust_addr_list t3 where t3.CUST_ID=t1.id limit 0,1
) order by id asc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open cur1;
custIDs_Loop:LOOP
fetch cur1 into custid;
IF done THEN
set done=FALSE;
LEAVE custIDs_Loop;
END IF;
select t.MOBILE,t.COMPANY_NAME into name1,mobile1 from p2p_customer_contactor t where t.CUST_ID=custid
and t.CONNECT_TYPE='FATHER' and DEL_FLAG='N';
IF done THEN
set done=FALSE;
ITERATE custIDs_Loop;
END IF;
select t.MOBILE,t.COMPANY_NAME into name2,mobile2 from p2p_customer_contactor t where t.CUST_ID=custid
and t.CONNECT_TYPE='MOTHER' and DEL_FLAG='N';
IF done THEN
set done=FALSE;
ITERATE custIDs_Loop;
END IF;
if name1 is not null and mobile1 is not null and name2 is not null and mobile2 is not null THEN
if name1 !='' and mobile1 !='' and name2 !='' and mobile2 !='' THEN
insert into p2p_cust_top_contactor ( CUST_ID, CON_NAME, MOBILE, RELATION_TYPE, CREATE_TIME, UPDATE_TIME )
values ( custid, name1, mobile1, 'parents', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP );
insert into p2p_cust_top_contactor ( CUST_ID, CON_NAME, MOBILE, RELATION_TYPE, CREATE_TIME, UPDATE_TIME )
values ( custid, name2, mobile2, 'parents', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP );
COMMIT;
END IF;
END IF;
END LOOP custIDs_Loop;
close cur1;
end
PROCEDURE DB.mv_parentsToContact()
begin
declare custid bigint(20);
declare name1 varchar(50);
declare mobile1 varchar(20);
declare name2 varchar(50);
declare mobile2 varchar(20);
declare tempStr varchar(200);
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR
select id from p2p_customer t1 where
not exists (
select t2.CUST_ID from p2p_cust_top_contactor t2 where t2.CUST_ID=t1.id limit 0,1
)
and exists (
select t3.CUST_ID from p2p_cust_addr_list t3 where t3.CUST_ID=t1.id limit 0,1
) order by id asc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
open cur1;
custIDs_Loop:LOOP
fetch cur1 into custid;
IF done THEN
set done=FALSE;
LEAVE custIDs_Loop;
END IF;
select t.MOBILE,t.COMPANY_NAME into name1,mobile1 from p2p_customer_contactor t where t.CUST_ID=custid
and t.CONNECT_TYPE='FATHER' and DEL_FLAG='N';
IF done THEN
set done=FALSE;
ITERATE custIDs_Loop;
END IF;
select t.MOBILE,t.COMPANY_NAME into name2,mobile2 from p2p_customer_contactor t where t.CUST_ID=custid
and t.CONNECT_TYPE='MOTHER' and DEL_FLAG='N';
IF done THEN
set done=FALSE;
ITERATE custIDs_Loop;
END IF;
if name1 is not null and mobile1 is not null and name2 is not null and mobile2 is not null THEN
if name1 !='' and mobile1 !='' and name2 !='' and mobile2 !='' THEN
insert into p2p_cust_top_contactor ( CUST_ID, CON_NAME, MOBILE, RELATION_TYPE, CREATE_TIME, UPDATE_TIME )
values ( custid, name1, mobile1, 'parents', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP );
insert into p2p_cust_top_contactor ( CUST_ID, CON_NAME, MOBILE, RELATION_TYPE, CREATE_TIME, UPDATE_TIME )
values ( custid, name2, mobile2, 'parents', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP );
COMMIT;
END IF;
END IF;
END LOOP custIDs_Loop;
close cur1;
end
0 0
- mysql存储过程例子cursor
- mysql存储过程 例子 游标cursor 循环嵌套 事物
- mysql存储过程 例子 游标cursor 循环嵌套 事物
- mysql存储过程 例子 游标cursor 循环嵌套 事物
- MySql存储过程 游标(Cursor)
- MySQL 存储过程例子
- mysql存储过程例子
- mysql 存储过程例子
- mysql 存储过程例子
- mysql 存储过程游标(Cursor)实例
- MySql存储过程—7、游标(Cursor)
- MySql存储过程—游标(Cursor)
- MySql存储过程—7、游标(Cursor)
- MySql存储过程—7、游标(Cursor)
- Mysql存储过程中使用cursor
- MySQL存储过程游标(cursor)示例
- MYSQL存储过程循环CURSOR(游标)使用
- mysql 存储过程小例子
- 关于集成开发环境eclipse
- ActiveMQ高级特性:虚拟Destinations实现消费者分组与简单路由
- 雅虎面试题-你真的了解HTML吗?
- NOIP提高组 千帆渡
- 并行编译 Xoreax IncrediBuild
- mysql存储过程例子cursor
- const char * 和 char const * 和 char * const 区别
- Mysql主从配置
- centos安装mysql
- Python学习笔记——前言
- bzoj 3781: 小B的询问
- 安装lnmp lamp lnamp环境
- java改变指定字符串的方法
- DDMS测试工具之线程监测