CREATE OR REPLACE FUNCTION plpgsql_example2() RETURNS integer AS
$$
DECLARE
    cur refcursor;
    word text;
    processed integer := 0;
BEGIN
    -- restore fiveletterstrings to all lowercase
    UPDATE fiveletterstrings SET x = lower(x);

    -- bind and open the cursor
    OPEN cur FOR SELECT x FROM fiveletterstrings FOR UPDATE;

    -- uppercase the vowels
    LOOP
        FETCH cur INTO word;
        EXIT WHEN NOT FOUND;
        word := translate(word, 'aeiou', 'AEIOU');
        UPDATE fiveletterstrings SET x = word WHERE CURRENT OF cur;
        processed := processed + 1;
    END LOOP;
    RETURN processed;
END;
$$ LANGUAGE plpgsql;
