Olá,

Em 6 de julho de 2010 10:55, TI <[email protected]> escreveu:

>  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.
>

Você realmente precisa fazer este procedimento usando cursor?

Eu propuria a seguinte solução:

CREATE OR REPLACE FUNCTION f_funcionario_afastado(INTEGER)

RETURNS boolean AS $$

BEGIN

IF EXISTS (SELECT datagozoini,datagozofim

    FROM historico_ferias

    WHERE codfuncionario=$1

    AND current_date BETWEEN datagozoini AND datagozofim

    ORDER BY 2) THEN

    RETURN TRUE;

END IF;

RETURN FALSE;

END;

$$ LANGUAGE PLPGSQL;


>   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
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>
>

[]s
-- 
JotaComm
http://jotacomm.wordpress.com
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a