Olá pessoal,

Preciso da ajuda de vocês no seguinte :

a)      Criei uma function que me retorna se um determinado funcionário está
de férias  neste caso eu passo como parâmetro de entrada o código do
funcionário e retorno “Verdadeiro” ou “Falso” em suas situações. O
funcionamento está ok se usada isoladamente (select * from
fnc_funcionario_afastado(matricula))
b)      Quando usamos a function acima dentro de um select, como por exemplo
: select matricula, nome from funcionários where
(fnc_funcionario_afastado(matricula))=false o sistema retorna a seguinte
mensagem de erro : cursor "_registros" already in use.


Cenário : PostgreSQL 8.4.1, compiled by Visual C++ build 1400, 32-bit  -->
Windows XP

Função :

CREATE OR REPLACE FUNCTION "public"."fnc_funcionario_afastado" ("eCodFunc"
integer) RETURNS boolean AS
$body$
DECLARE
  -- ferias
  _registros cursor for select datagozoini,
                               datagozofim
                          from historico_ferias
                         where codfuncionario=$1
                         order by datagozofim;
  registros record;                               
BEGIN

-- abrindo o cursor do historico das ferias do funcionario;
open _registros;
loop 
  fetch _registros into registros;
  exit when not found;
  if (current_date >= registros.datagozoini) and (current_date <=
registros.datagozofim) then
    return true;
    close _registros;
    exit;
  end if;
end loop;  
close _registros;
return false;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;


Onde será que estou errando?

Obrigado e no aguardo,

Rubens José Rodrigues

_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a