mysql设置变量的方式修改线上数据

本文介绍了如何使用SQL语句在数据库中批量修改线上关联数据,涉及设置连接、数据库和服务器的字符集,以及更新ks_sub_task_1、ks_sub_task_group_1和ks_put_wall_slot表的biz_status,同时更新ks_container_node表的container_node属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

根据指定的数据, 批量修改线上各种关联数据

思路

定义变量, 批量 sql 处理

对应的SQL

SET collation_connection = 'utf8mb4_general_ci';
SET collation_database = 'utf8mb4_general_ci';
SET collation_server = 'utf8mb4_general_ci';

SET @container_code = 'A74366273';
SET @station_code = 'W1';
SET @bill_no := '';
SET @sub_task_group_no := '';
SET @put_wall_slot_code := '';

SELECT bill_no, sub_task_group_no, put_wall_slot_code 
INTO @bill_no, @sub_task_group_no, @put_wall_slot_code 
FROM ks_sub_task_1 
WHERE station_code = @station_code AND container_code = @container_code AND biz_status='DONE'
LIMIT 1;

SELECT @bill_no AS bill_no, @sub_task_group_no AS sub_task_group_no, @put_wall_slot_code AS put_wall_slot_code;





update ks_sub_task_1 set biz_status='PROCESSING' where sub_task_group_no = @sub_task_group_no and biz_status='UNDO';

update ks_sub_task_group_1 set biz_status='PROCESSING' where sub_task_group_no = @sub_task_group_no and biz_status='UNDO';

UPDATE ks_put_wall_slot SET order_ids = CONCAT('[', @bill_no, ']'), station_slot_status='WAITING_BINDING' WHERE station_code=@station_code and put_wall_slot_code=@put_wall_slot_code and station_slot_status='IDLE';

按照条件逐个更新

SET @container_code := _utf8mb4 'A00010248A' COLLATE utf8mb4_general_ci;

UPDATE `ks_container_node` SET `bay` = 1, `level` = 1 where container_code like CONCAT('%', @container_code, '%') and `bay` = 1 and `level` = 2 and container_name='A1';
UPDATE `ks_container_node` SET `bay` = 2, `level` = 1 where container_code like CONCAT('%', @container_code, '%') and `bay` = 1 and `level` = 1 and container_name='A2';
UPDATE `ks_container_node` SET `bay` = 1, `level` = 2 where container_code like CONCAT('%', @container_code, '%') and `bay` = 2 and `level` = 2 and container_name='B1';
UPDATE `ks_container_node` SET `bay` = 2, `level` = 2 where container_code like CONCAT('%', @container_code, '%') and `bay` = 2 and `level` = 1 and container_name='B2';
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值