您可以这样尝试(基于此答案):
SELECT 'this goes infront of the ips' ||
replace(SYS_CONNECT_BY_PATH (x_text, '~'), '~', CHR(10)) ||
CHR(10) || 'this text comes after the ips' AS textarea
FROM (SELECT IP1 || ',' || IP2 || ',' || IP3 || ',' || subnetmask AS x_text,
ROW_NUMBER () OVER (ORDER BY referenceID) AS x_rownumber,
COUNT (*) OVER () AS x_count
FROM yourtable
WHERE referenceID > 0)
WHERE x_rownumber = x_count
START WITH x_rownumber = 1
CONNECT BY x_rownumber = PRIOR x_rownumber + 1
如果您使用的是 Oracle 11.2 或更高版本,则应使用以下内容(基于另一个答案):
SELECT 'this goes infront of the ips' || CHR(10) ||
LISTAGG(IP1 || ',' || IP2 || ',' || IP3 || ',' || subnetmask, CHR(10))
WITHIN GROUP (ORDER BY referenceID) ||
CHR(10) || 'this text comes after the ips' AS textarea
FROM yourtable
WHERE referenceID > 0
注意:referenceID > 0
这只是一个示例子句,用于将您的查询限制为特定的 referenceID,yourtable
应替换为表的名称。