oracle if else語句使用介紹
更新時(shí)間:2012年11月15日 11:47:52 作者:
Oracle if else 語句的寫法及應(yīng)用介紹,詳細(xì)可參考本文
接收contract_no和item_no值,在inventory表中查找,如果產(chǎn)品:
已發(fā)貨,在arrival_date中賦值為今天后的7天
已訂貨,在arrival_date中賦值為今天后的一個月
既無訂貨又無發(fā)貨,則在arrival_date中賦值為今天后的兩個月,
并在order表中增加一條新的訂單記錄。
product_status的列值為'shipped'和'ordered'
inventory:
product_idnumber(6)
product_descriptionchar(30)
product_statuschar(20)
std_shipping_qtynumber(3)
contract_item:
product_id number(6)
contract_nonumber(12)
item_nonumber(6)
arrival_datedate
order:
order_idnumber(6)
product_idnumber(6)
qtynumber(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
updatecontract_item
setarrival_date=add_months(sysdate,1)//加一個月
whereitem_no=&&itemnoandcontract_no=&&contractno;
else
updatecontract_item
setarrival_date=add_months(sysdate,2)
whereitem_no=&&itemnoandcontract_no=&&contractno;
insertintoorders
values(100,i_product_id,i_std_shipping_qty);
end if;
end if;
commit;
end;
已發(fā)貨,在arrival_date中賦值為今天后的7天
已訂貨,在arrival_date中賦值為今天后的一個月
既無訂貨又無發(fā)貨,則在arrival_date中賦值為今天后的兩個月,
并在order表中增加一條新的訂單記錄。
product_status的列值為'shipped'和'ordered'
inventory:
product_idnumber(6)
product_descriptionchar(30)
product_statuschar(20)
std_shipping_qtynumber(3)
contract_item:
product_id number(6)
contract_nonumber(12)
item_nonumber(6)
arrival_datedate
order:
order_idnumber(6)
product_idnumber(6)
qtynumber(3)
代碼:
復(fù)制代碼 代碼如下:
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
updatecontract_item
setarrival_date=add_months(sysdate,1)//加一個月
whereitem_no=&&itemnoandcontract_no=&&contractno;
else
updatecontract_item
setarrival_date=add_months(sysdate,2)
whereitem_no=&&itemnoandcontract_no=&&contractno;
insertintoorders
values(100,i_product_id,i_std_shipping_qty);
end if;
end if;
commit;
end;
相關(guān)文章
Oracle查詢中OVER (PARTITION BY ..)用法
這篇文章主要介紹了Oracle查詢中OVER (PARTITION BY ..)用法,內(nèi)容和代碼大家參考一下。2017-11-11查找oracle數(shù)據(jù)庫表中是否存在系統(tǒng)關(guān)鍵字的方法
遇到列說明無效的報(bào)錯情況,這是由于數(shù)據(jù)庫列名起的不好引起的,名字用到了數(shù)據(jù)庫的關(guān)鍵字2014-07-07Oracle數(shù)據(jù)泵EXPDP/IMPDP導(dǎo)出導(dǎo)入功能詳細(xì)深入解析
這篇文章主要給大家介紹了關(guān)于Oracle數(shù)據(jù)泵EXPDP/IMPDP導(dǎo)出導(dǎo)入功能的相關(guān)資料,數(shù)據(jù)泵導(dǎo)出/導(dǎo)入屬于邏輯備份,熱備份與冷備份都屬于物理備份,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12WMware redhat 5 oracle 11g 安裝方法
本文將詳細(xì)介紹WMware中redhat 5 安裝oracle 11g方法,需要的朋友可以參考下2012-12-12Oracle通過時(shí)間(分鐘)計(jì)算有幾天幾小時(shí)幾分鐘的方法
這篇文章主要介紹了Oracle通過時(shí)間(分鐘)計(jì)算有幾天幾小時(shí)幾分鐘的方法,涉及Oracle時(shí)間操作的技巧,需要的朋友可以參考下2015-03-03