CREATE OR REPLACE FUNCTION delete_r_juchu()
  RETURNS trigger AS $$
begin
insert into dat_rd_juchu (
rirekino
,sakujofg
,juchuno
,juchubi
,tokuisakicd
,tokuisakiatena
,projectcd
,biko
,shanaibiko
,tantoshaid
,bushocd
,tankarankcd
,shoninnichiji
,shoninshaid
,maeukenyukinbi
,maeukekingaku
,kessaikb
,denpyosakuseikb
,sakuseiuserid
,sakuseinichiji
,koshinuserid
,koshinnichiji
  ) values (
nextval('sqns_juchurirekino')
,true
,old.juchuno
,old.juchubi
,old.tokuisakicd
,old.tokuisakiatena
,old.projectcd
,old.biko
,old.shanaibiko
,old.tantoshaid
,old.bushocd
,old.tankarankcd
,old.shoninnichiji
,old.shoninshaid
,old.maeukenyukinbi
,old.maeukekingaku
,old.kessaikb
,old.denpyosakuseikb
,old.sakuseiuserid
,old.sakuseinichiji
,old.koshinuserid
,old.koshinnichiji
  );
insert into dat_rm_juchu (
rirekino
,juchuno
,gyono
,oyameisaicd
,meisaicd
,meisaikb
,hinmokucd
,hinmokumei
,kikaku
,kataban
,lotno
,nisugatacd
,suryo
,tanicd
,teika
,tanka
,kazeikb
,shohizeiritsu
,kingaku
,noki
,biko
,shanaibiko
,shukkosokocd
,nyukosokocd
,haisosakino
,haisomemo
,juchujotai
,hatchujotai
,shukkajotai
,yoteihaisobi
,yoteinyukabi
,sakuseiuserid
,sakuseinichiji
,koshinuserid
,koshinnichiji
) select
currval('sqns_juchurirekino')
,mj.juchuno
,mj.gyono
,mj.oyameisaicd
,mj.meisaicd
,mj.meisaikb
,mj.hinmokucd
,mj.hinmokumei
,mj.kikaku
,mj.kataban
,mj.lotno
,mj.nisugatacd
,mj.suryo
,mj.tanicd
,mj.teika
,mj.tanka
,mj.kazeikb
,mj.shohizeiritsu
,mj.kingaku
,mj.noki
,mj.biko
,mj.shanaibiko
,mj.shukkosokocd
,mj.nyukosokocd
,mj.haisosakino
,mj.haisomemo
,mj.juchujotai
,mj.hatchujotai
,mj.shukkajotai
,mj.yoteihaisobi
,mj.yoteinyukabi
,mj.sakuseiuserid
,mj.sakuseinichiji
,mj.koshinuserid
,mj.koshinnichiji
from dat_m_juchu mj
where mj.juchuno = old.juchuno
;
return new;
end;
$$
LANGUAGE plpgsql;
