您好,欢迎来到保捱科技网。
搜索
您的当前位置:首页postgresql创建function使两个表互动

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

Copyright © 2019- baoaiwan.cn 版权所有 赣ICP备2024042794号-3

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务