具有unpivot自动抓取列列表(oracle 11g)
这是将一行转置为多行Oracle的后续问题
我希望能够反转任意查询结果。
要手动取消透视表,我会这样做:
select value_type, value from (
(
-- query to be unpivoted
-- EG: select col1, col2, col3, col4, col5 from table
)
unpivot
(
-- Line I would like to change
value for value_type in (col1, col2, col3, col4, col5)
)
);
这适用于返回 5 列的所有查询,称为 col1、col2
等。我是否在 ( col1, col2, col3, col4, col5) 将从第一部分中选择的查询/视图/表中获取所有列名称?
This is a follow up question to Transpose one row into many rows Oracle
I want to be able to unpivot an arbitrary query result.
To unpivot a table manually, I would do:
select value_type, value from (
(
-- query to be unpivoted
-- EG: select col1, col2, col3, col4, col5 from table
)
unpivot
(
-- Line I would like to change
value for value_type in (col1, col2, col3, col4, col5)
)
);
This works for all queries that return 5 columns, called col1, col2
, etc. Is there something I put in instead of value for value_type in (col1, col2, col3, col4, col5)
that will grab all the column names from the query/view/table that is selected in the first part?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个存储过程来在 PL/SQL 中执行此操作,方法是动态创建 SQL 语句作为字符串,然后使用
立即执行
来执行它并返回游标。You could create a stored procedure to do this in PL/SQL by dynamically creating your SQL statement as a string an then using
execute immediate
to execute it and return a cursor.