select 'insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (' || user_id || ', ' || role_id || ');' from (
select distinct user_id, role_id from usermgr.ts_user_org_position uop, usermgr.ts_position p, usermgr.ts_role r
where uop.position_id=p.position_id and p.position_code=r.role_code
);
执行以上语句,会生成对应的insert语句:
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (239, 1176);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (419, 724);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (14627, 722);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (14410, 721);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (877, 721);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (511, 721);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (431, 721);
insert into USERMGR.TS_USER_ROLE(USER_ID, ROLE_ID) values (649, 720);
本文介绍了一种使用SQL语句批量生成并插入用户与其对应角色的方法。通过查询不同表中的相关信息,构造出INSERT语句,实现用户角色数据的有效批量导入。
2241

被折叠的 条评论
为什么被折叠?



