儲存過程(stored procedure)是在大型資料庫系統中,一組為了完成特定功能的 sql 語句集,經編譯後儲存在資料庫中,使用者通過指定儲存過程的名字並給出引數(如果該儲存過程帶有引數)來執行它。儲存過程是資料庫中的乙個重要物件,任何乙個設計良好的資料庫應用程式都應該用到儲存過程。
建立儲存過程語法
語法1
語法2create [or replace] procedure 過程名[(引數名 in/out 資料型別)]
as begin
plsql 子程式體;
end;
範例:建立乙個輸出 helloword 的儲存過程create [or replace] procedure 過程名[(引數名 in/out 資料型別)]
isbegin
plsql 子程式體;
end 過程名;
呼叫儲存過程,在 plsql 中呼叫儲存過程create or replace procedure helloworld is
begin
dbms_output.put_line('helloworld');
end helloworld;
範例 2:給指定的員工漲 100 工資,並列印出漲前和漲後的工資begin
-- call the procedure
helloworld;
end;
分析:我們需要使用帶有引數的儲存過程
呼叫create or replace procedure addsal1(eno in number) is
pemp myemp%rowtype;
begin
select * into pemp from myemp where empno = eno;
update myemp set sal = sal + 100 where empno = eno;
dbms_output.put_line('漲工資前' || pemp.sal || '漲工資後' ||
(pemp.sal + 100));
end addsal1;
begin
-- call the procedure
addsal1(eno => 7902);
commit;
end;
Oracle儲存過程學習
儲存過程是一組為了完成特定功能的 sql 語句塊,經編譯後儲存在資料庫中,使用者通過指定儲存過程的名字並給出引數 如果該儲存過程帶有引數 來執行它。1 儲存過程和函式以命名的資料庫物件形式儲存於資料庫當中。儲存在資料庫中的優點是很明顯的,因為 不儲存在本地,使用者可以在任何客戶機上登入到資料庫,並呼...
Oracle儲存過程學習
儲存過程建立語法 create or replace procedure 儲存過程名 param1 in type,param2 out type as 變數1 型別 值範圍 變數2 型別 值範圍 begin select count into 變數1 from 表a where列名 param1 ...
Oracle儲存過程學習
儲存過程建立語法 create or replace procedure 儲存過程名 param1 in type,param2 out type as 變數1 型別 值範圍 變數2 型別 值範圍 begin select count into 變數1 from 表a where列名 param1 ...