我一直在关注你的帖子,因为它在 Oracle 中被标记:D
在 oracle 中,它以多种可能的方式寻找,但在 mysql 中,您必须借助程序来遵循它:
架构:
create table table1 (org varchar(50), permission_id varchar(50));
create table table2 (permission_id int, permission_name varchar(50));
insert into table1 values ('Company1','1,3,7'),('Company2','1,3,8');
insert into table2 values (1,'Read'),(3,'Write'),(7,'Execute'),(8,'Delete');
程序:
DELIMITER $$
DROP PROCEDURE IF EXISTS `Update_Table_data`$$
CREATE PROCEDURE `Update_Table_data`()
BEGIN
declare max_row int;
declare p1 int;
Set p1 = 0;
SET max_row = (SELECT max(@i:=@i+1) AS row_num FROM table2 AS t,(SELECT @i:=0) AS foo);
label1: LOOP
set p1 = p1 + 1;
IF p1 <= max_row THEN
UPDATE Table1
SET permission_id =
replace(permission_id, (select permission_id from
(SELECT @i:=@i+1 AS row_num ,t.* FROM table2 AS t,(SELECT @i:=0) AS foo) a
where row_num = p1),
(select permission_name from
(SELECT @i:=@i+1 AS row_num ,t.* FROM table2 AS t,(SELECT @i:=0) AS foo) a
where row_num = p1));
Iterate label1;
END IF;
LEAVE label1;
END LOOP label1;
-- SET @x = p1;
END$$
DELIMITER ;
然后打电话更新你的价值观:
call Update_Table_data;
希望能帮助到你 :)