Friday, May 30, 2008

[pgsql-es-ayuda] pl/pgsql para torpes

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

--
TIP 5: ¿Has leído nuestro extenso FAQ?

http://www.postgresql.org/docs/faqs.FAQ.html

No comments: