需求:
1、select * from sys_role where id = ‘103’,查询结果如下:
2、将resource_ids表示的sys_resource表的id字段的集合。现在需要在sys_resource表中查出resource_ids中的所有id的记录。
解决方案:
使用regexp_split_to_table方法,resource_ids中id值进行拆分。
select * from regexp_split_to_table ((select resource_ids from sys_role where id = 103), ‘,’), 查询结果如下:
3、与sys_resource表关联,查询出结果;
select * from sys_resource r where EXISTS (select * from regexp_split_to_table ((select resource_ids from sys_role where id = 103), ‘,’) as result where CAST (result AS INT4) = r. ID) order by id
查询结果如下:
SQL regexp_split_to_table方法使用
最新推荐文章于 2024-05-21 15:31:22 发布