oracle 儲存過程例子

2021-09-01 19:28:14 字數 1678 閱讀 5365

oracle

儲存過程學習過程 建立乙個最簡單的儲存過程 create or replace procedure test_xg_p1 is begin dbms_output.put_line('hello world! this is the first procedure'); end; 建立乙個帶輸入輸出引數的儲存過程:把輸入的資料傳給輸出引數 create or replace procedure test_xg_p2(a in number,x out number) is begin x:=a; end test_xg_p2; 建立乙個邏輯判斷的儲存過程,幷包含輸入輸出引數:近似分數的登記判斷 create or replace procedure test_xg_p3(a in number,x out varchar2) is begin if a>=90 then begin x := 'a'; end; end if; if a<90 then begin x:='b'; end; end if; if a<80 then begin x:='c'; end; end if; if a<70 then begin x:='d'; end; end if; if a<60 then begin x:='e'; end; end if; end test_xg_p3; 建立乙個帶迴圈邏輯的儲存過程:近似累加函式

create or replace procedure test_xg_p4(a in number,x out varchar2) is tempresult number(16); begin tempresult :=0; for tempa in 0..a loop begin tempresult := tempresult + tempa; end; end loop; x:=tempresult; end test_xg_p4; 建立乙個能從資料庫中特定表中返回資料的儲存過程: create or replace procedure test_xg_p5(x out varchar2) is tempresult varchar2(1024); begin tempresult := 'start->'; select hotelid||hotelname into tempresult from hotel where hotelid =10041764; x:=tempresult; end test_xg_p5; 建立乙個能使用游標的帶迴圈的儲存過程: create or replace procedure test_xg_p6(x out varchar2) is tempresult varchar2(10240); cursor cursor1 is select * from hotel where hotelname like '浙江%'; begin tempresult := 'start->'; for cursor_result in cursor1 loop begin tempresult :=tempresult||cursor_result.hotelid||cursor_result.hotelname; end; end loop; x:=tempresult; end test_xg_p6

oracle儲存過程簡單例子

先建立一張表 create table mytest name varchar2 30 passwd varchar2 30 建立儲存過程 create or replace procedure sp pro1 is begin insert into mytest values jack 123 ...

Oracle 建立儲存過程例子

建立儲存過程 create or replace procedure xx p 引數in表示輸入引數,out表示輸入引數,型別可以使用任意oracle中的合法型別。is ym in char as 定義變數 vs msg varchar2 4000 錯誤資訊變數 vs ym beg char 6 起...

儲存過程例子

alter proc futurema updageorderdatasdistinguishresult asdeclare connectionstring nvarchar 256 declare server nvarchar 256 declare uid nvarchar 256 dec...