漂泊雪狼的博客

思考,讨论,分享C#,JavaScript,.NET,Oracle,SQL Server……技术

导航

oracle 游标笔记

Posted on 2016-01-11 17:29  漂泊雪狼  阅读(152)  评论(0编辑  收藏  举报
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;