请问个管道化表函数的用法。

蔡袅 2011-10-14 05:22:20
我在函数FT_DEAL_TIME中返回一个管道化表。
但是在这个管道化表函数中需要获取管道化表自身中的最后一行,如果跟当前列表某个字段比较为true则添加到管道化表,否则不添加。
我的做法是:
用max取最后那一条,可是不行报错哎(max那行),管道化表函数不会用,求指导。

代码如下:

create or replace function FT_DEAL_TIME(iMucid number)
return Time_Data_METADATA_Table
PIPELINED is
v_time_data_metadata Time_Data_METADATA;
nowdate date;
predate date;
begin
for x in (select f.positiontime as positiontime,
e.longitude as longitude,
e.latitude as latitude,
f.velocity as velocity
from BMPS_HIS_RECEIVE_GPSSTATUS d,
BMPS_HIS_RECEIVE_GPSJPINFO e,
BMPS_HIS_RECEIVE_GPSINFO f
where d.sequence = f.sequence
and e.sequence = f.sequence
and d.status14 = 1
and d.mcuid = iMucid
order by d.positiontime asc) loop
nowdate := x.positiontime;
predate := select max(t.positiontime) from table(FT_DEAL_TIME(iMucid)) t;;
if (nowdate - predate) * 24 * 60 > 5 then
v_time_data_metadata := Time_Data_METADATA(x.positiontime,
x.longitude,
x.latitude,
x.velocity);
pipe row(v_time_data_metadata);
end if;
end loop;
return;
end;
...全文
124 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jwd001 2011-10-14
  • 打赏
  • 举报
回复
跟踪维护最大值就行了.
if predate is null or predate < nowdate then
predate := nowdate;
end if;
xiaobn_cn 2011-10-14
  • 打赏
  • 举报
回复
要下班了,我帮你理下需求吧。

你的需求:但是在这个管道化表函数中需要获取管道化表自身中的最后一行,如果跟当前列表某个字段比较为true则添加到管道化表,否则不添加。

我的猜测:当前循环过程中,当前记录的positiontime列,与已加入管道中的历史数据中的最大值(也就是最后一条记录的positiontime)比较,差值如果大于5分钟,则将当前记录加入管道。

推荐的算法如下:

create or replace function FT_DEAL_TIME(iMucid number)
return Time_Data_METADATA_Table
PIPELINED is
v_time_data_metadata Time_Data_METADATA;
nowdate date;
predate date;
begin
for x in (select f.positiontime as positiontime,
e.longitude as longitude,
e.latitude as latitude,
f.velocity as velocity
from BMPS_HIS_RECEIVE_GPSSTATUS d,
BMPS_HIS_RECEIVE_GPSJPINFO e,
BMPS_HIS_RECEIVE_GPSINFO f
where d.sequence = f.sequence
and e.sequence = f.sequence
and d.status14 = 1
and d.mcuid = iMucid
order by d.positiontime asc) loop
nowdate := x.positiontime;
--predate := select max(t.positiontime) from table(FT_DEAL_TIME(iMucid)) t;

-- 下面的判断条件得加上第一条记录时predate is null的判断
if predate is null or (nowdate - predate) * 24 * 60 > 5 then
v_time_data_metadata := Time_Data_METADATA(x.positiontime,
x.longitude,
x.latitude,
x.velocity);
pipe row(v_time_data_metadata);
-- 记录前一条记录的时间
predate := nowdate();
end if;
end loop;
return;
end;

xiaobn_cn 2011-10-14
  • 打赏
  • 举报
回复
用的用法有问题,先理清需求吧。你在定义这个函数的位置又引用这个函数,这个可不大对。
蔡袅 2011-10-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xiaobn_cn 的回复:]

predate := select max(t.positiontime) from table(FT_DEAL_TIME(iMucid)) t;;
是这行出错吧?
[/Quote]是的。 不知何故,不会用的。
xiaobn_cn 2011-10-14
  • 打赏
  • 举报
回复
predate := select max(t.positiontime) from table(FT_DEAL_TIME(iMucid)) t;;
是这行出错吧?
蔡袅 2011-10-14
  • 打赏
  • 举报
回复
真的很需要各位指导,谢谢!!
蔡袅 2011-10-14
  • 打赏
  • 举报
回复
Time_Data_METADATA_Table :
CREATE OR REPLACE TYPE Time_Data_METADATA_Table
as table of Time_Data_METADATA


Time_Data_METADATA:
create or replace type Time_Data_METADATA as object
(
dtPOSITIONTIME date,
lLONGITUDE number,
lLATITUDE number,
iVelocity number
)

xiaobn_cn 2011-10-14
  • 打赏
  • 举报
回复
Time_Data_METADATA_Table 的声明部分呢?
Time_Data_METADATA的声明部分呢?

从代码本身看出来问题,猜测问题出在你的TYPE定义部分。

3,499

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧