我想知道是否有一种方法可以从具有逗号分隔值的列中进行选择。
例如,列具有以下数据:('16','20','27','2','3')
有没有可能这样做:
--从表中获取值16:-
select from table where value = '16'
或者可以在中使用?
select from table where value in '16'
发布于 2019-03-23 14:20:19
如果列value
包含带有单引号的数据,则如下所示:
'16', '20', '27', '2', '3'
然后您可以使用运算符like
select * from table where value like '%''16''%'
如果没有单引号的,的数据如下:
16, 20, 27, 2, 3
然后:
select * from table
where ',' || replace(value, ' ', '') || ',' like '%,16,%'
如果逗号分隔值之间没有空格,则不需要replace()
select * from table where ',' || value || ',' like '%,16,%'
发布于 2019-03-23 12:41:50
如果value列包含单引号sql fiddle here,请使用以下内容
select * from tt where REGEXP_LIKE(value1,'(''16'',)[^,]+');
如果没有单引号,请使用下面的sql fiddle here
select * from tt where REGEXP_LIKE(value1,'(16,)[^,]+');
发布于 2019-03-23 14:00:06
数据库架构可能违反了first normal form
https://stackoverflow.com/questions/55310314
复制