sql语句

drop PROCEDURE c

CREATE PROCEDURE c()
BEGIN
DECLARE mobile VARCHAR(255);
DECLARE emergencyContactMobile VARCHAR(255);
DECLARE realName VARCHAR(255);
DECLARE identity VARCHAR(255);
DECLARE DoctorName VARCHAR(255);
DECLARE createdate VARCHAR(255);
DECLARE userLabelIds VARCHAR(255);
DECLARE userLabelName1 VARCHAR(255);
DECLARE userLabelName2 VARCHAR(255);
DECLARE userLabelName3 VARCHAR(255);
DECLARE userLabelName4 VARCHAR(255);
DECLARE userLabelName VARCHAR(255);
DECLARE dones INT;
DECLARE cur_user_id CURSOR FOR
SELECT
SUBSTRING(payload->" . m o b i l e " , 2 , C H A R L E N G T H ( p a y l o a d − > " .mobile",2,CHAR_LENGTH(payload->" .mobile",2,CHARLENGTH(payload>".mobile")-2) AS ‘mobile’,
SUBSTRING(payload->" . e m e r g e n c y C o n t a c t M o b i l e " , 2 , C H A R L E N G T H ( p a y l o a d − > " .emergencyContactMobile",2,CHAR_LENGTH(payload->" .emergencyContactMobile",2,CHARLENGTH(payload>".emergencyContactMobile")-2)AS ‘emergencyContactMobile’ ,
SUBSTRING(payload->" . r e a l N a m e " , 2 , C H A R L E N G T H ( p a y l o a d − > " .realName",2,CHAR_LENGTH(payload->" .realName",2,CHARLENGTH(payload>".realName")-2) AS ‘realName’ ,
SUBSTRING( payload->" . i d e n t i t y " , 2 , C H A R L E N G T H ( p a y l o a d − > " .identity",2,CHAR_LENGTH( payload->" .identity",2,CHARLENGTH(payload>".identity")-2) AS ‘identity’
,(SELECT real_name FROM blade_user WHERE id=SUBSTRING(hr.payload->" . r e s p o n s i b l e D o c t o r I d " , 2 , C H A R L E N G T H ( h r . p a y l o a d − > " .responsibleDoctorId",2,CHAR_LENGTH(hr.payload->" .responsibleDoctorId",2,CHARLENGTH(hr.payload>".responsibleDoctorId")-2))AS ‘DoctorName’,
(SELECT create_time FROM hr_user_info WHERE id =hr.user_id ) AS ‘createdate’,
(SELECT user_label_ids FROM hr_user_info WHERE id =hr.user_id ) ‘userLabelIds’
FROM hr_f_personal_basic_information hr WHERE payload->" . m o b i l e " = " 无 " A N D p a y l o a d − > " .mobile"="无" AND payload->" .mobile"=""ANDpayload>".emergencyContactMobile"=“无”;
#游标中的内容执行完后将done设置为1
DECLARE CONTINUE HANDLER FOR NOT FOUND SET dones=1;
#打开游标
OPEN cur_user_id;
#执行循环
posLoop:LOOP
#判断是否结束循环
IF dones=1 THEN
LEAVE posLoop;
END IF;
#取游标中的值
FETCH cur_user_id INTO mobile,emergencyContactMobile,realName,identity,DoctorName,createdate,userLabelIds;
#截取人群标签id进行循环搜索然后拼接起来 (SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(userLabelIds,’,’, 1), ‘,’, -1)) 通过逗号分割
SELECT short_name into userLabelName1 FROM hr_lable_info WHERE id =(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(userLabelIds,’,’, 1), ‘,’, -1));
SELECT short_name into userLabelName2 FROM hr_lable_info WHERE id =(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(userLabelIds,’,’, 2), ‘,’, -1));
SELECT short_name into userLabelName3 FROM hr_lable_info WHERE id =(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(userLabelIds,’,’, 3), ‘,’, -1));
SELECT short_name into userLabelName4 FROM hr_lable_info WHERE id =(SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(userLabelIds,’,’, 4), ‘,’, -1));
#select user_ids,mobil;
if userLabelName4 <=> userLabelName3 then
set userLabelName4="";
end if;
IF userLabelName3 <=> userLabelName2 then
set userLabelName3="";
end if;
IF userLabelName2 <=> userLabelName1 then
set userLabelName2="";
end if;
set userLabelName = CONCAT(userLabelName1,userLabelName2,userLabelName3,userLabelName4);
select userLabelName,mobile,emergencyContactMobile,realName,identity,DoctorName,createdate;
insert into new_table values(mobile,emergencyContactMobile,realName,identity,DoctorName,createdate,userLabelName);
END LOOP posLoop;
#释放游标
CLOSE cur_user_id;
END
SELECT * FROM new_table
call c();

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值