一、代码
-- 报工设置,添加数据
set @org_id = '租户id';
set @created_user = 'yike';
set @updated_user = 'yike';
set @dispatch_list_id = <物料id>;
set @process_name = '工序名称';
set @process_code = '工序code';
set @code = '内部码';
set @num = 1;
DROP PROCEDURE IF EXISTS proc_initData;
DELIMITER $
CREATE PROCEDURE proc_initData()
BEGIN
DECLARE i INT DEFAULT 11;
WHILE i<=32 DO
insert into <表名>(org_id, created_user, updated_user, dispatch_list_id, process_name, process_code, `code`, num, created_user_id) VALUES(@org_id, @created_user, @updated_user, @dispatch_list_id, @process_name, @process_code, concat(@code, i), 1, <用户id>);
SET i = i+1;
END WHILE;
END $
CALL proc_initData();
二、分析代码
-
concat 函数,使用方法 CONCAT(str1, str2, …);
- 方法用于连接两个或多个数组。
-
DROP PROCEDURE IF EXISTS proc_initData; (存储过程)
-
CALL proc_initData(); 调用储存过程