oracle儲存過程學習筆記 一

2021-08-31 12:02:45 字數 1686 閱讀 3435

1. 基本結構

create or replace procedure 儲存過程名字

(引數1 in number,

) is

變數1 integer :=0;

變數2 date;

begin

end 儲存過程名字

2.select into statement

將select查詢的結果存入到變數中,可以同時將多個列儲存多個變數中,必須有一條

記錄,否則丟擲異常(如果沒有記錄丟擲no_data_found)例子:

begin

select col1,col2 into 變數1,變數2 from typestruct where ***;

exception

when no_data_found then

***x;

end;

3.if 判斷

if v_test=1 then

begin

do something

end;

end if;

4.while 迴圈

while v_test=1 loop

begin

***x

end;

end loop;

5.變數賦值

v_test := 123;

6.用for in 使用cursor

...is

cursor cur is select * from ***;

begin

for cur_result in cur loop

begin

v_sum :=cur_result.列名1+cur_result.列名2

end;

end loop;

end;

[b]create or replace procedure[/b] test

(id in varchar2

) [b]is[/b]

deptno varchar2(10);

[b]begin[/b]

select dno into deptno from emp where empno=id;

dbms_output.put_line(deptno);

[b]exception[/b]

when others then

dbms_output.put_line(『no data found』);

end;

[b]create or replace procedure[/b] update_professor

(v_prof_name professors.prof_name%type,

v_salary professors.salary%type :=null,

v_tenure professors.tenure%type :=null

)[b]is

begin[/b]

ifv_salary is null and v_tenure is null

then

return;

end if;

update professors set salary=nvl(v_salary,salary),tenure=nvl(v_tenure,tenure)

where prof_name=v_prof_name;

end;

Oracle儲存過程學習筆記 一

用了兩年 oracle 還沒寫過儲存過程,真是十分慚愧,從今天開始學習 oracle 儲存過程,完全零起點,爭取每日一篇學習筆記,可能開始認識的不全面甚至有錯誤,但堅持下來一定會有收穫。1.建立乙個儲存過程 create or replace procedure firstpro isbegin d...

oracle學習筆記 儲存過程

一 概述 oracle儲存過程開發的要點是 使用notepad文字編輯器,用oraclepl sql程式語言寫乙個儲存過程 在oracle資料庫中建立乙個儲存過程 在oracle資料庫中使用sql plus工具執行儲存過程 在oracle資料庫中修改儲存過程 通過編譯錯誤除錯儲存過程 刪除儲存過程 ...

oracle儲存過程學習筆記

建乙個不帶任何引數儲存過程 輸出系統日期 create or replace procedure output date is begin dbms output.put line sysdate end output date 執行這個儲存過程 begin output date end 建一張表...