GBase 8s LIST类型

1. 定义 row type

CREATE ROW TYPE rowtype_list(id int, name varchar(40));

2. 创建 spl

DROP FUNCTION IF EXISTS get_list;
CREATE FUNCTION get_list()
  RETURNING LIST(rowtype_list not null)
  
  DEFINE v_list LIST(rowtype_list not null);
  DEFINE i int;
  
  LET v_list = list{};
  
  FOR i = 1 TO 10
    INSERT INTO TABLE(v_list) values(ROW(i,'test'||i)::rowtype_list);
  END FOR;
  
  RETURN v_list;
END FUNCTION;

3. 查询spl返回

select * from table(get_list());

结果:

> select * from table(get_list());


         id name

          1 test1
          2 test2
          3 test3
          4 test4
          5 test5
          6 test6
          7 test7
          8 test8
          9 test9
         10 test10

10 row(s) retrieved.

标签: none

添加新评论

Free Web Hosting