Updated on 2024-05-07 GMT+08:00

MOVE

Function

MOVE repositions a cursor without retrieving any data. MOVE works exactly like the FETCH statement, except it only repositions the cursor and does not return rows.

Precautions

None

Syntax

MOVE [ direction [ FROM | IN ] ] cursor_name;

The direction clause specifies optional parameters.

NEXT
   | PRIOR
   | FIRST
   | LAST
   | ABSOLUTE count
   | RELATIVE count
   | count
   | ALL
   | FORWARD
   | FORWARD count
   | FORWARD ALL
   | BACKWARD
   | BACKWARD count
   | BACKWARD ALL

Parameter Description

The parameters of MOVE and FETCH are the same. For details, see Parameters in FETCH.

On successful completion, a MOVE statement returns a tag of the form MOVE count. The count is the number of rows that a FETCH statement with the same parameters would have returned (possibly zero).

Examples

-- Create a schema.
gaussdb=# CREATE SCHEMA tpcds;

-- Create the tpcds.reason table.
gaussdb=# CREATE TABLE tpcds.reason
(
r_reason_sk         INTEGER      NOT NULL,
r_reason_id         CHAR(16)     NOT NULL,
r_reason_desc       VARCHAR(40)
);

-- Insert multiple records into the table.
gaussdb=# INSERT INTO tpcds.reason VALUES (1, 'AAAAAAAABAAAAAAA', 'Xxxxxxxxx'),(2, 'AAAAAAAACAAAAAAA', ' Xxxxxxxxx'),(3, 'AAAAAAAADAAAAAAA', ' Xxxxxxxxx'),(4, 'AAAAAAAAEAAAAAAA', 'Not the product that was ordered'),(5, 'AAAAAAAAFAAAAAAA', 'Parts missing'),(6, 'AAAAAAAAGAAAAAAA', 'Does not work with a product that I have'),(7, 'AAAAAAAAHAAAAAAA', 'Gift exchange');

-- Start a transaction.
gaussdb=# START TRANSACTION;

-- Define a cursor cursor1.
gaussdb=# CURSOR cursor1 FOR SELECT * FROM tpcds.reason;

-- Skip the first three rows of cursor1.
gaussdb=# MOVE FORWARD 3 FROM cursor1;

-- Fetch the first four rows from cursor1.
gaussdb=# FETCH 4 FROM cursor1;
 r_reason_sk |   r_reason_id    |                                            r_reason_desc                                             
-------------+------------------+------------------------------------------------------------------------------------------------------
           4 | AAAAAAAAEAAAAAAA | Not the product that was ordred                                                                     
           5 | AAAAAAAAFAAAAAAA | Parts missing                                                                                       
           6 | AAAAAAAAGAAAAAAA | Does not work with a product that I have                                                            
           7 | AAAAAAAAHAAAAAAA | Gift exchange                                                                                       
(4 rows)

-- Close the cursor.
gaussdb=# CLOSE cursor1;

-- End the transaction.
gaussdb=# END;

-- Delete a table.
gaussdb=# DROP TABLE tpcds.reason;

-- Delete a schema.
gaussdb=# DROP SCHEMA tpcds CASCADE;

Helpful Links

CLOSE and FETCH