具有unpivot自动抓取列列表(oracle 11g)

发布于 2024-08-22 23:31:07 字数 544 浏览 4 评论 0原文

这是将一行转置为多行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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

西瓜 2024-08-29 23:31:07

您可以创建一个存储过程来在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文