PL/SQL: ORA-02287: 此处不允许使用序列号; REGEXP 和 CONNECT BY 的 DISTINCT 子查询问题

PL/SQL: ORA-02287: sequence number not allowed here; DISTINCT subquery issues with REGEXP and CONNECT BY

我正在尝试使用 IDsVARIABLE_ID 字段)和字符串(DETAILS 字段)填充 table 16=] 每个细胞。我使用 REGEXP_SUBSTRCONNECT BY 拆分了 ; 上的字符串,这很有效。当我尝试将值插入新的 table、

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;

仅当它们与一个单元格中的多个 DETAILS 相关联时才会产生多个 IDs(例如,averaged; smoothed), 这就是我想要的并且它运行:

但是,同样,当我将 DISTINCT 嵌套到 FROM 子句中时,我得到多个 IDs 和多个 DETAILS(实际上,总行数匹配他们所在的table):

是否有我没有看到的引擎盖下的东西?我在这里错过了什么?

看来您的 select 还需要再升一级。一旦您收集了所有不同的值,select 所有这些值并添加到外部查询中的序列调用中。例如:

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);