pl/pgsql para torpes

From: "Juan Carlos Barranco de Paz" <jcb(at)greccosoft(dot)es>
To: <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: pl/pgsql para torpes
Date: 2008-05-30 09:12:54
Message-ID: 000001c8c235$58a20ed0$09e62c70$@es
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola, estoy empezando a trabajar con pl/pgsql y no entiendo bien el uso de
las comillas y del raise, por favor me podeis decir como hacer esto o que
estoy haciendo mal y un donde puedo conseguir un manual paras torpes de
pl/pgsql.

Cuando ejecuto select dw0_0010() me devuelve este error :
ERROR: too many parameters specified for RAISE
CONTEXT: PL/pgSQL function "dw0_0010_1" line 6 at raise
sentencia SQL: «SELECT dw0_0010_1( $1 )»
PL/pgSQL function "dw0_0010" line 13 at perform

********** Error **********

ERROR: too many parameters specified for RAISE
Estado SQL:42601
Contexto:PL/pgSQL function "dw0_0010_1" line 6 at raise
sentencia SQL: «SELECT dw0_0010_1( $1 )»
PL/pgSQL function "dw0_0010" line 13 at perform

Estas son las funciónes :

CREATE OR REPLACE FUNCTION dw0_0010()
RETURNS smallint AS
$BODY$
DECLARE
dw01 dw01conf%ROWTYPE;
dw0_0010_c cursor for select * from dw01conf;
BEGIN
OPEN dw0_0010_c ;
LOOP
FETCH dw0_0010_c INTO dw01;
EXIT WHEN NOT FOUND;
PERFORM dw0_0010_1(dw01);
END LOOP;
CLOSE dw0_0010_c;
RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;

------ Hasta aqui creo que va bien pero esta me falla por todos lados

CREATE OR REPLACE FUNCTION dw0_0010_1(dw01 dw01conf)
RETURNS smallint AS
$BODY$
DECLARE
aux0 text;
dw10 dw10tcom%ROWTYPE;
dw0_0010_1_c refcursor;
BEGIN
RAISE NOTICE 'texto1', dw01.empresa;

if dw01.origen = 1 or dw01.origen = 3
then
aux0 := 'select distinct
c.empresa,to_number(to_char(c.fecha,''YYYYMMDDHH24''),''9999999999''),
to_number(to_char(c.fecha,''YYYY''),''9999''),
to_number(to_char(c.fecha,''Q''),''9''),
to_number(to_char(c.fecha,''MM''),''99''),
to_number(to_char(c.fecha,''W''),''9''),
to_number(to_char(c.fecha,''WW''),''99''),
to_number(to_char(c.fecha,''ID''),''9''),
to_number(to_char(c.fecha,''DD''),''99'')
from gc05albc c,gc06albl l
where c.empresa = ''' || dw01.empresa || '''
and c.serie = l.serie
and c.albaran = l.albaran
and c.fecha >=''' || dw01.fecha_inicial
|| '''
and c.proveedor = l.proveedor
and l.tipo = 1
and l.unidades <> 0
and length(l.articulo) = 0';
end if;

OPEN dw0_0010_1_c FOR EXECUTE aux0;

RAISE NOTICE 'PASA';
LOOP
FETCH dw0_0010_1_c INTO dw10;
EXIT WHEN NOT FOUND;
RAISE NOTICE 'prueba', dw10.tiempo;
END LOOP;

RAISE NOTICE 'PASA FIN';

RETURN 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 3145 (20080529) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Juan Carlos Barranco de Paz 2008-05-30 10:20:06 pl/pgsql para torpes
Previous Message yaa 2008-05-30 04:33:41 hola