Oracle SQL - 基于 concat 的外连接
Oracle SQL - Outer join based on concat
我需要交叉连接两个表,但连接条件是:
Select FutureInventory.Item,
To_Number(Concat(Location, Channel_Id)) Location,
From V_CUST_FUTURE_INV_POSITION FutureInventory,
xx_Item_Loc_Info_V ItemLoc
Where FutureInventory.Item(+) = ItemLoc.Item
And To_Number(Concat(Location, Channel_Id))(+) = ItemLoc.Loc;
我想将列 To_Number(Concat(Location, Channel_Id)) 外连接到 ItemLoc.Loc
(+) 号放在哪里
要在 Oracle 中执行外部联接,您可以使用适当的 JOIN
类型——就像在所有其他数据库中一样。我认为你想要的逻辑是:
select FutureInventory.Item,
To_Number(Concat(Location, Channel_Id)) as Location,
from xx_Item_Loc_Info_V ItemLoc LEFT JOIN
V_CUST_FUTURE_INV_POSITION FutureInventory,
on FutureInventory.Item = ItemLoc.Item AND
To_Number(Concat(Location, Channel_Id)) = ItemLoc.Loc;
首先,使用显式连接语法 - 旧的 (+)
难以阅读且容易出错。其次,使用 ||
运算符而不是 CONCAT
函数 - 同样,更易于阅读。所以我们最终得到
Select FutureInventory.Item,
To_Number(Location || Channel_Id) Location,
From xx_Item_Loc_Info_V ItemLoc
LEFT OUTER JOIN V_CUST_FUTURE_INV_POSITION FutureInventory,
ON FutureInventory.Item = ItemLoc.Item And
To_Number(Location || Channel_Id) = ItemLoc.Loc
我需要交叉连接两个表,但连接条件是:
Select FutureInventory.Item,
To_Number(Concat(Location, Channel_Id)) Location,
From V_CUST_FUTURE_INV_POSITION FutureInventory,
xx_Item_Loc_Info_V ItemLoc
Where FutureInventory.Item(+) = ItemLoc.Item
And To_Number(Concat(Location, Channel_Id))(+) = ItemLoc.Loc;
我想将列 To_Number(Concat(Location, Channel_Id)) 外连接到 ItemLoc.Loc (+) 号放在哪里
要在 Oracle 中执行外部联接,您可以使用适当的 JOIN
类型——就像在所有其他数据库中一样。我认为你想要的逻辑是:
select FutureInventory.Item,
To_Number(Concat(Location, Channel_Id)) as Location,
from xx_Item_Loc_Info_V ItemLoc LEFT JOIN
V_CUST_FUTURE_INV_POSITION FutureInventory,
on FutureInventory.Item = ItemLoc.Item AND
To_Number(Concat(Location, Channel_Id)) = ItemLoc.Loc;
首先,使用显式连接语法 - 旧的 (+)
难以阅读且容易出错。其次,使用 ||
运算符而不是 CONCAT
函数 - 同样,更易于阅读。所以我们最终得到
Select FutureInventory.Item,
To_Number(Location || Channel_Id) Location,
From xx_Item_Loc_Info_V ItemLoc
LEFT OUTER JOIN V_CUST_FUTURE_INV_POSITION FutureInventory,
ON FutureInventory.Item = ItemLoc.Item And
To_Number(Location || Channel_Id) = ItemLoc.Loc