简体   繁体   English

oracle sql列别名

[英]oracle sql column alias

I have 3 tables A, B, c and I want to join those tables. 我有3个表A,B,c,我想加入这些表。 These tables have common columns like, id_no, order_no 这些表具有公共列,例如id_no,order_no

and i want to write a query that returns all columns from all 3 tables with column name extension like tabA., tabB., tabC....I don't want to manually specify all column names. 我想编写一个查询,返回所有三个表的所有列,这些列的扩展名是tabA。,tabB。,tabC....。我不想手动指定所有列名。 In that way i can differentiate the common columns among tables. 这样,我可以区分表之间的公共列。

select tabA.id_no, tabA.order_no, tabA....., tabB.id_no, tabB.order_no,tabB..., tabC.id_no, tabC.order_no,tabC..
from A tabA, B tabB, C tabC
where tabA.id_no = tabB.id_no
and tabB.id_no = tabC.id_no

could u pls let me know how to achieve this in oracle sql. 您能否让我知道如何在oracle sql中实现这一点。

Oracle SQL Developer can do that. Oracle SQL Developer可以做到这一点。

Write your * query, put your mouse over the '*' 编写您的*查询,将鼠标置于“ *”上

在此处输入图片说明

SQL Developer offers to explode that to the fully qualified column list, click the blue text. SQL Developer提供了将其展开到完全限定的列列表的方法,单击蓝色文本。

Ta-da. -

在此处输入图片说明

Don't forget your WHERE clause or ANSI join in the FROM, or your DBA will explain to you what a Cartesian product is. 不要忘记您的WHERE子句或ANSI加入FROM中,否则您的DBA会向您解释什么是笛卡尔积。

If your table has foreign keys, SQLDev can generate that as well. 如果您的表具有外键,SQLDev也可以生成该外键。

You can do the following: 您可以执行以下操作:

SELECT tabA.*, tabB.*, tabC.*
  FROM a tabA INNER JOIN b tabB
    ON tabA.id_no = tabB.id_no
 INNER JOIN c tabC
    ON tabB.id_no = tabC.id_no;

EDIT 编辑

If you want only to get a list of the columns associated with the three tables, and to see which column names are common among the three, then you can try something like the following: 如果您只想获取与三个表关联的列的列表,并查看三个表中共有的列名,则可以尝试如下操作:

SELECT column_name, COUNT(*), LISTAGG(table_name, ',') WITHIN GROUP ( ORDER BY table_name
  FROM all_tab_columns
 WHERE owner = '<table_owner>'
   AND table_name IN ('A','B','C')
 GROUP BY column_name;

NB LISTAGG() assumes you're using Oracle 11g or greater; 注意: LISTAGG()假定您使用的是Oracle 11g或更高版本; prior to that you can use the undocumented function WM_CONCAT() . 在此之前,您可以使用未记录的函数WM_CONCAT()

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM