[email protected], pues se que no me pedian mi email, pero chevere tenerlos.
aca en estos foros han quedado ejemplos de 2 procedimientos almacenados que he creado sattisfactoriamente gracias ahuesos52, por si les sirven, aqui los posteo de nuevo y con la forma de llamarlos
Código SQL:
Ver originalCREATE OR REPLACE FUNCTION p_get_blocks_count(INTEGER, VARCHAR,INTEGER,VARCHAR,VARCHAR) RETURNS SETOF type_block_count AS $BODY$
DECLARE
FILTER ALIAS FOR $1;
list ALIAS FOR $2;
city ALIAS FOR $3;
socioeconomic ALIAS FOR $4;
country ALIAS FOR $5;
sql_query VARCHAR;
query_result type_block_count;
BEGIN
IF FILTER = 1 THEN
sql_query := 'SELECT country_name,region_name,city_name,locale_name,locale_code,socioeconomic_status,city_code,total
FROM conteo_manzanas_localidad_'||country||'
WHERE locale_code IN ('||list||') AND
city_code = '||city||' AND
socioeconomic_status IN ('||socioeconomic||')';
FOR query_result IN EXECUTE sql_query LOOP RETURN NEXT query_result;
END LOOP;
ELSE
sql_query := 'SELECT country_name,region_name,city_name,neighborhood_name,neighborhood_code,socioeconomic_status,city_code,total,locale_name,locale_code,
FROM conteo_manzanas_barrio_'||country||'
WHERE neighborhood_code IN ('||list||') AND
city_code = '||city||' AND
socioeconomic_status IN ('||socioeconomic||')';
FOR query_result IN EXECUTE sql_query LOOP RETURN NEXT query_result;
END LOOP;
END IF;
RETURN;
END $BODY$
LANGUAGE plpgsql;
SELECT * FROM p_get_blocks_count(1, $$119 ,120 ,121 ,122$$ ,739,$$'3','4','5'$$,'co')
SELECT * FROM p_get_blocks_count(2, $$'000076','000063','000066','000061'$$ ,76834,$$'3','4','5'$$,'co')
Y EL OTRO ES ALGO PARECIDO A LO QUE NECESITA QUINTANA RO
Código SQL:
Ver originalCREATE OR REPLACE FUNCTION p_update_locales_in_count() RETURNS INTEGER AS $BODY$
DECLARE
query_count RECORD;
query_has_locales RECORD;
real_data RECORD;
BEGIN
FOR query_count IN SELECT co.neighborhood_code,co.city_code
FROM conteo_manzanas_barrio_co co,sm_city ci
WHERE co.city_code = ci.pk_city AND has_locales = TRUE
LIMIT 1 OFFSET 0 LOOP
SELECT INTO real_data sl.pk_locale,sl.name
FROM sm_locale sl,sm_neighborhood sn,servcon_barrios sb
WHERE sn.pk_neighborhood = query_count.neighborhood_code AND
sl.fk_pk_city = query_count.city_code AND
sb.cod_localidad = sl.locale_code AND
sb.cod_barrio = sn.neighborhood_code AND
sl.name = sb.nom_localidad;
UPDATE conteo_manzanas_barrio_co
SET locale_code = real_data.pk_locale, locale_name = real_data.name
WHERE neighborhood_code = query_count.neighborhood_code;
END LOOP;
RETURN 0;
END $BODY$
LANGUAGE plpgsql;
SELECT p_update_locales_in_count()