查询以水平显示输出

use*_*315 5 sql oracle pivot

我需要以水平方式显示查询输出。我有一些示例数据

create table TestTable (id number, name varchar2(10))

insert into TestTable values (1, 'John')
insert into TestTable values (2, 'Mckensy')
insert into TestTable values (3, 'Valneech')
insert into TestTable values (4, 'Zeebra')

commit

select * from TestTable
Run Code Online (Sandbox Code Playgroud)

这会得到垂直视图的输出。

ID Name
==========
1  John
2  Mckensy
3  Valneech
4  Zeebra
Run Code Online (Sandbox Code Playgroud)

但是,我需要水平显示它。

ID   1    2       3        4
Name John Mckensy Valneech Zeebra
Run Code Online (Sandbox Code Playgroud)

怎样才能做到这一点呢?

Mic*_*uda 0

PIVOT运算符就是您正在寻找的。