使用 iBatis 的 PostgreSQL 存储过程
应用参数映射时发生错误:
--- Check the newSubs-InlineParameterMap.
--- Check the statement (query failed).
--- Cause:
org.postgresql.util.PSQLException:
ERROR: wrong record type supplied in RETURN NEXT Where:
PL/pgSQL function "getnewsubs" line 34 at return next
函数详细信息如下......
CREATE OR REPLACE FUNCTION getnewsubs(timestamp without time zone, timestamp without time zone, integer)
RETURNS SETOF record AS
$BODY$declare
v_fromdt alias for $1;
v_todt alias for $2;
v_domno alias for $3;
v_cursor refcursor;
v_rec record;
v_cpno bigint;
v_actno int;
v_actname varchar(50);
v_actid varchar(100);
v_cpntypeid varchar(100);
v_mrp double precision;
v_domname varchar(100);
v_usedt timestamp without time zone;
v_expirydt timestamp without time zone;
v_createdt timestamp without time zone;
v_ctno int;
v_phone varchar;
begin
open v_cursor for select cpno,c.actno,usedt from cpnusage c inner join account s on s.actno=c.actno where usedt >= $1 and usedt < $2 and validdomstat(s.domno,v_domno) order by c.usedt;
fetch v_cursor into v_cpno,v_actno,v_usedt;
while found
loop
if isactivation(v_cpno,v_actno,v_usedt) IS TRUE then
select into v_actno,v_actname,v_actid,v_cpntypeid,v_mrp,v_domname,v_ctno,v_cpno,v_usedt,v_expirydt,v_createdt,v_phone a.actno,a.actname as name,a.actid as actid,c.descr as cpntypeid,l.mrp as mrp,s.domname as domname,c.ctno as ctno,b.cpno,b.usedt,b.expirydt,d.createdt,a.phone from account a
inner join cpnusage b on a.actno=b.actno
inner join cpn d on b.cpno=d.cpno
inner join cpntype c on d.ctno=c.ctno
inner join ssgdom s on a.domno=s.domno
left join price_class l ON l.price_class_id=b.price_class_id
where validdomstat(a.domno,v_domno) and b.cpno=v_cpno and b.actno=v_actno;
select into v_rec v_actno,v_actname,v_actid,v_cpntypeid,v_mrp,v_domname,v_ctno,v_cpno,v_usedt,v_expirydt,v_createdt,v_phone;
return next v_rec;
end if;
fetch v_cursor into v_cpno,v_actno,v_usedt;
end loop;
return ;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION getnewsubs(timestamp without time zone, timestamp without time zone, integer) OWNER TO radius
如果我从控制台运行该函数,它运行良好并给出正确的响应。但是当通过java使用时就会出现上述错误。
The error occurred while applying a parameter map:
--- Check the newSubs-InlineParameterMap.
--- Check the statement (query failed).
--- Cause:
org.postgresql.util.PSQLException:
ERROR: wrong record type supplied in RETURN NEXT Where:
PL/pgSQL function "getnewsubs" line 34 at return next
the function detail is as below....
CREATE OR REPLACE FUNCTION getnewsubs(timestamp without time zone, timestamp without time zone, integer)
RETURNS SETOF record AS
$BODY$declare
v_fromdt alias for $1;
v_todt alias for $2;
v_domno alias for $3;
v_cursor refcursor;
v_rec record;
v_cpno bigint;
v_actno int;
v_actname varchar(50);
v_actid varchar(100);
v_cpntypeid varchar(100);
v_mrp double precision;
v_domname varchar(100);
v_usedt timestamp without time zone;
v_expirydt timestamp without time zone;
v_createdt timestamp without time zone;
v_ctno int;
v_phone varchar;
begin
open v_cursor for select cpno,c.actno,usedt from cpnusage c inner join account s on s.actno=c.actno where usedt >= $1 and usedt < $2 and validdomstat(s.domno,v_domno) order by c.usedt;
fetch v_cursor into v_cpno,v_actno,v_usedt;
while found
loop
if isactivation(v_cpno,v_actno,v_usedt) IS TRUE then
select into v_actno,v_actname,v_actid,v_cpntypeid,v_mrp,v_domname,v_ctno,v_cpno,v_usedt,v_expirydt,v_createdt,v_phone a.actno,a.actname as name,a.actid as actid,c.descr as cpntypeid,l.mrp as mrp,s.domname as domname,c.ctno as ctno,b.cpno,b.usedt,b.expirydt,d.createdt,a.phone from account a
inner join cpnusage b on a.actno=b.actno
inner join cpn d on b.cpno=d.cpno
inner join cpntype c on d.ctno=c.ctno
inner join ssgdom s on a.domno=s.domno
left join price_class l ON l.price_class_id=b.price_class_id
where validdomstat(a.domno,v_domno) and b.cpno=v_cpno and b.actno=v_actno;
select into v_rec v_actno,v_actname,v_actid,v_cpntypeid,v_mrp,v_domname,v_ctno,v_cpno,v_usedt,v_expirydt,v_createdt,v_phone;
return next v_rec;
end if;
fetch v_cursor into v_cpno,v_actno,v_usedt;
end loop;
return ;
end;$BODY$
LANGUAGE 'plpgsql' VOLATILE;
ALTER FUNCTION getnewsubs(timestamp without time zone, timestamp without time zone, integer) OWNER TO radius
If I run the function from the console it runs fine and gives the correct response. But when used through java it causes the above error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误的直接原因:一个或多个变量
v_cpno,v_actno,v_usedt
的数据类型与表cpnusage
和account
中的相应列不匹配代码>.更一般地说,您的 plpgsql 函数不必要地复杂和晦涩。可以用一小部分代码来编写。我简化为:
可能可以简化为单个
RETURN QUERY
。但我已经把这匹死马打败得够多了。Immediate cause of the error: The datatype of one or more these variables
v_cpno,v_actno,v_usedt
does not match the corresponding columns in the tablescpnusage
andaccount
.More generally, your plpgsql function is needlessly complicated and obscure. Could be written with a fraction of the code. I simplified to:
Could probably be simplified to a single
RETURN QUERY
. But I have beaten this dead horse quite enough.