0

我已经编写了以下语句,它以我需要更新另一个表的格式返回数据,但是我正在努力更新

SELECT element_id,
  LISTAGG(cast(0 as varchar2(20))||', '|| VALUE, ' | ') WITHIN GROUP (ORDER BY display_order)
FROM EDRN.MD$$_ELEMENT_VALUES
WHERE element_id IN
  (SELECT element_id FROM EDRN_NEW.DATA_DICTIONARY)
GROUP BY element_id;

我做了一个基本的转换成 UPDATE 语句

    UPDATE EDRN_NEW.DATA_DICTIONARY
SET Choices = (LISTAGG(CAST(0 AS VARCHAR2(20))||', '|| VALUE, ' | ') WITHIN GROUP (ORDER BY display_order)
FROM EDRN.MD$$_ELEMENT_VALUES
WHERE element_id IN
  (SELECT element_id FROM EDRN_NEW.DATA_DICTIONARY)
GROUP BY element_id);

这收到“ORA-00934:此处不允许组功能”错误。我不确定如何删除组功能但保留我需要的数据格式?

4

1 回答 1

2

您需要一个子查询才能使用listagg(). 在这种情况下,相关子查询:

update EDRN_NEW.DATA_DICTIONARY dd
    set choices = (SELECT LISTAGG(cast(0 as varchar2(20))||', '|| VALUE, ' | ') WITHIN GROUP (ORDER BY display_order)
                   FROM EDRN.MD$$_ELEMENT_VALUES ev
                   WHERE ev.element_id = dd.element_id
                  )
    where exists (select 1 
                  from EDRN.MD$$_ELEMENT_VALUES ev
                  where ev.element_id = dd.element_id 
                 );
于 2016-10-18T19:41:55.430 回答