当前位置:网站首页>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;
ENDExecute stored procedures :
call toCard();It contains wiegand26 Card number conversion agreement
边栏推荐
- 每月1号开始计算当月工作日
- Rest (XOR) position and thinking
- 对毕业季即将踏入职场的年轻人的一点建议
- tqdm的多行显示与单行显示
- Astparser parsing class files with enum enumeration methods
- STM32 single chip microcomputer programming learning
- QT获取某个日期是第几周
- 2022年遭“挤爆”的三款透明LED显示屏
- [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 is the relationship between digital transformation of manufacturing industry and lean production
猜你喜欢

RPA advanced (II) uipath application practice

Tdsql | difficult employment? Tencent cloud database micro authentication to help you

ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)

ctf 记录

可升级合约的原理-DelegateCall

亚马逊云科技 Community Builder 申请窗口开启

Principle of scalable contract delegatecall

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R

Verilog and VHDL signed and unsigned number correlation operations
随机推荐
2022年遭“挤爆”的三款透明LED显示屏
R HISTOGRAM EXAMPLE QUICK REFERENCE
解决uniapp列表快速滑动页面数据空白问题
SSRF
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
Eight sorting summaries
How to Create a Beautiful Plots in R with Summary Statistics Labels
Array splitting (regular thinking
Summary of flutter problems
在连接mysql数据库的时候一直报错
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
webauthn——官方开发文档
R HISTOGRAM EXAMPLE QUICK REFERENCE
Astparser parsing class files with enum enumeration methods
Attribute acquisition method and operation notes of C # multidimensional array
ros gazebo相关包的安装
MTK full dump grab
Cluster Analysis in R Simplified and Enhanced
spritejs
JS -- take a number randomly from the array every call, and it cannot be the same as the last time