Oracle包的使用

來源:互聯網
上載者:User

--函數和預存程序都可以單獨定義,這個時候它們分別會出現在pl/sql
--functions的檔案夾和Procedures檔案夾下面

--同時它們又可以同時被定義在package裡面

--而定義在一個package裡面的函數或者預存程序與單獨定義在functions檔案夾下的函數以及定義在procedures檔案夾下面的procedure即便是重名了也是不會相互影響的,因為它們的範圍是不一樣的,因為定義在package裡面的函數或者procedure在被調用的時候需要加上包名才行,而且在包裡面的函數又可以調用外部的函數或者是預存程序。

--不過需要瞭解的而是包只是對於方法和函數的一個定義就像是java裡面的介面一樣
--它只是定義了方法體和預存程序體但是沒有實現,實現需要在package body裡面實現

--這主要也是為了一種規範

--因為建立預存程序經常會出錯,建議看看出錯的常見情況:

create or replace function addDept(
f_deptno dept.deptno%type,
f_dname dept.dname%type,
f_loc dept.loc%type
)
return number
as
begin
insert into dept values(f_deptno,f_dname,f_loc);
if sql%found then
return 1;
else
return 0;
end if;
commit;
end;


--建立刪除部門函數
create or replace function deleteDept(
f_deptno dept.deptno%type
)
return number
as
begin
delete from dept where dept.deptno=f_deptno;
if sql%found then
return 1;
else
return 0;
end if;
end;

  • 1
  • 2
  • 3
  • 4
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.