oracle if else语句使用先容_硬盘数据恢复免费版

日期:2014-06-07 / 人气: / 来源:网络

接收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;

ORACLE PL/SQL 触发器编程篇介绍

ORACLE PL/SQL 触发器能够完成由数据库的完整性约束难以完成的复杂业务规则的约束;监视数据库的各种操作以及实现审计功能

ORACLE,PL/SQL,触发器

作者:管理员




现在致电4006-2991-90 OR 查看更多联系方式 →

Go To Top 回顶部