• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 917
  • Last Modified:

Identifying end of cursor in plpgsql

How do you identify the end of a cursor in plpgsql?

Oracle:

 WHILE mycursor%FOUND LOOP
   
 END LOOP;

How to do that in plpgsql ?

-g
0
gmanpert
Asked:
gmanpert
1 Solution
 
ivanovnCommented:
General idea: open the cursor, fetch the next record, see if it was found. If it was, continue processing, otherwise exit the loop, then close the cursor.

OPEN cursor_name;
LOOP
  FETCH cursor_name INTO field_list;
  IF NOT FOUND THEN
     EXIT;
  END IF;
END LOOP;
CLOSE cursor_name;
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now