1.基本結構
create or replace procedure 存儲過程名字
(
參數1 in number,
參數2 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 xxx;
exception
when no_data_found then
xxxx;
end;
...
3.if 判斷
if v_test=1 then
begin
do something
end;
end if;
4.while 循環
while v_test=1 loop
begin
xxxx
end;
end loop;
5.變量賦值
v_test := 123;
6.用for in 使用cursor
...
is
cursor cur is select * from xxx;
begin
for cur_result in cur loop
begin
v_sum :=cur_result.列名1+cur_result.列名2
end;
end loop;
end;
7.帶參數的cursor
cursor c_user(c_id number) is select name from user where typeid=c_id;
open c_user(變量值);
loop
fetch c_user into v_name;
exit fetch c_user%notfound;
do something
end loop;
close c_user;
8.用pl/sql developer debug
連接數據庫后建立一個test window
在窗口輸入調用sp的代碼,f9開始debug,ctrl+n單步調試
新聞熱點
疑難解答