Maison > base de données > tutoriel mysql > le corps du texte

postgresql创建function使两个表互动

WBOY
Libérer: 2016-06-07 14:59:01
original
1062 Les gens l'ont consulté

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

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!