基于列获取行的SQL查询
我有一个表雇员如下。“更改”列包含通过我的应用程序修改其值的列的名称。此列中的数据用逗号分隔。我需要以这样一种方式查询这个表,即结果每行有一个更改。ie用逗号分割更改列中的数据,并获取相应的行。我不知道从哪里开始!请帮忙。基于列获取行的SQL查询,sql,oracle,select,Sql,Oracle,Select,我有一个表雇员如下。“更改”列包含通过我的应用程序修改其值的列的名称。此列中的数据用逗号分隔。我需要以这样一种方式查询这个表,即结果每行有一个更改。ie用逗号分割更改列中的数据,并获取相应的行。我不知道从哪里开始!请帮忙。 让我们看看,您可以使用Oracle的regexp\u substr函数: select distinct Id, Name, Address, trim(regexp_substr(Change,'[^,]+', 1, level)) from Employee conne
让我们看看,您可以使用Oracle的regexp\u substr函数:
select distinct Id, Name, Address, trim(regexp_substr(Change,'[^,]+', 1, level))
from Employee
connect by regexp_substr(Change, '[^,]+', 1, level) is not null;
这适用于更改列中任意数量的逗号分隔值
请参见rexexp\u substr函数的文档:让我们看看,您可以使用Oracle的regexp\u substr函数:
select distinct Id, Name, Address, trim(regexp_substr(Change,'[^,]+', 1, level))
from Employee
connect by regexp_substr(Change, '[^,]+', 1, level) is not null;
这适用于更改列中任意数量的逗号分隔值
请参见rexexp\u substr函数的文档:这里我尝试使用包含多集级别的regexp\u substr
with temp as
(
select id, name, address, change from testemp
)
select id,name,address,trim(regexp_substr(change, '[^,]+', 1, levels.column_value)) change
from temp t,
table(cast(multiset(select level from dual
connect by level <= length (regexp_replace(change, '[^,]+')) + 1)
as sys.OdciNumberList)) levels;
在这里,我尝试使用regexp\u substr包含的多集级别
with temp as
(
select id, name, address, change from testemp
)
select id,name,address,trim(regexp_substr(change, '[^,]+', 1, levels.column_value)) change
from temp t,
table(cast(multiset(select level from dual
connect by level <= length (regexp_replace(change, '[^,]+')) + 1)
as sys.OdciNumberList)) levels;