【发布时间】:2016-11-13 19:39:32
【问题描述】:
我创建了复合类型
Create Type TestDetailReportType1 As
(
sName text,
cDetailsTimeStamp timestamp,
number text,
dropdi text,
queue text,
agent text,
status int,
reference int
)
我创建了一个游标,我希望它返回一个复合类型列表...但是当我执行 select * from TestdetailsCursortest11("abc") 时没有返回记录 但是在执行时直接在函数中编写的查询返回 31 行...我是 postgress 新手,所以我无法理解在执行此函数时我出错的地方,非常感谢前面的任何指导。
注意->我特别想在这种情况下写一个游标...当函数返回表时,我成功地能够得到结果。
CREATE OR REPLACE FUNCTION public.TestdetailsCursortest11(
hgname text)
RETURNS SETOF TestDetailReportType1
LANGUAGE 'plpgsql'
AS $TestdetailsCursortest11$
DECLARE
cDetailcursor refcursor;
cDetailtEvent RECORD; -- variable to store agent event.
cDetail callDetailReportType1;
BEGIN
OPEN cDetailcursor FOR
select tblUsers.UserName,tblCallEvent.StateCreateDate,tblCallRegister.Cli,tblCallRegister.DDI,tblhuntGroup.name,
tblUsers.Extension,
tblCallEvent.StateID,
tblCallRegister.CallID
from tblCallRegister
inner join tblCallEvent on tblCallRegister.callregisterid= tblCallEvent.callregisterid
inner join tblUsers on tblUsers.userid=tblCallEvent.agentid
inner join tblhuntGroup on tblhuntGroup.HGID=tblCallEvent.HGID
where name=hgname;
FETCH NEXT FROM callDetailcursor INTO callDetailtEvent;
callDetail.sName=callDetailtEvent.UserName;
callDetail.cDetailsTimeStamp=callDetailtEvent.StateCreateDate;
callDetail.number =callDetailtEvent.Cli;
IF callDetailtEvent.StateID = 19
THEN
callDetail.dropdi=callDetailtEvent.DDI;
ELSE
callDetail.dropdi=callDetailtEvent.DDI+1;
END IF;
callDetail.queue=callDetailtEvent.name;
callDetail.agent=callDetailtEvent.Extension;
callDetail.status =callDetailtEvent.StateID;
callDetail.reference=callDetailtEvent.CallID;
RETURN;
CLOSE callDetailcursor;
END;
$TestdetailsCursortest11$;
【问题讨论】:
标签: postgresql