环境 - 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;
它确实不起作用。
问题
此致 扬