create or replace procedure test is
v_count number(4);
cursor v_c is
select * from "t2voucherhandno";
begin
select count(*) into v_count from "t2voucherhandno";
if v_count>1 then
raise too_many_rows;
else
for my_v in v_c
loop
dbms_output.put_line(my_v.fno);
end loop;
end if;
end;
oracle 儲存過程的基本語法
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 ***;
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;
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單步除錯
ORACLE中用for in 使用cursor
cursor cur is select from for cur result in cur loop begin v sum cur result.列名1 cur result.列名2 end end loop end 中的cursor cur is得到的是什麼?用for in 能夠得到什麼?答...
Oracle儲存過程呼叫儲存過程
oracle儲存過程呼叫有返回結果集的儲存過程一般用光標的方式,宣告乙個游標,把結果集放到游標裡面,然後迴圈游標 declare newcs sys refcursor cs1 number cs2 number cstype table rowtype table列的個數和newcs返回的個數一樣...
ORACLE儲存過程
自定義函式開始 create or replace function fn wftemplateidget templatecategoryid number,organid number,templatemode number return number istemplateid number i...