动态从oracle表获取数据
在下面的情况下需要您的帮助。
Table1
Columns
Unique_id number
Name varchar2(20)
desc varchar2(20)
Column_Name varchar2(20) /* Contain Column name of Table2 like Col1, Col2, Col3*/
Table2
Columns
Unique_id number FK from Table1
Col1 varchar2(20)
Col2 varchar2(20)
Col3 varchar2(20)
我想编写一个查询以获取以下列。
Name, desc, Column_name, Value
值应来自 table2 。 所有的列(Col1,Col2,Col3)可能包含数据,或者只有一列可能包含数据。
需要帮助来获取这一点,我使用解码来获取它。在我的实际SCEANRIO中,大约有200列,还有其他更好(表现)解决问题的方法。
谢谢,维杰
Need your help in the below scenario.
Table1
Columns
Unique_id number
Name varchar2(20)
desc varchar2(20)
Column_Name varchar2(20) /* Contain Column name of Table2 like Col1, Col2, Col3*/
Table2
Columns
Unique_id number FK from Table1
Col1 varchar2(20)
Col2 varchar2(20)
Col3 varchar2(20)
I want to write a query to get the below columns.
Name, desc, Column_name, Value
The Value should be from Table2.
All the columns(Col1, Col2, Col3) may contain data or only one column may contain data.
Need help in how to get that, i used Decode to get that. In my actual sceanrio there are around 200 such columns are there, is there any other better (performant) way to get solve the issue.
Thanks, Vijay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您提到表2中包含一个以上包含值的1列,因此结果行也将不止一个。因此,您可以首先使用联合来生成多行,然后可以与Table1-一起加入。
Since you mentioned that if there is more than 1 column containing values in Table2, resulted rows would also be more than one. So you can use UNION ALL first to generate multiple rows and then can join that with Table1-