创建了一个数据库:test;一个schemas:test;一个表:t3,只有一个字段:id
插入数据:
insert into test.test.t3(id) values(1)
insert into test.test.t3(id) values(2)
访问数据:
select * from test.test.t3
用游标的方式访问数据:
DO
$$
DECLARE
r RECORD;
cur CURSOR FOR SELECT id FROM test.test.t3;
BEGIN
OPEN cur;
LOOP
FETCH cur INTO r;
EXIT WHEN NOT FOUND;
RAISE NOTICE 'ID: %', r.id;
END LOOP;
CLOSE cur;
END
$$
用游标的方式访问数据的结果:
注意: ID: 1
注意: ID: 2
DO
Query returned successfully in 52 msec.