我在查询中成功使用LISTAGG,但是我想把它带入更大的查询。我在FROM中创建了一个子查询,并使用它来引用LISTAGG但是我得到了ORA-01489,即使它不在子查询中时长度很好。我只是不明白为什么将LISTAGG放入子查询会导致它突然突破4000char限制?
所以下面的工作正常......
SELECT DISTINCT
PERSON.PIN "ContactRef",
LISTAGG(CODE.DESCR, '; ') WITHIN GROUP (ORDER BY CODE.DESCR) "Considerations2"
FROM
PERSON,
PERSON_SECURE_INFO,
CODE
WHERE
PERSON.PIN = PERSON_SECURE_INFO.PIN (+)
AND CODE.CODE = PERSON_SECURE_INFO.PSI_CODE
AND (CODE.CODE_TYPE = 'PSI' OR CODE.CODE_TYPE IS NULL)
AND PERSON_SECURE_INFO.PIN is not null
GROUP BY PERSON.PIN
但是当我在更大的SQL块中包含它时,我得到了ORA错误。
SELECT DISTINCT
PERSON.PIN "ContactRef",
PERSON.TITLE "Salutation",
PERSON.FORENAME "Forename",
PERSON.PERSON_SURNAME "Surname",
PERSON.HOME_TEL_NUM "Contact1",
'1' "Contact1Type" /*Home Phone*/,
PERSON.MOBILE_TEL_NUM "Contact2",
'5' "Contact2Type" /*Mobile Phone*/,
PERSON.EMAIL_ADDRESS "Contact3",
'6' "Contact3Type" /*Email*/,
null "Contact4",
null "Contact4Type",
'2' "PreferredContact",
CODE.DESCR "Considerations",
LISTAGG(CODEPSI.DESCR, '; ') WITHIN GROUP (ORDER BY CODEPSI.DESCR) "Considerations2"
FROM
PERSON,
RNT_OCCUPANTS,
CODE,
(SELECT DISTINCT
PERSON.PIN "ContactRef",
CODE.DESCR
FROM
PERSON,
PERSON_SECURE_INFO,
CODE
WHERE
PERSON.PIN = PERSON_SECURE_INFO.PIN (+)
AND CODE.CODE = PERSON_SECURE_INFO.PSI_CODE
AND (CODE.CODE_TYPE = 'PSI' OR CODE.CODE_TYPE IS NULL)
AND PERSON_SECURE_INFO.PIN is not null) "CODEPSI"
WHERE
PERSON.PIN = RNT_OCCUPANTS.PIN
AND PERSON.WARNING_CODE = CODE.CODE (+)
AND (CODE.CODE_TYPE = 'WARN' OR CODE.CODE_TYPE IS NULL)
AND RNT_OCCUPANTS.PARTY = 'Y'
AND RNT_OCCUPANTS.END_DATE_OF_OCCUPANCY is null
GROUP BY
PERSON.PIN,
PERSON.TITLE,
PERSON.FORENAME,
PERSON.PERSON_SURNAME,
PERSON.HOME_TEL_NUM,
PERSON.MOBILE_TEL_NUM,
PERSON.EMAIL_ADDRESS,
CODE.DESCR
有人可以提供一些建议吗?感谢