Postgresql Cursor For Loop Example
PL/SQL cursor FOR loop has one great advantage of loop continued until row not found. In sometime you require to use explicit cursor with FOR loop instead of use OPEN, FETCH, and CLOSE statement.
FOR loop iterate repeatedly and fetches rows of values from database until row not found.

Explicit Cursor FOR LOOP Example
Using PL/pgSQL for loop to iterate over a range of integers The following illustrates the syntax of the for loop statement that loops through a range of integers: for loopcounter in reverse from. To by step loop statements end loop label.
An example of parameterized cursor using cursor FOR LOOP: Cursor Parameter « Cursor « Oracle PL/SQL Tutorial. Let us take a look at an example now: If the query is executed as cursor you will notice that PostgreSQL goes for an index scan to speed up the creation of the first 10% of the data. If the entire resultset is fetched, PostgreSQL will go for a sequential scan and sort the data because the index scan is considered to be too expensive. (2 replies) hi I got 2 functions write in pl/pgsql. In the first function, i create a cursor and i need to use it into an other function so the parameter is a refcursor. The code: 1st function: DECLARE childCursor CURSOR FOR select. from.
following one emp_information table:
EMP_NO | EMP_NAME | EMP_DEPT | EMP_SALARY |
---|---|---|---|
1 | Forbs ross | Web Developer | 45k |
2 | marks jems | Program Developer | 38k |
3 | Saulin | Program Developer | 34k |
4 | Zenia Sroll | Web Developer | 42k |
Display employee number wise first two employee details emp,
Example
Postgresql Cursor For Loop Example Java


Result
Postgresql Function For Loop
EMP_No: 1
EMP_Name: Forbs ross
EMP_Dept: Web Developer
EMP_Salary:45k
EMP_No: 2
EMP_Name: marks jems
EMP_Dept: Program Developer
EMP_Salary:38k
PL/SQL procedure successfully completed.
Postgresql Cursor For Loop
