加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

达梦7的管道表函数(PIPELINED TABLE FUNCTION)

(2013-01-13 19:45:41)
标签:

dbms

dm7

it

sql

pl/sql

前一阵,我们在为客户移植ORACLE应用到达梦7时, 碰到了PL/SQL的PIPELINED TABLE FUNCTION,经过努力现在达梦7也支持了这个特性。简单介绍一下其用法:

 

先创建一个嵌套表类型s100_t:

SQL>create or replace type s100_t is table of varchar(100);

  /

操作已执行

已用时间: 119.854(ms) clock tick:245457446. Execute id is 7.

 

然后创建一个普通的函数, 它返回一个嵌套表对象,其内容通过普通的元素赋值获得:

SQL>create or replace function s100f1 return s100_t is

      s100_t;

  begin

      a = s100_t('hello', 'world', 'xxxx');

      a.extend(2);

6

      a(4) = 'yyyy';

      a(5) = 'uuuu';

      return a;

10  end;

11  /

操作已执行

已用时间: 270.073(ms) clock tick:553103141. Execute id is 8.

 

S100f2函数是一个管道表函数, 使用了pipe row语句。这个函数不需要显式创建一个对象, 也不需要返回值:

SQL>create or replace function s100f2 return s100_t

  pipelined

  is

  begin

      pipe row('hello');

      pipe row('world');

  end;

  /

操作已执行

已用时间: 134.468(ms) clock tick:275385227. Execute id is 9.

 

下面使用一个匿名脚本打印s100f1的结果:

SQL>declare

     b s100_t;

  begin

      b = s100f1;

      for i in 1..b.count loop

         print b(i);

      end loop;

  end;

  /

 

hello

world

xxxx

yyyy

uuuu

PL/SQL 过程已成功完成

已用时间: 101.508(ms) clock tick:207884297. Execute id is 10.

 

对于管道表函数, 也可以同样输出:

SQL>declare

     b s100_t;

  begin

      b = s100f2;

      for i in 1..b.count loop

         print b(i);

      end loop;

  end;

  /

 

hello

world

PL/SQL 过程已成功完成

已用时间: 212.282(ms) clock tick:434746279. Execute id is 11.

 

当然也可以这样, 直接用select 语句输出:

SQL>select * from table(s100f2);

 

行号       C

---------- -----

1          hello

         world

 

已用时间: 115.449(ms) clock tick:236433874. Execute id is 12.

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有