oracle題目(編寫程式包,此程式包中有過程和函式。以下省略,請看補充)

時間 2021-05-06 00:12:41

1樓:匿名使用者

create or replace package pk2 is

procedure jobs(empid scott.emp.job%type,numbs out number);

function depts(deptid scott.emp.deptno%type) return number;

end pk2;

/create or replace package body pk2 is

procedure jobs(empid scott.emp.job%type,numbs out number) is

begin

select count(*)

into numbs

from emp

where job = empid;

exception

when others then

numbs := 0;

end;

function depts(deptid scott.emp.deptno%type) return number is

numbs number;

begin

select count(*)

into numbs

from emp

where deptno = deptid;

return numbs;

exception

when others then

return 0;

end;

end pk2;/

用oracle編寫程式包,包中含有一個過程和一個函式

2樓:走過路過

create or replace package pk2 is

procedure jobs(empid scott.emp.job%type,numbs out number);

function depts(deptid scott.emp.deptno%type) return number;

end pk2;

/create or replace package body pk2 is

procedure jobs(empid scott.emp.job%type,numbs out number) is

begin

select count(*)

into numbs

from emp

where job = empid;

exception

when others then

numbs := 0;

end;

function depts(deptid scott.emp.deptno%type) return number is

numbs number;

begin

select count(*)

into numbs

from emp

where deptno = deptid;

return numbs;

exception

when others then

return 0;

end;

end pk2;/

3樓:匿名使用者

過程能夠輸出所有的student表的學生姓名(name欄位)和學號(id欄位)值。

函式能夠根據傳入的id引數,檢索出該id值對應的學生姓名(name欄位值),如果不存在,輸出「該學生不存在」

編寫oracle包、過程或者函式,返回結果集,並且編寫另一個過程或函式接收這個結果集並且輸出;誰能提供思

4樓:匿名使用者

-- 測試表資料。

select * from test_main;

id value

---------- --------------------

1 one

3 three

2 two

-- 返回結果集的函式.

create or replace function get_test_main_all

return sys_refcursor

isreturn_cursor sys_refcursor;

begin

open return_cursor for 'select * from test_main';

return return_cursor;

end;

/-- 普通的查詢,來檢視結果.

select get_test_main_all() from dual;

get_test_main_all()

--------------------

cursor statement : 1

cursor statement : 1

id value

---------- --------------------

1 one

3 three

2 two

-- 儲存過程呼叫, 來獲取結果.

declare

-- 呼叫函式的返回值.

testcursor sys_refcursor;

-- 儲存單行資料.

testrec  test_main%rowtype;

begin

-- 呼叫返回結果集的函式.

testcursor := get_test_main_all();

-- 迴圈,遍歷結果.

loop

-- 遊標向前.

fetch testcursor into testrec;

-- 無資料的情況下,退出迴圈.

exit when testcursor%notfound;

-- 輸出除錯資訊.

dbms_output.put_line( to_char(testrec.id) || ' ' || testrec.value);

end loop;

end;

/1 one

3 three

2 two

pl/sql 過程已成功完成。

5樓:匿名使用者

如果要返回多個值,可考慮用儲存過程實現

6樓:

先編寫一個函式返回結果集,再另外編寫一個過程呼叫此函式並返回就好了。

怎麼看程式包裡到底有哪些函式

7樓:匿名使用者

找到編譯設定裡設定指定生成的中間檔案,字尾為.map的映像檔案,編輯開啟它,其中統計了你的程式用到的庫、函式,以及各部分佔用記憶體的詳細情況。

如何建立oracle包,如何呼叫包的過程或是函式

8樓:匿名使用者

包用於在邏輯上組合過程和函式,它由包規範和包體兩部分組成。

1)、我們可以使用create package命令來建立包,如:

i、建立一個包sp_package

ii、宣告該包有一個過程update_sal

iii、宣告該包有一個函式annual_income

--宣告該包有一個儲存過程和一個函式

create package sp_package is

procedure update_sal(name varchar2, newsal number);

function annual_income(name varchar2) return number;

end;

2)、建立包體可以使用create package body命令

給包sp_package實現包體

create or replace package body sp_package is

--儲存過程

procedure update_sal(name varchar2, newsal number) is

begin

update emp set sal = newsal where ename = name;

commit;

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;

/3)、如何呼叫包的過程或是函式

當呼叫包的過程或是函式時,在過程和函式前需要帶有包名,如果要訪問其它方案的包,還需要在包名前加方案名。如:

--呼叫儲存過程

sql> exec sp_package.update_sal('scott', 8888);

--呼叫函式

var income number;

call sp_package.annual_income('scott') into:income;

print income;

特別說明:包是pl/sql 中非常重要的部分,我們在使用過程分頁時,將會再次體驗它的威力呵呵。

觸發器觸發器是指隱含的執行的儲存過程。當定義觸發器時,必須要指定觸發的事件和觸發的操作,常用的觸發事件insert,update,delete 語句,而觸發操作實際就是一個pl/sql 塊。可以使用create trigger 來建立觸發器。

特別說明:我們會在後面詳細為大家介紹觸發器的使用,因為觸發器是非常有用的,可維護資料庫的安全和一致性。

oracle中如何執行已經寫好的儲存過程,就exec 一下?好像不行哦,請舉例說明

9樓:知識雜集

這個得看你在**執行了,如果是命令視窗用 exec 儲存過程名 就可以。

如果是pl/sql視窗就得用 beging 過程名 end; 包含起來作為匿名塊來執行。

10樓:匿名使用者

儲存過程是為了更好的適應於其他的軟體設計功能而產生的一個功能函式。基本只用有資料庫的人反而沒有大用,,,但是做軟體開發的一定會用 他們會有自己開發工具或者框架的方法來呼叫這個函式 ,從而省略大量的sql邏輯批次;例如取錢後再存錢 減1000的同時另外的賬號加1000;只有sql語句就可能2次+, 但他們搞開發的直接調函式名字是不是更效率 更安全呢? 而且它還可以返回值;就是個方法嘛是吧?

--------------純手打, 給分啊

11樓:

call proc('x');

oracle 包中函式修改了其中一個函式,能不能只編譯其中一個函式就行了?

12樓:匿名使用者

不行,編譯的話整個包體全部都會被編譯,而不會你滑鼠圈**編譯**,如果你怕其他過程被編譯,你就把這個過程另拿出來create一個吧,然後在呼叫這個包裡的其他過程。

13樓:匿名使用者

如果你保證其他都沒有問題的話,那麼可以只編譯一個,其他在呼叫時應該會自動編譯。

但是如果別的也有問題,那麼你無法及時發現問題的。

14樓:0午夜流浪

修改函式的時候,有可能呼叫這個函式的儲存過程等都會失效,編譯完成後,檢視一下有沒有其他失效的包和過程,函式等,失效的話就要重新編譯

oracle如何在已定義的包中新增一個過程?

15樓:匿名使用者

建立包時,包分為兩個部分,包頭和body部分,在包頭部分宣告包內容,可以包括過程,函式啊等,body部分是包內容的詳細部分,你的過程就寫在body部分,找找包定義看看就知道了。

--------------------------------這個簡單啊,再建立跟原來一樣的包名稱 用replace關鍵字啊!

create or replace package.....

資料庫在編譯時,會自動查詢替換,就可以將procedure加進去了!

oracle多列求和語句合併,oracle中某列是數值列,如何相加並顯示出來,oracle語句要的是

青鳥中關村專家 可以使用多表連線查詢實現 1 先對錶1進行分組聚合查詢,並將查詢結果定義別名2 在對錶2進行分組聚合查詢,並將查詢結果定義別名3 將兩個查詢結果進行連線查詢,在從中查詢想要的結果列資訊select b.aa,b.bb,c.ccfrom select 表1.aa,sum 表1.bb c...

Oracle查詢去除重資料,oracle查詢出來的資料怎麼消除重複資料?

1 distinct 關鍵字的用法 distinct 關鍵字後面的欄位組合去重 distinct 必須 select distinct id from test 結果 根據id 去重 select distinct id,name from test 2 group by 分組去重 select i...

oracle建立使用者語句,用oracle裡的sql語言建立使用者

建立使用者 create user 使用者名稱 identified by 密碼,當然建立完使用者後,你要給最基本的connect和resource角色,否則無法登入的。查詢許可權 grant select on 該表使用者名稱.gecs law to 新加使用者名稱 建立使用者 create us...