当前位置:网站首页>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!

边栏推荐
- grub 学习
- Chapter 8 Intermediate Shell Tools II
- CPM:A large-scale generative chinese pre-trained lanuage model
- 【LeetCode】42. 接雨水 - Go 语言题解
- “蔚来杯“2022牛客暑期多校训练营4 DHKLN
- 2022中国物流产业大会暨企业家高峰论坛在杭州举办!
- IJCAI2022 Tutorial | Spoken Language Comprehension: Recent Advances and New Fields
- ML's shap: Based on FIFA 2018 Statistics (2018 Russia World Cup) team match star classification prediction data set using RF random forest + calculating SHAP value single-sample force map/dependency c
- 微软商店出现【0x800706D9】解决方法
- 抽象类和接口(学习笔记)
猜你喜欢

EasyExcel comprehensive course combat

Apache Doris系列之:安装与部署详细步骤

MySQL联合查询(多表查询)

Go1.18升级功能 - 泛型 从零开始Go语言

Reverse linked list - head insertion inversion method

Chapter 8 Intermediate Shell Tools II

Kotlin特殊类

Learning about XML (1)

Py's pdpbox: a detailed introduction to pdpbox, installation, and case application

【飞控开发基础教程10】疯壳·开源编队无人机-PID 基础原理
随机推荐
language code table
【Untitled】
软考学习计划
语言代码表
详解操作符
ZZULIOJ:1120: 最值交换
PS Basic Learning (1)
[SAM模板题] P3975 [TJOI2015] 弦论
HCIP第十六天笔记
2022.7.27
EasyExcel综合课程实战
reindex win10
PyTorch model export to ONNX file example (LeNet-5)
2021GDCPC广东省大学生程序设计竞赛 B.Byfibonacci
力扣题(2)—— 两数相加
抽象类和接口(学习笔记)
Lambda表达式
Compressing Deep Graph Neural Networks via Adversarial Knowledge Distillation
测试人面试 常被问到的计算机网络题,高薪回答模板来了
IJCAI2022 Tutorial | Spoken Language Comprehension: Recent Advances and New Fields