包用于在邏輯上組合過程和函數(shù),它由包規(guī)范和包體兩部分組成
10年積累的成都網(wǎng)站設(shè)計、成都做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先做網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有普寧免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
1.創(chuàng)建包
--創(chuàng)建一個包sp_package
create?package?sp_package?is
--聲明該包有一個過程和函數(shù),(沒有實現(xiàn))
procedure?update_sal(name?varchar2,newsal?number);
function?annual_nicome(name?varchar2)?return?number;
end;
--創(chuàng)建包體(用于實現(xiàn)已經(jīng)聲明的函數(shù)和過程)
create?package?body?sp_package?is
procedure?update_sal(name?varchar2,newsal?number)
is
BEGIN
UPDATE?emp
SET????sal?=?newsal
WHERE??ename?=?name;
END;
function?annual_income(name?varchar2)
return?number?is
annual_salary?number;
BEGIN
SELECT?sal?*?12?+?Nvl(comm,0)
INTO???annual_salary
FROM???emp
WHERE??ename?=?name;
RETURN?annual_salary;
END;
end;
--調(diào)用包中的內(nèi)容
exec?sp_package.update_sal('name',number);
--創(chuàng)建包頭
CREATE OR REPLACE PACKAGE ELS.pkg_proxy
AS
TYPE cursortype IS REF CURSOR;
-- 得到交接確認(rèn)代理人數(shù)據(jù)
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --當(dāng)前登錄用戶
v_to_emp_no IN VARCHAR2, --代理人工號
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理開始時間: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理結(jié)束時間: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工號
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
);
END pkg_proxy;
--創(chuàng)建包頭
CREATE OR REPLACE PACKAGE BODY ELS.pkg_proxy
AS
-- 得到交接確認(rèn)代理人數(shù)據(jù)
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --當(dāng)前登錄用戶
v_to_emp_no IN VARCHAR2, --代理人工號
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理開始時間: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理結(jié)束時間: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工號
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
)
AS
BEGIN
OPEN p_cursor FOR
WITH v AS
(
--查找當(dāng)前登錄人是否為管理員
SELECT *
FROM employee
WHERE dept_id IN (
SELECT ID
FROM department
START WITH ID =
(SELECT dept_id
FROM employee
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch')
UNION
SELECT dept_id
FROM employee_add
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch'))
CONNECT BY PRIOR ID = parent_id)
UNION
SELECT *
FROM employee
WHERE emp_no = v_emp_no)
SELECT DISTINCT *
FROM (SELECT a.currentuser, a.toagrentuser,
DECODE (a.agent_type,
'A', '當(dāng)前交接確認(rèn)代理',
'B', '將來離職簽核代理',
'C', '當(dāng)前離職簽核代理',
'D', '將來交接確認(rèn)代理',
''
) agent_type,
a.from_date, a.TO_DATE,
DECODE
(a.to_date1,
'', '無',
TO_CHAR (a.TO_DATE,
'yyyy/mm/dd am hh:mi:ss'
)
) to_date1,
a.flowinfo, b.emp_cname AS currentusername,
b1.emp_cname AS toagrentusername, workitem
FROM (
--當(dāng)前交接確認(rèn)代理
SELECT SUBSTR
(x.currentuser,
1,
INSTR (x.currentuser, '(') - 1
) AS currentuser,
SUBSTR
(x.toagrentuser,
1,
INSTR (x.toagrentuser, '(') - 1
) AS toagrentuser,
'A' AS agent_type,
x.create_date AS from_date,
x.create_date AS TO_DATE,
NULL AS to_date1, x.workid,
NULL AS formid, y.NAME workitem,
(SELECT e.emp_no
|| '('
|| e.emp_cname
|| ')'
FROM employee e
WHERE e.emp_no = y.emp_no)
AS flowinfo
FROM currentworkagrent x,
worktransferitem_m y
WHERE x.workid = y.ID
UNION ALL
--將來交接確認(rèn)代理
SELECT SUBSTR
(currentuser,
1,
INSTR (currentuser, '(') - 1
) AS currentuser,
SUBSTR
(toagrent,
1,
INSTR (toagrent, '(') - 1
) AS toagrent,
'D' AS agent_type, starttime,
endtime, endtime AS to_date1, NULL,
NULL, NULL, NULL
FROM futureagrent) a,
employee b,
employee b1
WHERE a.currentuser = b.emp_no(+)
AND a.toagrentuser = b1.emp_no(+)) a
WHERE currentuser IN (SELECT emp_no
FROM v)
AND (currentuser = v_from_emp_no OR v_from_emp_no IS NULL
)
AND ( currentusername = v_from_emp_name
OR v_from_emp_name IS NULL
)
AND (toagrentuser = v_to_emp_no OR v_to_emp_no IS NULL)
AND ( toagrentusername = v_to_emp_name
OR v_to_emp_name IS NULL
)
AND from_date =
TO_DATE (NVL (v_proxy_date2, '2099/12/31'),
'yyyy/mm/dd'
)
AND TO_DATE =
TO_DATE (NVL (v_proxy_date1, '1000/12/31'),
'yyyy/mm/dd'
)
ORDER BY a.agent_type, a.from_date DESC;
END;
END pkg_proxy;
在存儲過程或函數(shù)里調(diào)用oracle包的話,首先要有執(zhí)行這個包的權(quán)限;如果包屬于其他的用戶(不是系統(tǒng)包),調(diào)用時:用戶名.包名.存儲過程(參數(shù))名或者
變量:=用戶名.包名.函數(shù)(參數(shù));因為函數(shù)有返回值,變量類型要跟函數(shù)返回值的類型一致。
在command
下調(diào)用的話:exec
用戶名.包名.存儲過程名(參數(shù));select
用戶名.包名.函數(shù)名(參數(shù))
from
dual;就可以了。包屬于當(dāng)期用戶可以不寫用戶名。
網(wǎng)站欄目:oracle怎么設(shè)置包,oracle包的作用
鏈接分享:http://www.rwnh.cn/article24/dscdoce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、Google、用戶體驗、企業(yè)網(wǎng)站制作、動態(tài)網(wǎng)站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)