云数据库 GAUSSDB-MOVE:示例

时间:2025-03-03 09:50:32

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
--创建SCHEMA。
openGauss=# CREATE SCHEMA tpcds;

--创建表tpcds.reason。
openGauss=# CREATE TABLE tpcds.reason
(
r_reason_sk         INTEGER      NOT NULL,
r_reason_id         CHAR(16)     NOT NULL,
r_reason_desc       VARCHAR(40)
);

--向表中插入多条记录。
openGauss=# 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');

--开始一个事务。
openGauss=# START TRANSACTION;

--定义一个名为cursor1的游标。
openGauss=# CURSOR cursor1 FOR SELECT * FROM tpcds.reason;

--忽略游标cursor1的前3行。
openGauss=# MOVE FORWARD 3 FROM cursor1;

--抓取游标cursor1的前4行。
openGauss=# FETCH 4 FROM cursor1;
 r_reason_sk |   r_reason_id    |                                            r_reason_desc                                             
-------------+------------------+------------------------------------------------------------------------------------------------------
           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                                                                                       
(4 rows)

--关闭游标。
openGauss=# CLOSE cursor1;

--结束一个事务。
openGauss=# END;

--删除表。
openGauss=# DROP TABLE tpcds.reason;

--删除SCHEMA。
openGauss=# DROP SCHEMA tpcds CASCADE;
support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-0428.html