oracle a table of,Oracle Table Function

Oracle Table Function在Oracle9i时引入,完美的兼容了view和存储过程的优点:

e6adfb092243d8378dc2fa68d78ec4a8.gif

应用举例:

1.Table()函数:

set feedback off

create or replace type type_int_date_varchar2 as object (i integer, d date, v varchar2(99))

/

create or replace type table_int_date_varchar2 as table of

type_int_date_varchar2

/

create or replace function f_int_date_varchar2 return table_int_date_varchar2 as

a_type_int_date_varchar2 table_int_date_varchar2 := table_int_date_varchar2();

begin

a_type_int_date_varchar2.extend;

a_type_int_date_varchar2(a_type_int_date_varchar2.count) :=

type_int_date_varchar2(1,to_date(‘08.01.1947‘,‘dd.mm.yyyy‘), ‘David Bowie‘);

a_type_int_date_varchar2.extend;

a_type_int_date_varchar2(a_type_int_date_varchar2.count) :=

type_int_date_varchar2(2,to_date(‘27.01.1756‘,‘dd.mm.yyyy‘), ‘Mozart‘);

return a_type_int_date_varchar2;

end;

/

select * from table (cast (f_int_date_varchar2() as table_int_date_varchar2));

drop function f_int_date_varchar2;

drop type table_int_date_varchar2;

drop type type_int_date_varchar2;

2.A Function that returns a table of dates in a Range

create or replace type date_obj as object (dt date)

/

create or replace type date_table as table of date_obj

/

create or replace function date_range(from_dt in date, to_dt in date)

return date_table as

a_date_table date_table := date_table();

cur_dt date:=from_dt;

begin

while cur_dt <= to_dt loop

a_date_table.extend;

a_date_table(a_date_table.count) := date_obj(cur_dt);

cur_dt := cur_dt + 1;

end loop;

return a_date_table;

end date_range;

/

select * from table (

cast ( date_range(

to_date(‘01.01.2002‘,‘dd.mm.yyyy‘),

to_date(‘31.01.2002‘,‘dd.mm.yyyy‘)

)

as date_table

));

原文:http://blog.csdn.net/davidwang9527/article/details/25697611

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值