如何在Oracle中格式化listagg的输出以产生输出(单引号中的每个字段)为'student1', 'student2', 'student3'。 我已经阅读了有关listagg的文档和其他问题,但找不到太多。 SQL查询可连接Oracle中多个行的列值
'student1', 'student2', 'student3'
SELECT LISTAGG(student_name,',') WITHIN GROUP (ORDER BY student_name) from students
谢谢
您可以使用:
SELECT LISTAGG('''' || student_name || '''',',') WITHIN GROUP (ORDER BY student_name) FROM students;
或使用ENQUOTE_LITERAL功能:
ENQUOTE_LITERAL
SELECT LISTAGG(DBMS_ASSERT.ENQUOTE_LITERAL(student_name),',') WITHIN GROUP (ORDER BY student_name) AS r FROM students;
DBFiddle演示