标签:eal info repeat 数据库 ESS err val sel varchar
--穿建临时表保存每个表的最大id;
CREATE TABLE `table_max_id` (
`max_id` bigint(20)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
--穿建存储过程获取每个表的最大id存储至table_max_id;
CREATE PROCEDURE get_all_maxid()
BEGIN
DECLARE tb_name varchar(50); --
DECLARE done boolean default 0; --
DECLARE cur CURSOR FOR SELECT table_name --
FROM information_schema.columns WHERE table_schema = ‘ss_dlp‘ AND column_name =‘id‘ ORDER BY table_name DESC; --
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; --
TRUNCATE table_max_id; --
OPEN cur; --
REPEAT --
FETCH cur INTO tb_name; --
SET @sql=CONCAT(‘INSERT INTO table_max_id(max_id) SELECT MAX(id) FROM ‘,tb_name); --
PREPARE stmt1 FROM @sql; --
EXECUTE stmt1 ; --
DEALLOCATE PREPARE stmt1; --
until done end repeat; --
CLOSE cur; --
END;
--穿建函数从table_max_id中获取最大id;
create function get_id()
returns int
begin
return (select IFNULL(MAX(max_id),0) as max_id from table_max_id) + 1; --
end ;
--调用存储过程及函数获取最大值
call get_all_maxid();
INSERT INTO `ss_dlp`.`login_log` (`id`, `create_time`, `is_deleted`, `update_time`, `version`, `device_name`, `fullname`, `ip`, `operation`, `type`, `username`, `error_message`, `success`)
VALUES (get_id(), ‘1577328593977‘, b‘0‘, ‘1577328593977‘, ‘0‘, NULL, ‘adimin_test‘, ‘127.0.0.1‘, ‘登录成功1‘, ‘Admin‘, ‘admin‘, NULL, b‘1‘);
标签:eal info repeat 数据库 ESS err val sel varchar
原文地址:https://www.cnblogs.com/gcche/p/12598816.html