我正在使用 PostgreSQL,并且我有一个返回记录的函数:
CREATE OR REPLACE FUNCTION fn_lisMatricula()
RETURNS record AS
$BODY$
SELECT mat.codigo as codmatr, mat.codigoalumno as codal, mat.codigoempresa as codemp ,mat.codigopresentacion as codpre,
mat.codigosecretaria as codsec, mat.fecha as fechamat, mat.estado as estadomat,
mat.vigencia as vigmat, p.apellidos as apeAl,
p.nombres as nomAl,razonsocial ,pre.codigocurso as codcur,cur.nombre as curso
FROM matricula mat join alumno al on mat.codigoalumno = al.codigoalumno
join persona p on al.codigoalumno = p.codigo
join persona pe on mat.codigoalumno = pe.codigo
left join empresa emp on mat.codigoempresa = emp.codigo
join presentacion pre on mat.codigopresentacion = pre.codigo
join curso cur on cur.codigo = pre.codigocurso
order by p.apellidos
$BODY$
LANGUAGE sql VOLATILE
我用这个来称呼它,因为我必须声明输出值的类型,这在 Postgres 中可以正常工作:
select * from fn_lisMatricula() as (codmatr integer,codal integer,codemp integer,codpre integer,codsec integer,fechamat date,
estadomat char,vigmat boolean,apeal varchar,nomal varchar,razonsocial varchar,codcur integer,curso varchar)
但是要在 java 中的 callableStatement 中调用它,我使用:
proc = this.cn.prepareCall("{call fn_lisMatricula()}")
但我得到一个 postgreSQL.exception:
返回 «record» 的函数需要列的定义列表
所以我使用preparedStatement在Java中临时解决了这个问题:
PreparedStatement ps;
String SQL = "select * from fn_lisMatricula() as (codmatr integer,codal integer,codemp integer,codpre integer,codsec integer,fechamat date,\n"
+ "estadomat char,vigmat boolean,apeal varchar,nomal varchar,razonsocial varchar,codcur integer,curso varchar)";
ps = this.cn.prepareStatement(SQL);
我想使用 callableStatement。我怎样才能做到这一点?