miércoles, 25 de enero de 2012

Obtener número de lote


-- Function: fnt_left(character varying, integer)

-- DROP FUNCTION fnt_left(character varying, integer);

CREATE OR REPLACE FUNCTION fnt_left(character varying, integer)
  RETURNS character varying AS
$BODY$
begin

    return substring($1, 1, $2);

end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION fnt_left(character varying, integer)
  OWNER TO adempiere;

 -- Function: fnt_right(character varying, integer)

-- DROP FUNCTION fnt_right(character varying, integer);

CREATE OR REPLACE FUNCTION fnt_right(character varying, integer)
  RETURNS character varying AS
$BODY$
begin

    return substring($1, length($1) - $2 + 1, length($1));

end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION fnt_right(character varying, integer)
  OWNER TO adempiere;

-- Function: get_lote(character varying)

-- DROP FUNCTION get_lote(character varying);

CREATE OR REPLACE FUNCTION get_lote(character varying)
  RETURNS character varying AS
$BODY$
declare
    lote character varying;
begin
    lote = fnt_left($1, length($1) - 1);

    return fnt_right(lote, length(lote) - position('«' in lote));
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION get_lote(character varying)
  OWNER TO adempiere;


No hay comentarios:

Publicar un comentario