我有2个Oracle存储过程,一个用于设置全局变量,另一个用于以sys_refcursor的形式获取数据。 在PLSQL开发人员中,我以这种方式使用它:
begin
PKG_ARM_STRUCT.set_context_variables(37159,3,15,20181201,20171201,9,5,300,null);
end;
select pkg_arm_data.f_get_data from dual
它工作正常,并且f_get_data向我返回sys_refcursor数据。
现在,我想在Play框架中像这样执行它:
def getSliceTabData = db.withConnection { implicit connection =>
val rowParser: RowParser[Map[String,Any]] =
SqlParser.folder(Map.empty[String, Any]) { (map, value, meta) =>
Right(map + (meta.column.qualified -> value))
}
val rContext : SqlQueryResult = SQL("EXEC PKG_ARM_STRUCT.set_context_variables(37159,3,15,20181201,20171201,9,5,300,null)")
.executeQuery()
val parsedRes: List[Map[String, Any]] = SQL("select pkg_arm_data.f_get_data from dual").as(rowParser.*)
}
从数据库日志中,我可以看到pkg_arm_data.f_get_data正在正确调用,并且此过程看不到必须由set_context_variables设置的全局变量。
过程代码set_context_variables(在包装中):
procedure set_context_variables(
p_user_id in number default null,
p_user_role in number default null,
p_budget in number default 15,
p_ddate in number default null,
p_appg_date in number default null,
p_book in number default null,
p_tab in number default null,
p_slice in number default null,
p_pok in number default null
) is
begin
MSK_ANALYTICS.Set_Curr_Date_Context(s_date => TO_CHAR(TO_DATE(TO_CHAR(p_ddate),'yyyymmdd'),'dd.mm.yyyy'));
DBMS_SESSION.SET_CONTEXT('CLIENTCONTEXT','s_date_context',TO_CHAR(TO_DATE(TO_CHAR(p_ddate),'yyyymmdd'),'dd.mm.yyyy'));
g_user_id := p_user_id;
g_ddate := p_ddate;
g_appg_date := p_appg_date;
g_book_id := p_book;
g_slice_id := p_slice;
g_tab_id := p_tab;
g_pok_id := p_pok;
g_budget_id := p_budget;
if p_user_role != 0 then
g_user_role := p_user_role;
else
g_user_role := pkg_common.f_get_user_adm_level(p_user_id => p_user_id);
end if;
end;