如何将巨型几何体插入SDO_GEOMETRY类型的字段中?

时间:2016-11-08 20:50:29

标签: oracle plsql oracle-spatial

我正在尝试将此http://pastebin.com/cKXnCqx7几何图形插入到SDO_GEOMETRY字段中,如下所示:

declare
str clob = http://pastebin.com/cKXnCqx7
begin
INSERT INTO TEMP_TEST_GEOMETRY VALUES (SDO_CS.TRANSFORM (SDO_GEOMETRY (str, 4674), 1000205));
end;

并且产生以下错误:

enter image description here

1 个答案:

答案 0 :(得分:4)

PL / SQL中字符串文字的最大大小为32K。您正在尝试分配98K +文字,这是导致错误的原因(尽管因为它指的是4k,这似乎来自普通的SQL调用而不是您显示的PL / SQL块)。它没有尝试从CLOB创建sdo_geometry对象。

理想情况下,您要从文件或其他一些机制中加载值,以便为您提供完整的CLOB。如果你必须将它视为文字,你必须手动将其分成几个块;如果你把它们变大,至少有4个这个值:

declare
  str clob;
begin
  dbms_lob.createtemporary(str, false);
  dbms_lob.append(str, 'POLYGON ((-47.674240062208945 -2.8066454423517624, -47.674313162 -2.8066509996, <...snip...>');
  dbms_lob.append(str, '47.6753521374 -2.8067875453, -47.6752566506 -2.8067787567, -47.6752552377 -2.8067785117, <...snip...>');
  dbms_lob.append(str, '-47.658134547 -2.8044846153, -47.6581360233 -2.8044849964, -47.6581811229 -2.8044926289, <...snip...>');
  dbms_lob.append(str, '-47.6717079633 -2.8057792966, -47.6717079859 -2.80577931, -47.6717083252 -2.8057795101, -47.6718125136 -2.8058408619, -47.6719547186 -2.8059291721, -47.6719573483 -2.8059307844, -47.6719575243 -2.8059308908, -47.6719601722 -2.8059324729, -47.6720975574 -2.8060134925, -47.6721015308 -2.8060157903, -47.6721017969 -2.8060159412, -47.6721058088 -2.806018171, -47.6721847946 -2.8060611947, -47.6721897923 -2.8060650985, -47.6722059263 -2.8060767675, -47.6722070291 -2.8060775047, -47.6722416572 -2.8060971165, -47.6722428566 -2.8060976832, -47.6722611616 -2.8061055189, -47.6722666301 -2.8061076243, -47.6722849174 -2.806116847, -47.6722862515 -2.8061174528, -47.6723066339 -2.8061257231, -47.6723316499 -2.8061347029, -47.6723426416 -2.8061383836, -47.6723433793 -2.8061386131, -47.672354519 -2.8061418177, -47.6723803034 -2.8061486384, -47.6725084039 -2.8061908942, -47.6725130545 -2.8061923817, -47.6725133654 -2.806192478, -47.6725180423 -2.806193881, -47.6728423039 -2.8062879629, -47.6728698649 -2.8062995965, -47.6728952856 -2.8063088527, -47.672897007 -2.8063093833, -47.672949984 -2.8063200428, -47.6729517767 -2.8063202193, -47.672966443 -2.8063209226, -47.6729679855 -2.8063213223, -47.6733393514 -2.8064196858, -47.6733738728 -2.8064264543, -47.6733761939 -2.8064267537, -47.6733804796 -2.8064270239, -47.6733890639 -2.806431641, -47.6734057692 -2.8064398944, -47.6734069006 -2.8064404055, -47.6734241363 -2.8064474849, -47.6736663052 -2.8065373005, -47.6736676833 -2.8065378073, -47.6736677752 -2.8065378409, -47.673669156 -2.8065383402, -47.6737754465 -2.8065764489, -47.673793217 -2.8065850801, -47.6737945765 -2.8065856723, -47.6738366895 -2.8066000123, -47.6738381279 -2.8066003728, -47.6738811819 -2.8066074503, -47.6739137725 -2.8066153813, -47.6739159177 -2.806615636, -47.6739318345 -2.8066165588, -47.673951326 -2.806622013, -47.6739530661 -2.8066223195, -47.6739793945 -2.8066256302, -47.6740948445 -2.8066344025, -47.674240062208945 -2.8066454423517624))');
  INSERT INTO TEMP_TEST_GEOMETRY
  VALUES (SDO_CS.TRANSFORM (SDO_GEOMETRY (str, 4674), 1000205));
  dbms_lob.freetemporary(str);
end;
/

您可以缩小块并添加更多内容,这在某些方面可能更易于管理,但需要设置更多工作。手动操作仍然很痛苦,所以如果你不能以其他方式获得价值,这可能是最后的手段。

如果字符串来自HTTP调用,您可以使用dbms_lob.append以大致相同的方式读取块中的响应并将其转换为CLOB。究竟如何取决于您当前获得响应所使用的机制。另外值得注意的是Oracle 12c有built-in JSON handling;在早期版本中,您可以使用第三方PL/JSON modulewhich seems to handle CLOBs