2017-02-17 34 views
0

我正在學習oracle sql。如何在單行顯示名字?

我只是試圖用逗號分隔的單行顯示'員工'表中的所有員工的名字。

例如:約翰,亞歷克斯,紅潤

我使用SQL * Plus運行查詢。

+0

你檢查這個網站?,這對寫作查詢更多詳細信息來連接行。 https://oracle-base.com/articles/misc/string-aggregation-techniques –

+0

可能的重複[如何將多行組合到Oracle中的逗號分隔列表中?](http://stackoverflow.com/questions/468990/how-can-i-combine-multiple-rows-into-a-com-delimited-list-in-oracle) – Aleksej

回答

0

您必須使用一些內置的功能,如:

SYS_CONNECT_BY_PATH , ROW_NUMBER() OVER 

Here is the solution

+0

非常感謝。現在我可以在單行顯示名字 –

+0

太好了。將其標記爲您的問題的答案,以便其他人會發現它有幫助。 –

0
SQL> 
SQL> create table test(id int, name varchar(10)); 
Table created 
SQL> begin 
    2  insert into test values(1,'john'); 
    3  insert into test values(2,'alex'); 
    4  insert into test values(3,'rosy'); 
    5 end; 
    6/
PL/SQL procedure successfully completed 
SQL> select listagg(name ,',') within group(order by id) result from test; 
RESULT 
-------------------------------------------------------------------------------- 
john,alex,rosy 
SQL> drop table test purge; 
Table dropped 

SQL> 
相關問題