我一直在尋找甲骨文的東西,它像SQL Server中的表變量一樣。我發現有人在這裏提出類似這樣的問題,而人們總是說「是的,Oracle有這樣的」,但是這些例子表明這些實體根本不像SQL Server。有人能告訴我如何在Oracle中執行以下簡單的TSQL解決方案嗎?Oracle中的表變量樣式實體
declare @users table (
ID int,
Name varchar(50),
Age int,
Gender char(1)
)
;with users as (
select 1001 as ID, 'Bob' as Name, 25 as Age, 'M' as Gender
union
select 1021 as ID, 'Sam' as Name, 29 as Age, 'F'
)
insert into @users (ID, Name, Age, Gender)
select * from users
declare @grades table (
UserID int,
ClassID int,
Grade int
)
;with grades as (
select 1001 as UserID , 120 as ClassID, 4 as Grade
Union
select 1001 as UserID , 220 as ClassID, 2 as Grade
Union
select 1021 as UserID , 130 as ClassID, 4 as Grade
Union
select 1021 as UserID , 230 as ClassID, 4 as Grade
Union
select 1021 as UserID , 340 as ClassID, 2 as Grade
)
insert into @grades
select * from grades
select u.ID, u.Name, GPA = AVG(cast(g.grade as decimal))
from @users u
inner join @grades g on u.ID=g.UserID
group by u.ID, u.Name
我明白這一點,我已多次被告知。 – wcm
所以你說,即使有各種類型的數組和集合,我們沒有表變量,它們可以像表一樣使用標準SQL連接到其他表中。 – wcm
沒有變量,您可以隨時創建並在標準SQL @ wcm中加入其他表,是的。有許多不同類型的對象可以創建,這些對象將允許您執行此操作,但不完全像在T-SQL中那樣。 – Ben