包頭(Package)與包體(Package body)的學習與應用
包由包規範和包體兩部分組成。
特點:
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
定義包體:
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
只有當包頭編輯成功後才能編輯包體,其中的函式名與過程名須和包頭中的函式過程一樣。
包應用的一個例子:
包的作用: 根據出生年月返回年齡function Getage,返回工資function Getsalary
--建立環境
--新增資料
--建立包頭
--建立包體
--測試
特點:
定義包頭:1.將有聯絡的物件打成包,方便使用;
2.包中物件包括儲存過程、函式、遊標、自定義型別和變數,可以在PL_SQL塊中應用這些物件。
----------------------------------------------------------------------------------------------
create_package ::=
----------------------------------------------------------------------------------------------
定義包體:
----------------------------------------------------------------------------------------------
create_package_body ::=
----------------------------------------------------------------------------------------------
只有當包頭編輯成功後才能編輯包體,其中的函式名與過程名須和包頭中的函式過程一樣。
包應用的一個例子:
包的作用: 根據出生年月返回年齡function Getage,返回工資function Getsalary
--建立環境
Create Table T_PsnSalary --工資表
(
Fpsncode varchar(4) default '', --個人程式碼
Fpsndesc varchar(20) default '', --描述
FpsnBirth varchar(20) default '', --生日
FpsnSalary number(8,2) --工資
);
--新增資料
Insert into T_PsnSalary(Fpsncode,Fpsndesc,FpsnBirth,FpsnSalary) Values('C001','張三','1986.01.10',1100);
Insert into T_PsnSalary(Fpsncode,Fpsndesc,FpsnBirth,FpsnSalary) Values('C002','李四','1980.10.10',3000);
Insert into T_PsnSalary(Fpsncode,Fpsndesc,FpsnBirth,FpsnSalary) Values('C003','王五','1996.12.10',800);
commit;
--建立包頭
create or replace package A_GetData is
function Getage(birthst varchar,birthend varchar) return integer;
function Getsalary(VFpsncode varchar) return number;
end A_Getdata;
--建立包體
create or replace package body A_GETDATA is
function Getage(birthst varchar,birthend varchar) return integer --得到年齡函式
is
V_birth integer;
ToDateEnd Date;
Toyear number(4);
Tomonth number(4);
Fromyear number(4);
Frommonth number(4);
begin
if (birthend='') or (birthend is null) then
select sysdate into ToDateEnd from dual; --得到系統時間
end if;
Toyear := to_number(to_char(ToDateEnd,'YYYY')); --得到最後年月
Tomonth := to_number(to_char(ToDateEnd,'MM'));
Fromyear := to_number(substr(birthst,1,4));--計算的年月
Frommonth := to_number(substr(birthst,6,2));
if Tomonth-Frommonth>0 then V_birth:=Toyear-fromyear;
else V_birth:=Toyear-fromyear-1;
end if;
return(V_birth);
end Getage;
function getSalary(VFpsncode varchar) return number--返回工資情況
is
V_psnSalary number(8,2);
begin
Select FpsnSalary into V_psnSalary from T_PsnSalary where Fpsncode=VFpsncode;
return(V_psnSalary);
end getSalary;
end A_GETDATA;
--測試
select a.*,A_getdata.Getage(Fpsnbirth,'')age from T_psnsalary a; --呼叫包得到年齡功能參考:
select A_getdata.Getsalary('C001') from dual; --程式碼得到工資
1、http://blog.csdn.net/moonzhang520/article/details/4036210
2、http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/create_package_body.htm#LNPLS01372
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29439655/viewspace-1071317/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- java 包(package)JavaPackage
- 關於包(Package)應用規範的說明 (轉)Package
- PL/SQL 09 包 packageSQLPackage
- Package Specification 和 Package Body 及 Package有什麼區別? (轉)Package
- perl的包(package)和模組(PM)Package
- ORA-04042 procedure, function, package, or package body does not existFunctionPackage
- Oracle 查詢某一個包體’PACKAGE BODY‘中包含PROCEDURE/FUNCTION的名稱有哪些OraclePackageFunction
- go package包名規範GoPackage
- java物件導向(包package)Java物件Package
- 應用市場中包名(package name)的唯一性Package
- 關鍵字、Package 包的使用、import 的用法 - Go 學習記錄PackageImportGo
- npm入門(二)—package(包)的管理NPMPackage
- zt_aix常用軟體包software package小概念AIPackage
- 2-2 Go語言的包(package)GoPackage
- Oracle Data Integrator 12c----包(Package)OraclePackage
- Python的包(package)和模組(module)介紹PythonPackage
- 如何使用lerna進行多包(package)管理Package
- create or replace package body DBMS_ASSERT wrappedPackageAPP
- GO語言學習筆記-包結構篇 Study for Go ! Chapter eight - Package StructureGo筆記APTPackageStruct
- [z] 利用閃回恢復被覆蓋的Oracle PACKAGE包OraclePackage
- package鎖的查詢與解鎖Package
- 未能正確載入“visual C++ package”包C++Package
- dbms_scheduler package body INVALID 解決方案Package
- 利用 Python 的 package 機制簡化 utils 包設計PythonPackage
- 我的Duke線上銀行打不了包(ant package-ejb)?Package
- Python學習之模組與包Python
- Appium學習筆記1_獲取到APK安裝包的Package以及Activity屬性值APP筆記APKPackage
- python閉包 - 理解與應用Python
- Go 應用中 package main 的規則GoPackageAI
- user_dependencies_trigger_view_package_body依賴ViewPackage
- JAVA學習之路 (七) package包管理JavaPackage
- npm-package-json-lint 是一個用於檢查 package.json 檔案格式和內容規範的 npm 包。NPMPackageJSON
- 為了前端的深度-閉包概念與應用前端
- not an rpm package (or package manifest):Package
- not an rpm package (or package manifest)Package
- packagePackage
- Oracle Package在itpub菠菜上的一點應用OraclePackage
- ORA-04063: package body "SYS.DBMS_EXPORT_EXTENSION" has errorsPackageExportError