当前位置:网站首页>MySQL stored procedure cursor traversal result set
MySQL stored procedure cursor traversal result set
2022-07-02 11:44:00 【Hundred million yards ahead】
Create stored procedure :
# Determine whether the stored procedure exists , There are deletions
DROP PROCEDURE IF EXISTS toCard;
CREATE DEFINER=`root`@`%` PROCEDURE `toCard`()
BEGIN
# Declaration end identifier
DECLARE end_flag int DEFAULT 0;
# Variable
DECLARE userId,cardThird bigint;
DECLARE cardHex,leftCard,rightCard,ecardNum VARCHAR(10);
# declare cursor user_curosr, take sql The result set is assigned to the cursor
DECLARE user_curosr CURSOR FOR SELECT id,ecardNumThird FROM u_user WHERE ecardNumThird IS NOT NULL AND ecardNumThird!='';
# Set termination ID
DECLARE CONTINUE HANDLER FOR NOT FOUND SET end_flag=1;
# Open cursor
OPEN user_curosr;
# Traversal cursor
REPEAT
# Get the current cursor pointer record , Get the value and assign it to the custom variable , notes : The variable name should not be the same as sql The returned column names are the same , The order of variables should be the same as sql The result columns are in the same order
FETCH user_curosr INTO userId,cardThird;
SET cardHex=CONV(LEFT(cardThird, 8), 10, 16);
SET leftCard= CONV(LEFT(LPAD(cardHex,8,0) , 4), 16, 10);
SET rightCard= CONV(RIGHT(LPAD(cardHex,8,0) , 4), 16, 10);
SET ecardNum=LPAD(CONCAT(leftCard,rightCard),8,0);
# Output results
#SELECT userId,cardThird,cardHex,leftCard,rightCard,ecardNum;
# Use the obtained value to operate the database
UPDATE u_user SET ecardNum=ecardNum WHERE id=userId;
# according to end_flag Judge whether it is over
UNTIL end_flag END REPEAT;
# Close cursor
close user_curosr;
END
Execute stored procedures :
call toCard();
It contains wiegand26 Card number conversion agreement
边栏推荐
- Solve the problem of data blank in the quick sliding page of the uniapp list
- How to Create a Nice Box and Whisker Plot in R
- enumrate的start属性的坑
- ros gazebo相关包的安装
- Cluster Analysis in R Simplified and Enhanced
- 【云原生】2.5 Kubernetes 核心实战(下)
- Some suggestions for young people who are about to enter the workplace in the graduation season
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- ros缺少xacro的包
- 基于Hardhat和Openzeppelin开发可升级合约(二)
猜你喜欢
Webauthn - official development document
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
微信小程序利用百度api达成植物识别
预言机链上链下调研
MySQL comparison operator in problem solving
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
CentOS8之mysql基本用法
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
随机推荐
Mmrotate rotation target detection framework usage record
enumrate的start属性的坑
How to Create a Beautiful Plots in R with Summary Statistics Labels
基于 Openzeppelin 的可升级合约解决方案的注意事项
PX4 Position_Control RC_Remoter引入
[multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
What are the methods of adding elements to arrays in JS
八大排序汇总
Bedtools tutorial
Solve the problem of data blank in the quick sliding page of the uniapp list
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
tqdm的多行显示与单行显示
mysql链表数据存储查询排序问题
Pit of the start attribute of enumrate
揭露数据不一致的利器 —— 实时核对系统
vant tabs组件选中第一个下划线位置异常
Order by注入
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
C#多维数组的属性获取方法及操作注意
How to Create a Nice Box and Whisker Plot in R