热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

postgresql创建function使两个表互动

postgresql创建function使两个表互动createfunctionf_m_stockcurrent_post(charactervarying(32))RETURNSintegeras$$declarerecrecord;beginupdatestockcurrentsetunitsunits+(selecthandqtyfromshipmentinlinespinnerjoinstockcurr

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


推荐阅读
author-avatar
雷神鑫源义_341
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有