return: text
lang: plpgsql
src: |
  DECLARE	
  	result TEXT;
  BEGIN
  	EXECUTE 'update pmsi.t_actes
  		SET
  			topographie_1_id=subq.topographie_1_id, topographie_1_code=subq.topographie_1_code, topographie_1_texte=subq.topographie_1_texte,
  			topographie_2_id=subq.topographie_2_id, topographie_2_code=subq.topographie_2_code, topographie_2_texte=subq.topographie_2_texte, 
  			action_id=subq.action_id, action_code=subq.action_code, action_texte=subq.action_texte, 
  			technique_id=subq.technique_id, technique_code=subq.technique_code, technique_texte=subq.technique_texte
  		from
  		(
  		select t_actes.oid as acte_id,
  			topographie_1.oid as topographie_1_id, topographie_1.code as topographie_1_code  , topographie_1.texte as  topographie_1_texte,
  			topographie_2.oid as topographie_2_id, topographie_2.code as topographie_2_code  , topographie_2.texte as  topographie_2_texte,
  			action.oid as action_id, action.code as action_code  , action.texte as   action_texte,
  			technique.oid as technique_id, technique.code as technique_code  , technique.texte as   technique_texte
  		from pmsi.t_actes
  		join base.t_structure_code_ccam as topographie_1 on substr(t_actes.code, 1, 1) = topographie_1.code and topographie_1.type = 1 
  		join base.t_structure_code_ccam as topographie_2 on substr(t_actes.code, 1, 2) = topographie_2.code and topographie_2.type = 2 
  		join base.t_structure_code_ccam as action on substr(t_actes.code, 3, 1) = action.code and action.type = 3 
  		join base.t_structure_code_ccam as technique on substr(t_actes.code, 4, 1) = technique.code and technique.type = 4
  		) as subq
  		where t_actes.oid = subq.acte_id';
  	RETURN 'OK';
  END;