Oracle創建帶字符串參數的視圖

--創建包
create or replace package p_view_param is

  function set_budget_date_param(budget_date varchar2) return varchar2;
  function get_budget_date_param return varchar2;
  
end p_view_param;

--實現包體
create or replace package body p_view_param is

  paramValue varchar2(10);
  
  function set_budget_date_param(budget_date varchar2) return varchar2 is
  begin
    paramValue:=budget_date;
    return budget_date;
  end;

  function get_budget_date_param return varchar2 is
  begin
    return paramValue;
  end;   
end p_view_param;

--創建視圖
create or replace view zx_xxb_budget_month_sum參數 as
select so.code as 機構代碼,
       so.name as 機構名稱,
       so.area 區域,
       bs.budget_date 預算年月,
       decode(bs.status,null,'未彙總','0','未彙總','1','審批不通過','2','審批中','3','審批通過') as 彙總情況 ,
       bs.status as 彙總狀態,
       bs.user_name as 預算彙總人,
       bs.post_id as 崗位ID,
       bs.post_name as 崗位名稱,
       bs.total_amount as 總金額,
       bs.cancel_instructions as 取消彙總說明,
       bs.type_name as 申請類型名稱,
       decode(so.status,'enabled','啓用','disabled','禁用') as 是否啓用
  from sec_organization so 
  left join budget_summary bs
    on so.id = bs.org_id and bs.budget_date = p_view_param.get_budget_date_param()
 order by so.code
 
--查詢數據

select * from zx_xxb_budget_month_sum參數 t where p_view_param.set_budget_date_param('參數') = '參數'
select * from zx_xxb_budget_month_sum參數 t where p_view_param.set_budget_date_param('201903') = '201903'

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章