oracle中plsql块的结构,oracle plsql的结构
變量聲明部分(沒有變量可以不寫declare)
begin
執行部分
exception
異常處理部分
end
*:declare 和 exception部分是可選的
(1)PL/sql中變量的定義
格式1
變量名 變量類型 【約束】 default 默認值
格式2
變量名 變量類型 【約束】【:=初始值】
(2)一個簡單的PL/sql塊
declare
i number :=99;
begin
i:=i+10;
dbms_output.put_line(i);
end;
/
PL/sql塊中流程控制
一。if語句
if 條件 then
。。。
end if;
if 條件 then
。。。
else
。。。
end if;
declare
zhangsan numberdefault 24;
lisi number :=28;
beginif zhangsan
dbms_output.put_line(‘zhangsan younger than lisi‘);
endif;
end;/
if 條件 then
...
elsif 條件 then
...
end if;
declare
age numberdefault 90;
height number :=175;
genderchar(2):=‘男‘;
beginif gender=‘男‘then
dbms_output.put_line(‘你可以和女性結婚‘);
endif;if height>170then
dbms_output.put_line(‘可以打籃球‘);elsedbms_output.put_line(‘可以踢足球‘);
endif;if age<20then
dbms_output.put_line(‘年輕小伙‘);
elsif age<= 50then
dbms_output.put_line(‘年輕有為‘);
elsif age<=70then
dbms_output.put_line(‘安享天倫‘);elsedbms_output.put_line(‘佩服佩服‘);
endif;
end;
二。While循環語句:
while 條件 loop
循環體
end loop;
declare
age numberdefault 1;
beginwhile age <=10loop
dbms_output.put_line(‘age is‘||age);
age:=age+1;
end loop;
end;
三。For循環結構:
for 循環變量 in [reverse] 起始值..終止值 loop
循環體
end loop;
beginfor i in 1..9loop
dbms_output.put_line(i);
end loop;for i in reverse 1..9loop
dbms_output.put_line(i);
end loop;
end;
四。Loop循環語句:
loop
循環體
exit when 條件;
end loop;
//計算1-100的和
declare
i number:=0;
total number:=0;
begin
loop
i:=i+1;
total:=total+i;if i=100then
exit;
endif;
end loop;
dbms_output.put_line(‘總和‘||total);
end;
跳出loop的方法
declare
i number :=0;
total number :=0;
begin
loop
i := i+1;
total := total +i;
exit when i>=100;
end loop;
dbms_output.put_line(‘總和‘||total);
end;
存儲過程創建語法:
create or replace procedure 名稱[(參數)]
authid current_user|definer --以定義者還是調用者的身份運行is[不要加declare]
變量聲明部分
begin
主體部分
exception
異常部分
end;
create procedure a1isbegin
dbms_output.put_line(‘hello‘);
end;/
調用
Call a1();
create procedure a2(width int,height int)isareaint:=0;
begin
area:=width*height;
dbms_output.put_line(‘area is‘||area);
end;/
調用
Call a2(20,3);
oracle plsql的結構
標簽:efi???exit???rev???int???條件???變量???部分???number???user
本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴 本文系統來源:https://www.cnblogs.com/111wdh/p/13634608.html
總結
以上是生活随笔為你收集整理的oracle中plsql块的结构,oracle plsql的结构的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信用卡分期提前还款能恢复额度吗
- 下一篇: 无房贷车贷,在银行存200万,存款利率4