程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> 關於Oracle數據庫 >> oracle if else語句使用介紹

oracle if else語句使用介紹

編輯:關於Oracle數據庫
接收contract_no和item_no值,在inventory表中查找,如果產品:
已發貨,在arrival_date中賦值為今天後的7天
已訂貨,在arrival_date中賦值為今天後的一個月
既無訂貨又無發貨,則在arrival_date中賦值為今天後的兩個月,
並在order表中增加一條新的訂單記錄。

product_status的列值為'shipped'和'ordered'
inventory:
product_idnumber(6)
product_descriptionchar(30)
product_statuschar(20)
std_shipping_qtynumber(3)
contract_item:
product_id number(6)
contract_nonumber(12)
item_nonumber(6)
arrival_datedate
order:
order_idnumber(6)
product_idnumber(6)
qtynumber(3)

代碼:
代碼如下:

declare
i_product_id inventory.product_id%type;
i_product_description inventory.product_description%type;
i_product_status inventory.product_status%type;
i_std_shipping_qty inventory.std_shipping_qty%type;
begin
//sql語句,將查詢出來的值放到定義的變量中
select product_id, product_description, product_status, std_shipping_qty
into i_product_id, i_product_description, i_product_status, i_std_shipping_qty
from inventory where product_id=(
select product_id from contract_item where contract_no=&&contract_no and item_no=&&item_no
);
if i_product_status='shipped' then
update contract_item set arrival_date=sysdate+7 contract_no=&&contract_no and item_no=&&item_no;
//這裡的elseif 是連著寫的
elseif i_product_status='ordered'then
updatecontract_item
setarrival_date=add_months(sysdate,1)//加一個月
whereitem_no=&&itemnoandcontract_no=&&contractno;
else
updatecontract_item
setarrival_date=add_months(sysdate,2)
whereitem_no=&&itemnoandcontract_no=&&contractno;
insertintoorders
values(100,i_product_id,i_std_shipping_qty);
end if;
end if;
commit;
end;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved