oracle 游标笔记

时间:2022-04-10 04:39:20
declare
v_x number;
v_y number;
v_geo clob;
cursor cur is
select c_x, c_y
from t_map_data
where c_type = 'STREET'
and c_object_id = '6FABC5EF8F9D4050950A775CDC86DC47'
order by c_id;
begin
v_geo := 'POLYGON(('; open cur; --打开游标
fetch cur
into v_x, v_y; --让游标指针往下移动
while cur%found --判断游标指针是否指向某行记录
loop
--遍历
--dbms_output.put_line('v_x' || v_x);
v_geo := v_geo || ',' || to_char(v_x) || ' ' || to_char(v_y);
fetch cur
into v_x, v_y;
end loop;
close cur;
v_geo := v_geo || '))';
--dbms_output.put_line(v_geo); insert into T_TEMP_TEST(c_Object_Id,c_map_data)
values('6FABC5EF8F9D4050950A775CDC86DC47',v_geo);
end;