在 Oracle 中,查找逗号分隔列中的数据所需的执行时间太长。

huangapple go评论54阅读模式
英文:

In Oracle execution time for finding a data inside comma seperated column taking too long

问题

I am trying to find out if the list of data is in a comma-separated column. I have a code select * from my_table where (regexp_substr ( listcolumn, '[^,]+', 1, level ) in ('a','d')) connect by level <= regexp_count(listcolumn, ',') + 1; and a table with a lot of data. The problem is it works for a small data table, but it is taking too much time to execute for a table with a lot of data. I am not an expert in the database, so can you please help with how to resolve this problem? Thank you in advance.

英文:

I am trying to find out if the list of data is in comma separated column. I have a code select * from my_table where (regexp_substr (
listcolumn,
&#39;[^,]+&#39;,
1,
level
) in (&#39;a&#39;,&#39;d&#39;))
connect by level &lt;= regexp_count(listcolumn, &#39;,&#39;) + 1;
and table with a lot data. The problem is it works for small data table but it is taking too much time to execute for a lot a table with a lot of data. I am not expert in database. so can you please help to how to resolve this problem. Thank you in advance.

答案1

得分: 1

不要拆分字符串,查找子字符串匹配(带有周围的分隔符,以便匹配整个项):

SELECT *
FROM   my_table
WHERE  ',' || listcolumn || ',' LIKE '%,' || 'a' || ',%'
OR     ',' || listcolumn || ',' LIKE '%,' || 'd' || ',%';
英文:

Don't split the string, look for a sub-string match (with the surrounding delimiters so that you match entire terms):

SELECT *
FROM   my_table
WHERE  &#39;,&#39; || listcolumn || &#39;,&#39; LIKE &#39;%,&#39; || &#39;a&#39; || &#39;,%&#39;
OR     &#39;,&#39; || listcolumn || &#39;,&#39; LIKE &#39;%,&#39; || &#39;d&#39; || &#39;,%&#39;;

huangapple
  • 本文由 发表于 2023年2月14日 06:47:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75441897.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定