当前位置:主页 > 数据库 > Oracle >

oracle if else语句使用介绍

时间:2021-07-05 09:21:07 | 栏目:Oracle | 点击:

接收contract_no和item_no值,在inventory表中查找,如果产品:?W
已发货,在arrival_date中赋值为今天后的7天?W
已订货,在arrival_date中赋值为今天后的一个月?W
既无订货又无发货,则在arrival_date中赋值为今天后的两个月,?W
并在order表中增加一条新的订单记录。?W

product_status的列值为'shipped'和'ordered'?W
inventory:?W
product_id?Wnumber(6)?W
product_description?Wchar(30)?W
product_status?Wchar(20)?W
std_shipping_qty?Wnumber(3)?W
contract_item:?W
product_id number(6)?W
contract_no?Wnumber(12)?W
item_no?Wnumber(6)?W
arrival_date?Wdate?W
order:?W
order_id?Wnumber(6)?W
product_id?Wnumber(6)?W
qty?Wnumber(3)?W

代码:
复制代码 代码如下:

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'?Wthen?W
update?Wcontract_item?W
set?Warrival_date=add_months(sysdate,1)?W//加一个月
where?Witem_no=&&itemno?Wand?Wcontract_no=&&contractno;?W
else
update?Wcontract_item?W
set?Warrival_date=add_months(sysdate,2)?W
where?Witem_no=&&itemno?Wand?Wcontract_no=&&contractno;?W
insert?Winto?Worders?W
values(100,i_product_id,i_std_shipping_qty);?W
end if;
end if;
commit;
end;

您可能感兴趣的文章:

相关文章