我的数据库中有一个列,其中包含 4 个字段作为“\”分隔字符串。
我已经拆分了这些字段,因为我在报告中需要单独使用它们。
我还需要单独使用这些字段作为针对另一个表的条件。
我尝试过的事情:临时表:
CREATE GLOBAL TEMPORARY TABLE pfcc
ON COMMIT PRESERVE ROWS
AS select REGEXP_SUBSTR(s, '[^\]+', 1, 1) colA,
REGEXP_SUBSTR(s, '[^\]+', 1, 2) colB,
REGEXP_SUBSTR(s, '[^\]+', 1, 3) colC,
REGEXP_SUBSTR(s, '[^\]+', 1, 4) colD
from (select delimited s from products
where productid = 1)
然后将其加入到另一个表中。
select * from pfcc tmp
inner join lineitems gch
on gch.Line = tmp.colA
AND gch.productB = tmp.colB
AND gch.productC = tmp.colC
我还尝试立即加入而不将值存储在表中:
select REGEXP_SUBSTR(s, '[^\]+', 1, 1) colA,
REGEXP_SUBSTR(s, '[^\]+', 1, 2) colB,
REGEXP_SUBSTR(s, '[^\]+', 1, 3) colC,
REGEXP_SUBSTR(s, '[^\]+', 1, 4) colD
from (select delimited s from products
where productid = 1) tmp
inner join lineitems gch
on gch.Line = tmp.colA
AND gch.productB = tmp.colB
AND gch.productC = tmp.colC
我想AVOID使用临时表,并与第二种方式类似。如果这是不可避免的,那就这样吧。
有人有解决方案吗?
谢谢,
联合菲特