我目前返回我这样的结果只读数据库的查询。这不是一个表。
ID|METRIC
1|"123,456,789"
2|"546,123,789"
有没有一种方法,我可以递归从该查询这样的结果看起来是这样的选择 - 基本分裂逗号分隔符到自己的列中的字符串。理想的情况是类似的东西选择---有些东西在这里---从(--original query--);
1|"123|456|789"
2|"546|123|789"
我看到其他的答案创建视图或表,我将没有权限做。该数据库被锁定,只是非易失性SELECT语句。
这并不是说读,但是它的工作原理:
select id,
substr(metric, 1, instr(metric, ',') - 1) col1,
substr(substr(metric, length(substr(metric, 1, instr(metric, ',') - 1)) + 2), 1, instr(substr(metric, length(substr(metric, 1, instr(metric, ',') - 1)) + 2), ',') - 1) col2,
substr(substr(metric, length(substr(metric, 1, instr(metric, ',') - 1)) + 2), instr(substr(metric, length(substr(metric, 1, instr(metric, ',') - 1)) + 2), ',') + 1) col2
from tablename
随着CTE:
with qry as (
select
id,
substr(metric, 1, instr(metric, ',') - 1) col1,
substr(metric, instr(metric, ',') + 1) right1 from tablename
)
select
id,
col1,
substr(right1, 1, instr(right1, ',') - 1) col2,
substr(right1, instr(right1, ',') + 1) col3
from qry q
见demo