Re: Funcion

From: Espartano <espartano(dot)mail(at)gmail(dot)com>
To: gilberto(dot)castillo(at)etecsa(dot)cu
Cc: "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: Funcion
Date: 2008-03-05 22:20:54
Message-ID: d353bd50803051420j519e1889k892e944ef32b26cd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

2008/3/5, Gilberto Castillo Martínez <gilberto(dot)castillo(at)etecsa(dot)cu>:
> Estoy utilizando esta función para que me devuelva un select:
>
> CREATE OR REPLACE FUNCTION listarTipoDocumento(dato "varchar")
> RETURNS varchar AS
> $BODY$
> DECLARE
>
> lista_dato record;
> BEGIN
> IF dato isnull THEN
> select * into lista_dato from nom_tipo_documento;
> END IF;
> IF dato notnull THEN
> select * into lista_dato from nom_tipo_documento where
> tipo_documento like '%dato%';
> END IF;
> RETURN lista_dato;
> END;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
>
> Pero me devuelve la cadena vacía ¿ que estoy haciendo mal? help.

Algunas cosas estas haciendo mal, primero especifícas que te regrese
un tipo varchar cuando realmente regresas un record, luego si esperas
que te regrese mas de una tupla tienes que especificarlo mediante
SETOF y poniendo el select en un for in ...... y darle dentro del
ciclo return next y al final return ......

lamento no poderte ayudar mas pero tiene muchisimo tiempo que no toco
el plpgsql.

--
"Linux is for people who hate Windows, BSD is for people who love UNIX".
"Social Engineer -> Because there is no patch for human stupidity"
"The Unix Guru's View of Sex unzip ; strip ; touch ; grep ; finger ;
mount ; fsck ; more ; yes ; umount ; sleep."
"Documentation is like sex: when it is good, it is very, very good;
and when it is bad, it is better than nothing."

In response to

  • Funcion at 2008-03-05 22:05:09 from Gilberto Castillo Martínez

Responses

  • Re: Funcion at 2008-03-06 00:06:49 from marcelo Cortez

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Gabriel Hermes Colina Zambra 2008-03-06 00:03:13 Re: Fwd: Encuesta sobre bases de datos
Previous Message Gilberto Castillo Martínez 2008-03-05 22:05:09 Funcion