CREATE OR ALTER function FN_LPAD (
    VALOR varchar(1000),
    TAMANHO integer,
    CARACTERE varchar(1000) = ' ')
returns varchar(1000)
AS
declare variable ZEROS varchar(1000);
declare variable RET varchar(1000);
begin
    RET = '';
            
    IF( CHAR_LENGTH(COALESCE(VALOR,'')) > 0 ) THEN
    BEGIN
      
        IF(CHAR_LENGTH(VALOR) >= TAMANHO) THEN
        BEGIN
            RET = VALOR;
        END
        ELSE
        BEGIN
            RET = LPAD(VALOR,TAMANHO,CARACTERE);
        END
    END

    RETURN RET;

end;