第三十七講
if then
if else then?
if else then elsif elsif
create or replace procedure pro1(v_in_ename varchar2) is
--定義工資變量
v_sal emp.sal%type;
begin
select sal into v_sal from emp where ename=發(fā)——沁+;
if v_sal<2000 then
update emp set sal=sal*1.1 where ename=v+in+ename;
end if;
end;
第二個(gè)例子 if then else
create or replace procedure pro2(v_in_ename varchar) is
v_com emp.com%type;
begin
select comm into v_comm from emp where ename=v_in_ename;
if v_comm<>0 then
update emp set comm=comm+100 where ename=v_in_ename;
else?
update emp set comm=200 where ename=v_in_ename;
end if;
end;
特別說(shuō)明一下,字符串比較是一個(gè)等號(hào)
2.循環(huán)語(yǔ)句loop ?....end loop先執(zhí)行后退出
loop
..
exit when 條件表示式
end loop;
說(shuō)明 這里的條件表達(dá)式如果為true,則繼續(xù)執(zhí)行
create table users(
id number primary key,
name varchar2(42)
)
create or replace procedure pro1(v_in_name varchar,n number) is
--定義變量
v_empno number:=1;
begin
--exit when n<=0;
loop
--執(zhí)行添加任務(wù)
insert into users values(v_empno,v_in_name);
exit when v_empno=n;
--v_empno自己增加一下
v_empno:=v_empno+1;
end loop;
end;
[跟著hsp步步學(xué)習(xí)系統(tǒng)]oracle培訓(xùn)學(xué)習(xí)集錦全360度掃描(7) if-else及l(fā)oop end loop的使用
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
