我正在尝试使用现有数字IDs
(VARIABLE_ID
字段)和字符串(DETAILS
字段)填充桥接表,每个单元格格式为averaged; smoothed
。我使用;
和REGEXP_SUBSTR
分割了CONNECT BY
上的字符串,这有效。当我尝试将值插入新表时,
INSERT INTO PC_VARIABLES_DETAILS_BRIDGE (DETAIL_BRIDGE_ID, VARIABLE_ID, THE_DETAIL)
SELECT DISTINCT PC_VAR_DETAILS_BRIDGE_PK.NEXTVAL, e.VARIABLE_ID, TRIM(REGEXP_SUBSTR(e.DETAILS,'[^;]+', 1, LEVEL)) FROM (SELECT VARIABLE_ID, DETAILS FROM EG_VAR_UPLOAD_TEST WHERE DETAILS IS NOT NULL) e
CONNECT BY TRIM(REGEXP_SUBSTR(e.DETAILS, '[^;]+', 1, LEVEL)) IS NOT NULL;
我收到错误PL/SQL: ORA-02287: sequence number not allowed here
,这是有道理的。当我将DISTINCT
嵌套到FROM
子句(SELECT DISTINCT VARIABLE_ID...FROM...
)中时,它会运行,但我会得到一个根本不同的输出。
仅吸引SELECT
子句,我想要的是
SELECT DISTINCT e.VARIABLE_ID E_VARIABLE_ID, TRIM(REGEXP_SUBSTR(e.DETAILS,'[^;]+', 1, LEVEL)) THE_DETAIL FROM (SELECT VARIABLE_ID, DETAILS FROM EG_VAR_UPLOAD_TEST WHERE DETAILS IS NOT NULL) e
CONNECT BY TRIM(REGEXP_SUBSTR(e.DETAILS, '[^;]+', 1, LEVEL)) IS NOT NULL ORDER BY e.VARIABLE_ID;
只有当它们与一个单元格中的多个IDs
相关联时才产生多个DETAILS
,例如averaged; smoothed
),这就是我想要的并且它运行:
但是,当我将DISTINCT
嵌套到FROM
子句中时,我得到多个IDs
和多个DETAILS
(实际上,总行数与他们所在的表格:
引擎盖下有什么东西我没看到吗?我在这里缺少什么?
答案 0 :(得分:1)
您的选择似乎只需要一个级别。收集完所有不同的值后,选择所有值并在外部查询中添加序列调用。例如:
INSERT INTO pc_variables_details_bridge
(detail_bridge_id
,variable_id
,the_detail)
SELECT pc_var_details_bridge_pk.nextval
,variable_id
,the_detail
FROM (SELECT DISTINCT e.variable_id
,TRIM(REGEXP_SUBSTR(e.details, '[^;]+', 1, LEVEL)) the_detail
FROM (SELECT variable_id
,details
FROM eg_var_upload_test
WHERE details IS NOT NULL) e
CONNECT BY TRIM(REGEXP_SUBSTR(e.details, '[^;]+', 1, LEVEL)) IS NOT NULL);