oracle if else语句使用介绍

所属分类: 数据库 / oracle 阅读数: 81
收藏 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固定执行计划之SQL PROFILE概要文件详解

概要文件,就是一份描述如何使用系统的资源(主要是CPU资源)的配置文件,这篇文章主要介绍了Oracle固定执行计划之SQL PROFILE概要文件 ,需要的朋友可以参考下
收藏 0 赞 0 分享

Oracle 12CR2查询转换教程之表扩展详解

Oracle 12cR2版本已经发布有一段时间,下面这篇文章主要给大家介绍了关于Oracle 12CR2查询转换教程之表扩展的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Oracle 12CR2查询转换教程之cursor-duration临时表详解

这篇文章主要给大家介绍了关于Oracle 12CR2查询转换教程之cursor-duration临时表的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Oracle 12CR2查询转换教程之临时表转换详解

这篇文章主要给大家介绍了关于Oracle 12CR2查询转换教程之临时表转换的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Oracle中字符串截取常用方法总结【推荐】

这篇文章主要介绍了Oracle中字符串截取常用方法总结,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
收藏 0 赞 0 分享

关于expdp任务异常的处理案例详析

这篇文章主要给大家介绍了关于expdp任务异常处理的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

oracle中的一些常用函数及示例

这篇文章主要给大家介绍了关于oracle中的一些常用函数及示例的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

oracle实现一对多数据分页查询筛选示例代码

这篇文章主要给大家介绍了关于oracle实现一对多数据分页查询筛选的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
收藏 0 赞 0 分享

Oracle数据库新装之后出现的监听程序无法正常启动和运行(Oracle-12514)问题

这篇文章主要介绍了Oracle数据库新装之后出现的监听程序无法正常启动和运行(Oracle-12514)问题,需要的朋友可以参考下
收藏 0 赞 0 分享

Oracle中定义以及使用同义词的方法

这篇文章主要给大家介绍了关于Oracle中定义以及使用同义词的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多