在java中调用postgresql存储函数并返回?

bzzcjhmw  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(428)

所以我有一个名为“get\u ss\u org\u struct\u ver\u id”的存储函数,它返回双精度

CREATE OR REPLACE FUNCTION public.get_ss_org_struct_ver_id(business_id double precision)
 RETURNS double precision
 LANGUAGE plpgsql
AS $function$
   DECLARE
      v_org_struct_ver_id   double precision;
   BEGIN

    select internalid into v_org_struct_ver_id from WOT_ORG_STRUCTURE_VER where now() between date_from and date_to and business_group_id = business_id;

      RETURN v_org_struct_ver_id;
   EXCEPTION
      WHEN OTHERS
      THEN
         RETURN NULL;
   END;
$function$
;

关键是,我需要在set函数中使用以下存储过程:

CoreOrgStructure coreOrgStructure = new CoreOrgStructure();

coreOrgStructure.setOrgVerId(get_ss_org_struct_ver_id(businessGroupId));

我必须得到businessgroupid的值,但我不知道如何调用该函数。现在,我刚刚创建了null返回类,如:

private Long get_ss_org_struct_ver_id(Long businessGroupId) {
        // TODO Auto-generated method stub
        return null;
    }

我可以调用这个返回类中存储的函数吗?

gr8qqesn

gr8qqesn1#

[编辑:这里真的解决了]
在我看来:

coreOrgStructure.setOrgVerId(coreOrgUnitsService.getOrgVerIdByBusinessGroupId(businessGroupId));

在这个getorgveridbybusinessgroupid(businessgroupid)服务中,它将进入我的dao:

@Override
    public Long getOrgVerIdByBusinessGroupId(Long orgBusinessGroupId) {
        StringBuffer sbQuery = new StringBuffer();
        sbQuery.append(" select get_ss_org_struct_ver_id(:orgBusinessGroupId) ");

        Query result = getSession().createSQLQuery(sbQuery.toString());
        result.setLong("orgBusinessGroupId", orgBusinessGroupId);

        Number results = (Number) result.uniqueResult();
        if(results == null) {
            results = 0;
        }

        return (long) results.intValue();
    }

现在它真的起作用了!除息的

相关问题