table函数

最近更新时间: 2024-10-17 17:10:00

  • Oracle用法。
create table t_table(f1 varchar2(36),f2 varchar2(36),f3 varchar2(36));
insert into t_table values('tbase','tbase','tbase');
insert into t_table values('Tbase','Tbase','Tbase');
commit;
create or replace type ty_row as object
(
  col1 varchar2(36),
  col2 varchar2(36),
  col3 varchar2(36)
);
/
create or replace type ty_table as table of ty_row;
create or replace function f_table  return ty_table as
  v_ty_table ty_table;
begin
  select ty_row(f1,f2,f3) bulk collect  into v_ty_table from t_table;
  return v_ty_table;
end;
/
#调用,使用table返回一个表格
select * from table(f_table());
  • TDSQL-PG改写。
create table t_table(f1 varchar2(36),f2 varchar2(36),f3 varchar2(36));
insert into t_table values('tbase','tbase','tbase');
insert into t_table values('Tbase','Tbase','Tbase');
create or replace function f_table  returns setof t_table as
  v_rec record;
begin
  for v_rec in select * from t_table loop
      return next v_rec;
  end loop;
  return;
end;
/
#调用
select * from f_table();