Re: [pgbr-geral] RES: Function com mais de um retorno

2009-11-20 Por tôpico Joao Cosme de Oliveira Junior

ou retorna tb set of records.João Cosme de Oliveira Júnior

Seja inteligente, use Software-livre!!!
LPI Certified
LPI000185554
Em 20/11/2009 às 10:30 horas, pgbr-geral@listas.postgresql.org.br escreveu:








Obrigado.

 





De: pgbr-geral-boun...@listas.postgresql.org.br
[mailto:pgbr-geral-boun...@listas.postgresql.org.br] Em nome de Wolak
Enviada em: sexta-feira, 20 de novembro de 2009 10:26
Para: Comunidade PostgreSQL Brasileira
Assunto: Re: [pgbr-geral] Function com mais de um retorno





 

Exemplo...
PS. Vc tambem pode utilizar o parametro com OUT em vez de TYPEs...

DROP TYPE IF EXISTS exemplo_retorno CASCADE;
CREATE TYPE exemplo_retorno AS (
    data  TIMESTAMP,
    valor NUMERIC(15,2),
    descricao VARCHAR);
    
CREATE OR REPLACE FUNCTION exemplo()
RETURNS SETOF exemplo_retorno AS
$$
DECLARE
   rRetorno exemplo_retorno;
BEGIN
    FOR i IN 1..10
    LOOP
        rRetorno.data = "">
        rRetorno.valor = RANDOM();
        rRetorno.descricao = 'LINHA = '||i;
        RETURN NEXT rRetorno;
    END LOOP;
    RETURN;
END;
$$
LANGUAGE plpgsql;

Chamada da PL:
SELECT * FROM exemplo();
OU 
SELECT exemplo();
OU 
SELECT (exemplo()).valor;

Wolak.


Saulo Morais Lara escreveu: 

É possível uma função retornar mais de um valor? Alguem tem
um exemplo? Obrigado.

 

Saulo
Morais Lara

Analista
de Sistemas

Ability
Informática Ltda

Rua
São Paulo, 106 - São José - Pará de Minas - MG

(37)
3232-1127 / (37) 9194-0234

sa...@abilityonline.com.br

www.abilityonline.com.br

 



__ Information from ESET NOD32 Antivirus, version of virus signature
database 4620 (20091118) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



 

 ___pgbr-geral mailing listpgbr-geral@listas.postgresql.org.brhttps://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral   __ Information from ESET NOD32 Antivirus, version of virus signature database 4620 (20091118) __ The message was checked by ESET NOD32 Antivirus. http://www.eset.com   



__ Information from ESET NOD32 Antivirus, version of virus signature
database 4624 (20091120) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com








"Esta mensagem do SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), empresa pública federal regida pelo disposto na Lei Federal nº 5.615, é enviada exclusivamente a seu destinatário e pode conter informações confidenciais, protegidas por sigilo profissional. Sua utilização desautorizada é ilegal e sujeita o infrator às penas da lei. Se você a recebeu indevidamente, queira, por gentileza, reenviá-la ao emitente, esclarecendo o equívoco."

"This message from SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO) -- a government company established under Brazilian law (5.615/70) -- is directed exclusively to its addressee and may contain confidential data, protected under professional secrecy rules. Its unauthorized use is illegal and may subject the transgressor to the law's penalties. If you're not the addressee, please send it back, elucidating the failure."
___
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral


[pgbr-geral] RES: Function com mais de um retorno

2009-11-20 Por tôpico Saulo Morais Lara
Obrigado.

 

De: pgbr-geral-boun...@listas.postgresql.org.br
[mailto:pgbr-geral-boun...@listas.postgresql.org.br] Em nome de Wolak
Enviada em: sexta-feira, 20 de novembro de 2009 10:26
Para: Comunidade PostgreSQL Brasileira
Assunto: Re: [pgbr-geral] Function com mais de um retorno

 

Exemplo...
PS. Vc tambem pode utilizar o parametro com OUT em vez de TYPEs...

DROP TYPE IF EXISTS exemplo_retorno CASCADE;
CREATE TYPE exemplo_retorno AS (
data  TIMESTAMP,
valor NUMERIC(15,2),
descricao VARCHAR);

CREATE OR REPLACE FUNCTION exemplo()
RETURNS SETOF exemplo_retorno AS
$$
DECLARE
   rRetorno exemplo_retorno;
BEGIN
FOR i IN 1..10
LOOP
rRetorno.data = CURRENT_TIMESTAMP;
rRetorno.valor = RANDOM();
rRetorno.descricao = 'LINHA = '||i;
RETURN NEXT rRetorno;
END LOOP;
RETURN;
END;
$$
LANGUAGE plpgsql;

Chamada da PL:
SELECT * FROM exemplo();
OU 
SELECT exemplo();
OU 
SELECT (exemplo()).valor;

Wolak.


Saulo Morais Lara escreveu: 

É possível uma função retornar mais de um valor? Alguem tem um exemplo?
Obrigado.

 

Saulo Morais Lara

Analista de Sistemas

Ability Informática Ltda

Rua São Paulo, 106 - São José - Pará de Minas - MG

(37) 3232-1127 / (37) 9194-0234

sa...@abilityonline.com.br

www.abilityonline.com.br

 



__ Information from ESET NOD32 Antivirus, version of virus signature
database 4620 (20091118) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



 



  _  



 
___
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
 
 
 
__ Information from ESET NOD32 Antivirus, version of virus signature
database 4620 (20091118) __
 
The message was checked by ESET NOD32 Antivirus.
 
http://www.eset.com
 
  



__ Information from ESET NOD32 Antivirus, version of virus signature
database 4624 (20091120) __

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

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