找到了答案。首先,我做了一个名为 getSrid 的 plpgsql 函数
CREATE OR REPLACE FUNCTION getSRID() returns text[] as $$
declare
resultado text[];
consulta cursor for
Select srid,substring(srtext from (position('DATUM["' in srtext)+7)
for(position('ID["' in srtext)+2)
- (position('DATUM["' in srtext)+7)) as sub
from spatial_ref_sys;
cont int;
i int;
sridd int;
srTextt text;
begin
open consulta;
i=1;
EXECUTE 'SELECT COUNT(*) FROM SPATIAL_REF_SYS' into cont;
resultado := ARRAY[cont];
while(i<cont) loop
fetch consulta into sridd,srTextt;
resultado[i] := sridd;
resultado[i+1] := srTextt;
i:=i+2;
end loop;
return resultado;
end
$$ language plpgsql;
如您所见,我在返回时得到了一个 Text[],所以在我的 java 调用中,我将对象转换为 String[]:
public List<SridDTO> listaa(){
int i = 0;
List<SridDTO> list = new ArrayList<SridDTO>();
Query query = em().createNativeQuery("Select getSrid()");
String[] vector = (String[]) query.getSingleResult();
while(i<vector.length){
SridDTO sridDTO = new SridDTO(new Long(vector[i]),vector[i+1]);
i = i + 2;
list.add(sridDTO);
}
return list;
}