postgresql创建function使两个表互动

WBOY
发布: 2016-06-07 14:59:01
原创
1092 人浏览过

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 stockcurr

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');
 

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!