当前位置:网站首页>In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
In MySQL, the stored procedure cannot realize the problem of migrating and copying the data in the table
2022-07-30 23:14:00 【live healthy and safe】
A problem description
1.1 Problem Description
Write a stored procedure, the logic is to query the data of some fields in a certain table, and then insert it into another new table.But found in the operation process, the insertion is null.
1. Stored procedure
#select * from tb_studrop PROCEDURE IF EXISTS p_sync_stu;CREATE PROCEDURE p_sync_stu()begin-- Need to define variables that receive cursor datadeclare id int(10);declare u_name varchar(255);declare u_age int(10);declare create_date TIMESTAMP;declare flag int default 0; -- define the flag variable-- Create a cursor to query student information datadeclare stu_data_List cursor for select u_name from tb_stu where create_time>='2022-07-27 10:00:00';-- After the cursor ends, change the mark amount to 1declare exit handler for not found set flag=1;-- open cursoropen stu_data_List;-- loop through the cursorrepeat-- Use the cursor to traverse the result datafetch stu_data_List into u_name;-- save data to tableinsert into tb_stu3 values(u_name);until flag=1end repeat;-- close cursorclose stu_data_List;endcall p_sync_stu();
2. Screenshot
3. After executing the stored procedure, insert data into the table
1.2 Solution
After a lot of investigations, I finally found that when defining the cursor: The field name of declare stu_data_List cursor for select xx and the field name to be declared cannot be the same or the same.
Execute the modified stored procedure again to view the data in the table, as shown in the following figure: You can see that there is already data!
边栏推荐
猜你喜欢
随机推荐
PS基础学习(一)
# # yyds dry goods inventory interview will brush TOP101: to determine whether there is a part of the list
Computer shortcut icon whitening solution
Reverse linked list - in-place inversion method
EasyExcel综合课程实战
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
2021GDCPC广东省大学生程序设计竞赛 B.Byfibonacci
PyTorch模型导出到ONNX文件示例(LeNet-5)
Chapter 8 Intermediate Shell Tools II
第一节 zadig 入门
Gxlcms audio novel system/novel listening system source code
[SAM模板题] P3975 [TJOI2015] 弦论
雪佛兰开拓者,安全保障温暖你的家庭出行的第一选择
智能创意中的尺寸拓展模块
mysql锁机制
PyTorch model export to ONNX file example (LeNet-5)
详解操作符
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
$\text{ARC 145}$
Mysql进阶优化篇01——四万字详解数据库性能分析工具(深入、全面、详细,收藏备用)