设为首页 加入收藏

TOP

postgresql创建function使两个表互动
2014-11-24 00:43:58 来源: 作者: 【 】 浏览:13
Tags:postgresql 创建 function 两个 互动
postgresql创建function使两个表互动
create function f_m_stockcurrent_post(character varying(32))
RETURNS integer
as
$$
declare
rec record;
begin
update stockcurrent set units=units+(select handqty from shipmentinline sp inner join stockcurrent st on st.product=sp.product where sp.documentno=$1);
for rec in (select sp.location,sp.handqty,sp.product from shipmentinline sp where sp.documentno=sp_documentno and not exists(select handqty from shipmentinline sp inner join stockcurrent st on st.product=sp.product where sp.documentno=$1)) loop
insert into stockcurrent(location,product,attributesetinstance_id,units)values(rec.location,rec.product,null,rec.handqty);
end loop;
end;
$$
language 'plpgsql' VOLATILE;
数据库中检验函数是否生效
select f_m_stockcurrent_post('123');
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇postgresql状态查询 下一篇MongoDB千万级数据的分析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: