儲存過程乙個例項

2021-08-31 12:27:36 字數 1744 閱讀 5378

--下面是關於包的定義

create or replace package pkg_indexdata is

-- author  : yuanqiangl

-- created : 2011-6-8 12:18:08

-- purpose : 指標資料管理

-- public function and procedure declarations

function f_get_details(in_collogid in number, in_indexcode in number, in_orgno in varchar2) return number;

end pkg_indexdata;

--下面是關於包體的定義

create or replace package body pkg_indexdata is

-- function and procedure implementations

function  f_get_exceptioncnt(in_indexid in number,in_collogid in number, in_indexcode in number, in_orgno in varchar2)

return number is

out_cnt number;

v_sql varchar2(4000);

v_tab_name varchar2(256);

begin

--獲取指標明細表表名

select det_table into v_tab_name from p_index where index_id = in_indexid ;

--注意:if不能這種格式:if(...)而且 if裡的條件 連線只能用  and  or ,跟null比較,要寫成 is null 或者 is not null

if v_tab_name is null or ''=trim(v_tab_name) then

return 0;

end if;

v_sql:='select count(1)  

from   '||v_tab_name||'  where col_log_id = '||in_collogid||'

and index_code = '||in_indexcode||'

and org_no in (select org_no

from v_o_org t where level = 2

start with t.org_no ='||in_orgno||'

connect by t.p_org_no = prior t.org_no)';

execute immediate v_sql  into out_cnt;

return      out_cnt;

end;

end pkg_indexdata;

----注:執行動態sql時,若有增刪改的操作,則使用如"execute immediate v_sql returning into out_cnt;"

否則即簡單:execute immediate v_sql into out_cnt

--在sql中的呼叫方式:

select (pkg_indexdata.f_get_exceptioncnt(200,

1,'0393726253',

a.org_no)  expcount  from test;

即:包明.函式名(引數列表)

乙個儲存過程

create or replace package abc zys is procedure daily census end abc zys 建乙個包,包中有儲存過程daily census。不涉及任何引數。create or replace package body abc zys is pro...

乙個儲存過程

首先是建立儲存過程.drop procedure if exists externalcalltocomplete delimiter create procedure externalcalltocomplete begin drop table if exists temp1 create ta...

乙個分頁儲存過程

page language c import namespace system.data import namespace system.data.sqlclient 訂單號 服務專案 預訂日期 操作人員 分配狀態 databinder.eval container.dataitem,offerid...