Re: AYUDA STORE PROCEDURE EN POSTGRESQL

From: angel Iracheta <angel(dot)iracheta(at)gmail(dot)com>
To: ruben avila <ravila(at)ciclo2000(dot)com(dot)pe>
Cc: Ayuda Postgres <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: AYUDA STORE PROCEDURE EN POSTGRESQL
Date: 2005-06-08 17:21:37
Message-ID: 62b48473050608102141d8675@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Que tal...

Un pequeño ejemplo con arrays podría ser de la siguiente manera:

1. Crea esta tabla:

CREATE TABLE calificaciones
(
matricula numeric(7),
cve_materia varchar(10),
resultado numeric(6,2)
)
WITHOUT OIDS;
ALTER TABLE calificaciones OWNER TO postgres;
GRANT ALL ON TABLE calificaciones TO postgres WITH GRANT OPTION;

2. Crea esta función:

CREATE OR REPLACE FUNCTION prueba_array("numeric", _text)
RETURNS bool AS
'
DECLARE
t_matricula ALIAS FOR $1;
t_resultados ALIAS FOR $2;
f_ciclo INTEGER;
f_posini INTEGER;
f_posfin INTEGER;
BEGIN
f_posini:=POSITION(\':\' IN array_dims(t_resultados))+1;
f_posfin:=POSITION(\']\' IN array_dims(t_resultados));
FOR f_ciclo IN 1..SUBSTRING(array_dims(t_resultados) FROM f_posini
FOR f_posfin-f_posini)::INT LOOP
INSERT INTO calificaciones (matricula,cve_materia,resultado)
VALUES (t_matricula,t_resultados[f_ciclo][1],TO_NUMBER(t_resultados[f_ciclo][2],\'99999\'));
END LOOP;
RETURN 1;
END;
'
LANGUAGE 'plpgsql' IMMUTABLE;

3. Ejecuta--> select
prueba_array(1500,'{{M-0100,75},{M-0200,91},{M-0300,84}}');

4. Y si hacemos un select a la tabla calificaciones:

select * from calificaciones;

matricula cve_materia resultado
-------------- ------------------ ----------------
1 1500 M-0100 75.00
2 1500 M-0200 91.00
3 1500 M-0300 84.00

Saludos!!!

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message dass dass 2005-06-08 17:53:12 Imagen
Previous Message Alvaro Herrera 2005-06-08 17:18:29 Re: Separador decimal y de miles