Hibernate动态创建视图
程序员文章站
2022-07-13 12:06:13
...
create or replace procedure pro_view_TblAutoAnalyse(queryPara varchar2,orderSort varchar2) is
querySql varchar2(1000);
begin
querySql := 'create or replace view v_TblAutoAnalyse as select * from tbl_auto_analyse where 1=1 ';
if queryPara is not null then
querySql := querySql || queryPara;
end if;
if orderSort is not null then
querySql := querySql || orderSort;
end if;
EXECUTE IMMEDIATE querySql;
end pro_view_TblAutoAnalyse;
/**
* 根据条件创建动态视图
* @param valueMap
* @throws Exception
*/
private void createDynamicView(HashMap valueMap)throws Exception{
Session session = hibernateTemplate.getSessionFactory().openSession();
Connection conn = session.connection();
CallableStatement call = conn.prepareCall("{Call pro_view_TblAutoAnalyse(?,?)}");
call.setString(1, valueMap.get("soc_sql")==null?"":valueMap.get("soc_sql").toString());
call.setString(2, valueMap.get("soc_orderby")==null?"":valueMap.get("soc_orderby").toString());
call.executeUpdate();
session.close();
}
querySql varchar2(1000);
begin
querySql := 'create or replace view v_TblAutoAnalyse as select * from tbl_auto_analyse where 1=1 ';
if queryPara is not null then
querySql := querySql || queryPara;
end if;
if orderSort is not null then
querySql := querySql || orderSort;
end if;
EXECUTE IMMEDIATE querySql;
end pro_view_TblAutoAnalyse;
/**
* 根据条件创建动态视图
* @param valueMap
* @throws Exception
*/
private void createDynamicView(HashMap valueMap)throws Exception{
Session session = hibernateTemplate.getSessionFactory().openSession();
Connection conn = session.connection();
CallableStatement call = conn.prepareCall("{Call pro_view_TblAutoAnalyse(?,?)}");
call.setString(1, valueMap.get("soc_sql")==null?"":valueMap.get("soc_sql").toString());
call.setString(2, valueMap.get("soc_orderby")==null?"":valueMap.get("soc_orderby").toString());
call.executeUpdate();
session.close();
}