Cursor-basierte Datensätze in PostgreSQL

Ich versuche, verwenden Sie Cursor für eine Abfrage, die joins von mehreren Tabellen. Ich habe gesehen, dass bei oracle gibt es eine cursor-basierten Datensatz. Wenn ich versuche, das gleiche für Postgres, wirft es einige Fehler. Wie kann ich das gleiche tun in Postgres?

CREATE OR REPLACE FUNCTION avoidable_states()
RETURNS SETOF varchar AS
$BODY$
DECLARE
    xyz CURSOR FOR select * from address ad
                            join city ct on ad.city_id = ct.city_id;    
    xyz_row RECORD;
BEGIN   
    open xyz;

    LOOP
    fetch xyz into xyz_row;
        exit when xyz_row = null;
        if xyz_row.city like '%hi%' then
            return next xyz_row.city;               
        end if;
    END LOOP;
    close xyz;  
END;
$BODY$
  LANGUAGE plpgsql VOLATILE;

Fehler den ich bekomme, ist:

ERROR:  relation "xyz" does not exist
CONTEXT:  compilation of PL/pgSQL function "avoidable_states" near line 4
InformationsquelleAutor Zeus | 2014-03-12
Schreibe einen Kommentar