选择带有名称列的查询

时间:2013-01-25 17:07:48

标签: sql oracle10g rdbms

我想查询表值

Column1 Column2 Coulum3   
a         b      c    
d         e      f

结果应为

Column1 a
Column2 b
Column3 c
Column1 d
Column2 e
Column3 f

基本上是键值对。是否可以在Oracle中使用?

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您可以使用UNION ALL执行此操作,如下所示:

SELECT 'Column1' as Name, Column1 as Value FROM my_table
UNION ALL
SELECT 'Column2' as Name, Column2 as Value FROM my_table
UNION ALL
SELECT 'Column3' as Name, Column3 as Value FROM my_table

Here is a demo on sqlfiddle