日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle中存储过程 =,oracle中的存储过程使用

發(fā)布時間:2025/3/11 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle中存储过程 =,oracle中的存储过程使用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一 存儲過程的基本應(yīng)用

1 創(chuàng)建存儲過程(SQL窗口)

create or replace procedure update_staff

as

begin

update staff set name = 'xy';

commit;

end update_staff;

存儲過程適合做更新操作,特別是大量數(shù)據(jù)的更新

2 查看存儲過程在數(shù)據(jù)字典中的信息(SQL窗口)

select object_name,object_type,status from user_objects where lower(object_name) = 'update_staff'

3 查看存儲過程語句(SQL窗口)

select * from user_source where lower(name) = 'update_staff'

4 執(zhí)行存儲過程(Command窗口)

execute update_staff;

5 存儲過程的優(yōu)點

① 提高數(shù)據(jù)庫執(zhí)行效率。使用SQL接口更新數(shù)據(jù)庫,如果更新復(fù)雜而頻繁,則需要頻繁得連接數(shù)據(jù)庫。

② 提高安全性。存儲過程作為對象存儲在數(shù)據(jù)庫中,可以對其分配權(quán)限。

③ 可復(fù)用性。

二 帶輸入?yún)?shù)的存儲過程

1 創(chuàng)建存儲過程(SQL窗口)

create or replace procedure update_staff(in_age in number) as

begin

declare newage number;

begin

newage := in_age + 10;

update staff set age = newage;

commit;

end;

end update_staff;

2 執(zhí)行存儲過程(Command窗口)

execute update_staff(10);

3 默認值

只有in參數(shù)可以有默認值,比如

create or replace procedure update_staff(in_name in varchar2,in_age in number default 20)

調(diào)用時可只寫execute update_staff('xy');

三 帶輸出參數(shù)的存儲過程

1 創(chuàng)建存儲過程(SQL窗口)

create or replace procedure update_staff (in_age in number,out_age outnumber) as

begin

update staff set age = in_age;

select age into out_age from student where num = 1;

commit;

end update_staff;

存儲過程沒有顯示制定返回值,但輸出參數(shù)可以輸出

2 輸出存儲過程結(jié)果(Command窗口)

set serverout on;

declare age number;

begin

update_staff(20,age);

dbms.output.put_line(age);

end;

四 帶輸入輸出的存儲過程

其中最典型的應(yīng)用是交換兩個數(shù)的值

1 創(chuàng)建存儲過程(SQL窗口)

create or replace procedure swap (param1 in out number, param2 in out number) as

begin

declare param number;

begin

param:=param1;

param1:=param2;

param2:=param;

end;

end swap;

2 輸出存儲過程結(jié)果(Command窗口)

set serverout on;

declare p1 number:= 25;

p2 number:=35;

begin

swap(p1,p2);

dbms_output.put_line(p1);

end;

五 參數(shù)總結(jié)

①輸入?yún)?shù):有調(diào)用者傳遞給存儲過程,無論存儲過程如何調(diào)用該參數(shù),該參數(shù)的值都不能被改變,可以認為該參數(shù)的值是只讀的。

②輸出參數(shù):可以作為返回值來用??梢哉J為可寫。

③輸入輸出參數(shù):這中類型的參數(shù)和java方法中的參數(shù)最像,傳入方法,可讀可寫(final標識符除外)。

④參數(shù)順序總結(jié)如下:具有默認值的參數(shù)應(yīng)該位于參數(shù)列表的末尾,因為有時用戶需要省略該參數(shù)。沒有默認值的參數(shù)可以遵循"in -> out -> in out"。

總結(jié)

以上是生活随笔為你收集整理的oracle中存储过程 =,oracle中的存储过程使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。