For reference, here are examples of table-valued functions in both Oracle and SQL Server
Oracle:
create or replace type range_row_type as object(n number);
create or replace type range_table_type as table of range_row_type;
create or replace function number_range(startNumber in number, endNumber in number)
return range_table_type
pipelined
is
result_row range_row_type := range_row_type(0);
begin
for i in startNumber .. endNumber loop
result_row.n := i;
pipe row(result_row);
end loop;
return;
end;
select * from table(number_range(10,20));
SQL Server:
create function number_range (@start int, @end int)
returns @sequence table (n int)
as begin
declare @i int
set @i = @start
while @i <= @end begin
insert into @sequence(n) values(@i)
set @i = @i + 1
end
return
end
go
select * from number_range(10,20)