使用带有布尔IN参数的@NamedPLSQLStoredFunctionQuery,未安装'SYS.SQLJUTL'

时间:2015-06-23 08:51:11

标签: oracle java-ee jpa eclipselink jpa-annotations

环境 - JavaSE 6,Oracle 11,WebSphere 7,eclipseLink 2.5.2

用例 我们想用

@NamedPLSQLStoredFunctionQuery
像这样:

@NamedPLSQLStoredFunctionQuery
   (name = "convertToString",
    functionName = "my_schema.my_package.convert_to_string",
    parameters =
      { @PLSQLParameter(name = "p_boolean", databaseType = "BOOLEAN") },
        returnParameter = @PLSQLParameter(name = "RESULT", databaseType = "VARCHAR_TYPE"))

我们执行这样的函数:

Query query = em.createNamedQuery("convertToString");
        query.setParameter("p_boolean", true);
        Object result = query.getSingleResult();
        System.out.println("result=" + result);

和/或

Query query = em.createNamedQuery("convertToInteger");
        query.setParameter("p_boolean", true);
        Object result = query.getSingleResult();
        System.out.println("result=" + result);

我们的Oracle函数实现如下:

CREATE OR REPLACE package body my_schema.my_package
as
    /**
    * Converts the given boolean into an integer (true: 1, false: 0).
    * @param p_boolean boolean value to convert to an integer
    */
    function convert_to_integer
    (
        p_boolean   in boolean
    )
        return integer
    is
    begin
        if (p_boolean = true) then
            return isac_api.api_boolean_constants_pg.integer_true;
        end if;

        return isac_api.api_boolean_constants_pg.integer_false;
    end;

    /**
    * Converts the given boolean into a string (true: 'true', false: 'false').
    * @param p_boolean boolean value to convert
    */
    function convert_to_string
    (
        p_boolean   in boolean
    )
        return varchar2
    is
    begin
        if (p_boolean = true) then
            return isac_api.api_boolean_constants_pg.string_true;
        end if;

        return isac_api.api_boolean_constants_pg.string_false;
    end;
end;

它确实不起作用。

问题

  • 有什么问题?
  • 如果我们不允许在数据库上安装'SYS.SQLJUTL',我们该怎么办?但eclipseLink似乎用它来进行转换?

此致 扬

0 个答案:

没有答案