当前位置:网站首页>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
边栏推荐
- MTK full dump grab
- Is it safe to open a stock account through the QR code of the securities manager? Or is it safe to open an account in a securities company?
- Principle of scalable contract delegatecall
- Compilation errors and printout garbled problems caused by Chinese content in vs2019 code
- deepTools对ChIP-seq数据可视化
- What are the methods of adding elements to arrays in JS
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- 2022年4月17日五心红娘团队收获双份喜报
- 从ros1到ros2配置的一些东西
- tidb-dm报警DM_sync_process_exists_with_error排查
猜你喜欢

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

Importerror: impossible d'importer le nom « graph» de « graphviz»

mysql链表数据存储查询排序问题

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

可昇級合約的原理-DelegateCall

Map set assignment to database
![[idea] use the plug-in to reverse generate code with one click](/img/b0/00375e61af764a77ea0150bf4f6d9d.png)
[idea] use the plug-in to reverse generate code with one click

Mmrotate rotation target detection framework usage record

亚马逊云科技 Community Builder 申请窗口开启
随机推荐
MySql存储过程游标遍历结果集
Jenkins installation
What are the methods of adding elements to arrays in JS
ros缺少catkin_pkg
spritejs
Cluster Analysis in R Simplified and Enhanced
ros缺少xacro的包
LVM operation
mysql链表数据存储查询排序问题
[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)
Gaode draws lines according to the track
C file and folder operation
6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
CentOS8之mysql基本用法
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
MySQL comparison operator in problem solving
The difference between SQL left join main table restrictions written after on and where
The working day of the month is calculated from the 1st day of each month
ROS lacks catkin_ pkg
Mmrotate rotation target detection framework usage record