oracle if else语句使用介绍

所属分类: 数据库 / oracle 阅读数: 92
收藏 0 赞 0 分享
接收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;
更多精彩内容其他人还在看

Oracle轻松取得建表和索引的DDL语句

Oracle轻松取得建表和索引的DDL语句
收藏 0 赞 0 分享

重新编译PLSQL中的无效对象或者指定的对象 的方法

重新编译PLSQL中的无效对象或者指定的对象 的方法
收藏 0 赞 0 分享

在OracleE数据库的字段上建立索引的方法

在OracleE数据库的字段上建立索引的方法
收藏 0 赞 0 分享

oracle下加密存储过程的方法

oracle下加密存储过程的方法
收藏 0 赞 0 分享

浅谈LogMiner的使用方法

浅谈LogMiner的使用方法
收藏 0 赞 0 分享

oracle 下WITH CHECK OPTION用法

oracle 下WITH CHECK OPTION用法
收藏 0 赞 0 分享

在Oracle中向视图中插入数据的方法

在Oracle中向视图中插入数据的方法
收藏 0 赞 0 分享

DBA_2PC_PENDING 介绍

DBA_2PC_PENDING 介绍
收藏 0 赞 0 分享

在Oracle PL/SQL中游标声明中表名动态变化的方法

在Oracle PL/SQL中游标声明中表名动态变化的方法
收藏 0 赞 0 分享

DB2和 Oracle的并发控制(锁)的比较

DB2和 Oracle的并发控制(锁)的比较
收藏 0 赞 0 分享
查看更多