create procedure PRO_update_Goods_group_stock is
v_min_stock NUMBER(10, 2);
v_gg_stock NUMBER(10, 2);
v_goods_no number;
v_sum_cost NUMBER(10, 2);
begin
for g_goods_no in (select ggi.goods_no
from goods_group_item ggi
where ggi.is_delete = 'N'
GROUP by ggi.goods_no) loop
select count(*)
into v_goods_no
from goods_no_stock gn
where gn.goods_no = g_goods_no.goods_no;
if v_goods_no > 0 then
continue;
end if; --查询组合子商品的库存再除以绑定的数量 取最小值 gg主商品 g子商品
select min(TRUNC(g.available_stock /
decode(gg1.group_goods_amount,
0,
1,
gg1.group_goods_amount),
0))
into v_min_stock
from goods_group_item gg1, goods g, goods gg
where gg1.goods_no = g_goods_no.goods_no
and gg1.is_delete = 'N'
and gg.goods_id = gg1.goods_id
and gg.is_delete = 'N'
and g.goods_id = gg1.GROUP_GOODS_ID; --计算成本价格 gg主商品 g子商品
select trunc(sum(g.cost_price * gg1.group_goods_amount), 2)
into v_sum_cost
from goods_group_item gg1, goods g, goods gg
where gg1.goods_no = g_goods_no.goods_no
and gg1.is_delete = 'N'
and gg.goods_id = gg1.goods_id
and gg.is_delete = 'N'
and g.goods_id = gg1.GROUP_GOODS_ID; update goods
set available_stock = v_min_stock, COST_PRICE = v_sum_cost
where goods_no = g_goods_no.goods_no
and is_delete = 'N';
commit;
end loop; --下架问题组合码
insert into sys_user_message
(MESSAGE_ID,
PRODUCT_CODE,
TARGET_MODUL_ID,
MESSAGE_BODY,
MESSAGE_STAGE,
IS_DELETE)
select sys_user_message_seq.nextval,
p.product_code,
254,
'商品:'||p.product_code||' 没有维护组合码',
'',
'N'
from product p
where not exists (select 1
from goods_group_item ggi
where ggi.goods_no = p.product_code)
and p.is_delete = 'N'
and p.is_onsale = 'Y'
and p.product_code like 'A%'; update product p set p.is_onsale = 'N'
where not exists (select 1
from goods_group_item ggi
where ggi.goods_no = p.product_code)
and p.is_delete = 'N'
and p.is_onsale = 'Y'
and p.product_code like 'A%'; commit;
end; select * from goods_no_stock gn
where gn.goods_no in (select ggi.goods_no
from goods_group_item ggi
where ggi.is_delete = 'N'
GROUP by ggi.goods_no); select * from goods g where g.GOODS_NO='02-00056'; select * from goods g where g.GOODS_NO=''; select * from goods g where g.goods_no=''; select gn.goods_no from goods_no_stock gn;
goods_no_stock:库存同步黑名单表,在这张表中的数据,都不会进行相关的更新操作
 

oracle 存储函数,更新库存的更多相关文章

  1. Oracle存储函数,存储过程

    一.Oracle存储函数:存储的PL/SQL语法块,完成特定的功能.1.语法: 函数关键字: function (1)创建函数 CREATE [OR REPLACE] FUNCTION <fun ...

  2. ORACLE 存储函数

    前奏: 必要的概念: ORACLE 提供能够把 PL/SQL 程序存储在数据库中.并能够在不论什么地方来运行它.这样就叫存储过 程或函数. 过程和函数统称为 PL/SQL 子程序.他们是被命名的 PL ...

  3. Oracle存储函数jdbc调用

    package com.jckb.procedure; import java.sql.CallableStatement; import java.sql.Connection; import ja ...

  4. oracle存储函数实例

    CREATE OR REPLACE PROCEDURE "PROC_INS_DAY_DOCTOR_LL"(v_date in VARCHAR) is --PROC_INS_DAY_ ...

  5. Oracle的基本语法,存储函数及触发器

    1.PL/SQL    PL/SQL是Oracle对 ql语言的过程化扩展,指在 SQL 命令语言中增加了过程处理语句,使SQL语言具有过程处理能力.把 SQL 语言的数据操纵能  力与过程语言的数据 ...

  6. Oracle03——游标、异常、存储过程、存储函数、触发器和Java代码访问Oracle对象

    作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7476717.html 1.游标(光标)Cursor 在写java程序中有集合的概念,那么 ...

  7. oracle存储过程和存储函数&触发器

    oracle存储过程和存储函数 指存储在数据库中供所有用户程序调用的子程序叫存储过程,存储函数 存储过程和存储函数的相同点:完成特定功能的程序 存储过程和存储函数的区别:是否用return语句返回值 ...

  8. oracle之存储过程和存储函数的使用和区别

    #存储过程:封装在服务器上一段sql片段,已经编译好了的代码. 1.客户端调存储过程,执行效率就会非常高效. 语法: create [or replace] procedure 存储过程名称 (参数名 ...

  9. Oracle数据库游标,序列,存储过程,存储函数,触发器

    游标的概念:     游标是SQL的一个内存工作区,由系统或用户以变量的形式定义.游标的作用就是用于临时存储从数据库中提取的数据块.在某些情况下,需要把数据从存放在磁盘的表中调到计算机内存中进行处理, ...

随机推荐

  1. poj1679The Unique MST(次小生成树模板)

    次小生成树模板,别忘了判定不存在最小生成树的情况 #include <iostream> #include <cstdio> #include <cstring> ...

  2. Incorrect integer value: '' for column 'id' at row 1 错误解决办法

    最近一个项目,在本地php环境里一切正常,ftp上传到虚拟空间后,当执行更新操作(我的目的是为了设置id为空)set id=‘’时提示: Incorrect integer value: '' for ...

  3. janusgraph-图数据库的学习(2)

    janusgraph的简单使用 当安装好以后简单的使用janusgraph 1.进入janusgraph的shell命令界面 [root@had214 janusgraph-0.3.1-hadoop2 ...

  4. Effective C++ 读后感笔记

    1.赋值不一定是初始化.例如 AClassName::AClassName(const std::string &name, const std::string &address, c ...

  5. yii2 oracle 原生sql分页

    $sql_list = "SELECT ID, FID, INSID, FLIGHTNO, DEPNAME, ARRNAME, to_char(DEPDATE,'yyyy-MM-dd HH2 ...

  6. 【批处理】choice命令,call 命令,start 命令,rem

    [1]choice命令简介 使用此命令可以提示用户输入一个选择项,根据用户输入的选择项再决定执行具体的过程. 使用时应该加/c:参数,c: 后应写提示可输入的字符或数字,之间无空格.冒号是可选项. 使 ...

  7. sublime text 3插件改造之AutoFileName去掉.vue文件中img标签后面的width和height,完全去掉!!

    在.vue文件中img标签使用autofilename提示引入文件时,会在文件后面插入宽度高度,如下图: 文件后面会自动插入height和width,其实这两玩意儿在大多数时候并没卵用,然后就开始了百 ...

  8. Brexit Gym - 101490C

    题目链接:Brexit vector的使用(vector存边),巧用queue,相当于Bfs /* */ # include <iostream> # include <cstdio ...

  9. 第12组 Beta冲刺(1/5)

    Header 队名:To Be Done 组长博客 作业博客 团队项目进行情况 燃尽图(组内共享) 展示Git当日代码/文档签入记录(组内共享) 注: 由于GitHub的免费范围内对多人开发存在较多限 ...

  10. CF830E Perpetual Motion Machine

    题面 题解 神仙构造题. 分五种情况考虑: 如果存在一个环,那么令环上的点权值为\(1\),其余点权值为\(0\). 如果存在一个度数大于\(3\)的点,令这个点的权值为\(2\),和它相邻的点权值为 ...