码迷,mamicode.com
首页 > 数据库 > 详细

plsql function

时间:2015-11-09 10:49:55      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:



do language plpgsql
$$
declare
 dz driver_zone%rowtype;
 leadtime integer;
begin
    leadtime = 0;
    for dz in select * from driver_zone
    loop
        leadtime = leadtime + 1;
        update driver_zone set lead_time = leadtime where id = dz.id;
    end loop;
end
$$
;

===============================================

 

CREATE OR REPLACE FUNCTION deliver_orders()
  RETURNS integer AS
$BODY$
DECLARE
  cnt integer := 0;
  rev consolidated_order_revenue%rowtype;
  firstOrder _order%rowtype;
  sellingCount integer := 0;
  buyingCount integer := 0;
BEGIN
    FOR rev IN select distinct * from consolidated_order_revenue where id in (select buying_consolidation_id from _order where created_on > ‘2013-11-01‘)
    LOOP
SELECT * INTO firstOrder FROM _order WHERE buying_consolidation_id = rev.id;

SELECT COUNT(*) INTO buyingCount FROM _order WHERE buying_consolidation_id = firstOrder.buying_consolidation_id;
SELECT COUNT(*) INTO sellingCount FROM _order WHERE selling_consolidation_id = firstOrder.selling_consolidation_id;

IF sellingCount > 0 AND buyingCount <> sellingCount THEN
RAISE NOTICE ‘Fixing revenue: % (buying %, selling %)‘, rev.id, buyingCount, sellingCount;
END IF;

    END LOOP;
    
    RAISE NOTICE ‘Delivered % orders‘, cnt;
    RETURN cnt;
END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION deliver_orders()
  OWNER TO jetty;

 

plsql function

标签:

原文地址:http://www.cnblogs.com/Uncho/p/4949002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!