当前位置:网站首页>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
边栏推荐
- 【云原生】2.5 Kubernetes 核心实战(下)
- Installation of ROS gazebo related packages
- Some suggestions for young people who are about to enter the workplace in the graduation season
- php 根据经纬度查询距离
- 亚马逊云科技 Community Builder 申请窗口开启
- Astparser parsing class files with enum enumeration methods
- Summary of flutter problems
- 通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- Bedtools tutorial
- R HISTOGRAM EXAMPLE QUICK REFERENCE
猜你喜欢

GGPlot Examples Best Reference

解决uniapp列表快速滑动页面数据空白问题

VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题

预言机链上链下调研

Wechat applet uses Baidu API to achieve plant recognition

K-Means Clustering Visualization in R: Step By Step Guide

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

【云原生】2.5 Kubernetes 核心实战(下)

vant tabs组件选中第一个下划线位置异常

数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
随机推荐
每月1号开始计算当月工作日
Resources reads 2D texture and converts it to PNG format
Order by注入
Principle of scalable contract delegatecall
ros缺少xacro的包
R HISTOGRAM EXAMPLE QUICK REFERENCE
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
SQLite modify column type
PowerBI中导出数据方法汇总
Tick Data and Resampling
Amazon cloud technology community builder application window opens
程序员成长第六篇:如何选择公司?
可昇級合約的原理-DelegateCall
map集合赋值到数据库
MySQL linked list data storage query sorting problem
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
deepTools对ChIP-seq数据可视化
VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
Verilog and VHDL signed and unsigned number correlation operations
Some suggestions for young people who are about to enter the workplace in the graduation season