我有一个XML文件,我加载到XMLType变量中,我想从具有不同属性值的几个.../ExtendedData/SchemaData/SimpleData
节点和一个.../Polygon/outerBoundaryIs/LinearRing/coordinates
节点中提取不同的值,将它们插入此表中:
CREATE TABLE LIE_GEOF
(
IDE_GEO VARCHAR2(24) NOT NULL,
COD_COM VARCHAR2(3) ,
COD_VIL VARCHAR2(5) ,
NOM_COM VARCHAR2(50) ,
ALT_MOY NUMBER(4,0) ,
SUP_HEC NUMBER(12,0) ,
NBR_POP NUMBER(10,0) ,
COD_ARR VARCHAR2(1) ,
COD_DEP VARCHAR2(2) ,
NOM_DEP VARCHAR2(30) ,
COD_REG VARCHAR2(2) NOT NULL,
NOM_REG VARCHAR2(35) NOT NULL,
TXT_POL CLOB ,
CONSTRAINT LIE_GEOF_PK PRIMARY KEY (IDE_GEO) USING INDEX
);
插入必须遵循以下规则:
/Document/Folder/Placemark/ExtendedData/SchemaData/SimpleData
个节点的值进入表格的11个第一个字段。/Document/Folder/Placemark/Polygon/outerBoundaryIs/LinearRing/coordinates
的值进入表的最后一个字段(TXT_POL
,这是一个CLOB)。E.g。插入:
ID_GEOFLA
COD_COM
TXT_POL
这是我的XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="COMMUNE" id="COMMUNE">
<SimpleField name="ID_GEOFLA" type="string"></SimpleField>
<SimpleField name="CODE_COM" type="string"></SimpleField>
<SimpleField name="INSEE_COM" type="string"></SimpleField>
<SimpleField name="NOM_COM" type="string"></SimpleField>
<SimpleField name="STATUT" type="string"></SimpleField>
<SimpleField name="X_CHF_LIEU" type="int"></SimpleField>
<SimpleField name="Y_CHF_LIEU" type="int"></SimpleField>
<SimpleField name="X_CENTROID" type="int"></SimpleField>
<SimpleField name="Y_CENTROID" type="int"></SimpleField>
<SimpleField name="Z_MOYEN" type="int"></SimpleField>
<SimpleField name="SUPERFICIE" type="float"></SimpleField>
<SimpleField name="POPULATION" type="int"></SimpleField>
<SimpleField name="CODE_ARR" type="string"></SimpleField>
<SimpleField name="CODE_DEPT" type="string"></SimpleField>
<SimpleField name="NOM_DEPT" type="string"></SimpleField>
<SimpleField name="CODE_REG" type="string"></SimpleField>
<SimpleField name="NOM_REG" type="string"></SimpleField>
</Schema>
<Folder><name>COMMUNE</name>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMMUNE">
<SimpleData name="ID_GEOFLA">COMMUNE00000000000000001</SimpleData>
<SimpleData name="CODE_COM">216</SimpleData>
<SimpleData name="INSEE_COM">32216</SimpleData>
<SimpleData name="NOM_COM">LOURTIES-MONBRUN</SimpleData>
<SimpleData name="STATUT">Commune simple</SimpleData>
<SimpleData name="X_CHF_LIEU">500820</SimpleData>
<SimpleData name="Y_CHF_LIEU">6264958</SimpleData>
<SimpleData name="X_CENTROID">500515</SimpleData>
<SimpleData name="Y_CENTROID">6265413</SimpleData>
<SimpleData name="Z_MOYEN">252</SimpleData>
<SimpleData name="SUPERFICIE">966</SimpleData>
<SimpleData name="POPULATION">139</SimpleData>
<SimpleData name="CODE_ARR">3</SimpleData>
<SimpleData name="CODE_DEPT">32</SimpleData>
<SimpleData name="NOM_DEPT">GERS</SimpleData>
<SimpleData name="CODE_REG">76</SimpleData>
<SimpleData name="NOM_REG">LANGUEDOC-ROUSSILLON-MIDI-PYRENEES</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>0.523147623541907,43.45799199978569 0.523016926446493,43.458214941462735 0.522819929792566,43.458571384907614 0.523158712137025,43.463844819851531 0.525919177622142,43.466722549687468 0.534681879985461,43.464747550783542 0.543836737927885,43.469777335356682 0.548247371718109,43.472768370413348 0.550322756594321,43.477287979477317 0.551468474597506,43.478160877453561 0.552015304755935,43.478439663216299 0.552453497415003,43.478221827985358 0.555100797978036,43.474481276701823 0.555807213328205,43.473593492995199 0.558991284076016,43.472423990577127 0.56086273814842,43.472185286329086 0.564888471150887,43.471711436291166 0.566623349308327,43.471515470873307 0.567427459167519,43.471439009340536 0.568571543995261,43.468291800893347 0.569365669469214,43.464620982438333 0.567828019844389,43.460101271732199 0.567509757649282,43.458423540573534 0.567072440746275,43.458596443463989 0.566331570343829,43.458584307788286 0.562627166751401,43.458262522540728 0.560416690686975,43.457911246027962 0.559805673058565,43.457721968280353 0.554192459548327,43.459256113328266 0.551822357433493,43.460071196874786 0.549836876685425,43.460442173041024 0.548786602838374,43.460469727487656 0.548449080291229,43.459430568250141 0.548216275147381,43.458572899197428 0.549999653359123,43.456795920024497 0.550686563685562,43.456536916638157 0.553860511528465,43.456050548180549 0.555937760797512,43.456713991749211 0.55612105137207,43.45676223078474 0.556436817751908,43.456542525872251 0.556441991370131,43.456362621910301 0.555847087361284,43.455678628111059 0.552874026887119,43.453652001502725 0.551053529573104,43.452678364660322 0.550753210222253,43.452448351090517 0.550735797660037,43.451000593387143 0.550915991905762,43.449206264922303 0.553238100421676,43.447940984342978 0.553771683066166,43.447653300288636 0.554738707003582,43.44728268718503 0.56019111305528,43.444531605495072 0.562938636713414,43.443858069856788 0.56516268550633,43.443759562234121 0.567023409839381,43.443430527931177 0.566871862109568,43.442340715151943 0.566475653104936,43.44116529926356 0.566069176230466,43.440349687490794 0.564972682557216,43.439523066858889 0.564547029266048,43.439336180634278 0.562328585402901,43.439277281890504 0.559811880846763,43.438853383472782 0.557964223826497,43.438382404156521 0.557848915902549,43.438101676680482 0.557402040643657,43.436611852944097 0.556595818480535,43.436778188864331 0.550636409582979,43.43880112426811 0.546799103741674,43.440005028613726 0.543629269595757,43.4407612883318 0.543320674518776,43.44075609078584 0.54265340718862,43.440385418205821 0.542657248886231,43.440295495610123 0.540784834255311,43.440578841341114 0.539476542216563,43.44101538502607 0.537977690329699,43.441574496966403 0.537598849484849,43.441882721780303 0.525443080131764,43.448439347839923 0.523192997567408,43.452635557123507 0.522863538404974,43.455264457764613 0.523286197033435,43.457500103439656 0.523210047392157,43.457948420812656 0.523147623541907,43.45799199978569</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMMUNE">
<SimpleData name="ID_GEOFLA">COMMUNE00000000000000002</SimpleData>
<SimpleData name="CODE_COM">033</SimpleData>
<SimpleData name="INSEE_COM">47033</SimpleData>
<SimpleData name="NOM_COM">BOUDY-DE-BEAUREGARD</SimpleData>
<SimpleData name="STATUT">Commune simple</SimpleData>
<SimpleData name="X_CHF_LIEU">516424</SimpleData>
<SimpleData name="Y_CHF_LIEU">6384852</SimpleData>
<SimpleData name="X_CENTROID">515575</SimpleData>
<SimpleData name="Y_CENTROID">6385938</SimpleData>
<SimpleData name="Z_MOYEN">112</SimpleData>
<SimpleData name="SUPERFICIE">1019</SimpleData>
<SimpleData name="POPULATION">414</SimpleData>
<SimpleData name="CODE_ARR">3</SimpleData>
<SimpleData name="CODE_DEPT">47</SimpleData>
<SimpleData name="NOM_DEPT">LOT-ET-GARONNE</SimpleData>
<SimpleData name="CODE_REG">75</SimpleData>
<SimpleData name="NOM_REG">AQUITAINE-LIMOUSIN-POITOU-CHARENTES</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>0.662777282430262,44.533218568792947 0.662625822063777,44.533683684987352 0.664135149761232,44.534301045766654 0.664601701741105,44.53474141714144 0.666067383219144,44.536202611177508 0.668371575237184,44.539071163388307 0.668780667988665,44.540111918933022 0.668694056305804,44.54132503082527 0.668237007094513,44.541902583263834 0.661102933562012,44.546525868685222 0.655808192025645,44.551625506724115 0.653467772380693,44.554175912637433 0.653141277604395,44.554576059140636 0.652486763179636,44.555442964276793 0.652183507746879,44.559674906105244 0.652050074453185,44.56203443873585 0.65262297218604,44.565978803821366 0.652985155710664,44.566479151724735 0.653173392380475,44.566527283736086 0.655703231649244,44.566071260198626 0.656280531260281,44.566124944124233 0.665861275263747,44.560864637649679 0.672258642298041,44.557309814039932 0.67799949907915,44.554599131975017 0.681452233083963,44.553121722329216 0.68225272878296,44.55371853273703 0.685712108726268,44.555884152916839 0.690569705466486,44.555408571617306 0.691265658733825,44.555238499982032 0.694383518064652,44.554026576432449 0.695593865542916,44.55350426999884 0.695528458077783,44.551435083497076 0.695086762394766,44.549358943255577 0.694945159859387,44.547737576530992 0.695346064664764,44.546925484921545 0.698073114077193,44.543795107633322 0.70046954041872,44.54119995483682 0.701115056066572,44.54062440044305 0.701895787889718,44.539727437699398 0.701898155870446,44.539638326402738 0.701585945597984,44.539543565425753 0.700850223013555,44.53890231681244 0.699442272579967,44.537576997853272 0.695904965284708,44.533386509441243 0.695362918653616,44.532569143918337 0.695030202600581,44.531034758336737 0.695924050526905,44.530172626698942 0.697096892400962,44.529260473371338 0.698441139658732,44.528342877669623 0.698635976884175,44.528165018106449 0.698670774882986,44.527403828815736 0.694169986184412,44.526478611374884 0.677305847476098,44.525695337096792 0.675878255066445,44.5250519592865 0.675502505745163,44.5248522134494 0.674807388781219,44.525162690384242 0.663037031530505,44.532783664990923 0.662777282430262,44.533218568792947</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMMUNE">
<SimpleData name="ID_GEOFLA">COMMUNE00000000000000003</SimpleData>
<SimpleData name="CODE_COM">009</SimpleData>
<SimpleData name="INSEE_COM">32009</SimpleData>
<SimpleData name="NOM_COM">ARMOUS-ET-CAU</SimpleData>
<SimpleData name="STATUT">Commune simple</SimpleData>
<SimpleData name="X_CHF_LIEU">472979</SimpleData>
<SimpleData name="Y_CHF_LIEU">6278963</SimpleData>
<SimpleData name="X_CENTROID">473004</SimpleData>
<SimpleData name="Y_CENTROID">6278937</SimpleData>
<SimpleData name="Z_MOYEN">221</SimpleData>
<SimpleData name="SUPERFICIE">932</SimpleData>
<SimpleData name="POPULATION">95</SimpleData>
<SimpleData name="CODE_ARR">3</SimpleData>
<SimpleData name="CODE_DEPT">32</SimpleData>
<SimpleData name="NOM_DEPT">GERS</SimpleData>
<SimpleData name="CODE_REG">76</SimpleData>
<SimpleData name="NOM_REG">LANGUEDOC-ROUSSILLON-MIDI-PYRENEES</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>0.211253773793326,43.587275605450763 0.211662108609333,43.586825129365288 0.211410524399261,43.582088410940848 0.208388730598386,43.579871612218852 0.20791605570955,43.579277855019072 0.207747805004554,43.578816168736715 0.208179512909645,43.575542931484456 0.209504673568602,43.573834000361572 0.211507579682536,43.572497189496914 0.212150181576571,43.571835762135244 0.212220464219109,43.571612490215699 0.213304466304859,43.570734613884099 0.213572297332405,43.570191402028087 0.213343145301762,43.569377045441009 0.212477217367309,43.569360214746013 0.204382664237701,43.568630775264452 0.195504880892616,43.567919208267085 0.194771157076325,43.56768057328533 0.189887165282241,43.565695100853603 0.189464969023205,43.5654167771076 0.188573547265921,43.564455566501138 0.188277267038432,43.564134583389972 0.186022497178221,43.560097674244325 0.17965714473443,43.554240687039545 0.182359538159759,43.552852384226945 0.182962621356,43.552645664922274 0.182446681269315,43.552186618810737 0.18232300927318,43.552184308135637 0.168497898595728,43.554156277940244 0.16709367693472,43.5542654823644 0.167166420588363,43.555450395008101 0.167947100991704,43.566173754481518 0.169739934430584,43.568107590095238 0.17062790120118,43.569158906666985 0.170674775790308,43.569564373279157 0.170566743707011,43.570776093398251 0.170501036877491,43.571179526416337 0.170135040125033,43.572700537631427 0.169592574675525,43.573957655078644 0.168949458803322,43.574618831508829 0.161962656163579,43.579477358477909 0.161335403761748,43.5796896447509 0.161682881391107,43.580326261347274 0.165625298788884,43.580720060701331 0.167651845556293,43.579457563414131 0.172907376774138,43.579441484776346 0.178764502682293,43.580614811260261 0.183020836373061,43.587784790504855 0.190549481732969,43.588537141980531 0.191355477908399,43.588822688177068 0.191725286645556,43.589137463308489 0.192379775756839,43.589304741921623 0.198546721318716,43.588371923285642 0.210870974543736,43.587226159609642 0.211253773793326,43.587275605450763</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMMUNE">
<SimpleData name="ID_GEOFLA">COMMUNE00000000000000004</SimpleData>
<SimpleData name="CODE_COM">225</SimpleData>
<SimpleData name="INSEE_COM">38225</SimpleData>
<SimpleData name="NOM_COM">AUTRANS-MEAUDRE EN VERCORS</SimpleData>
<SimpleData name="STATUT">Commune simple</SimpleData>
<SimpleData name="X_CHF_LIEU">898640</SimpleData>
<SimpleData name="Y_CHF_LIEU">6450689</SimpleData>
<SimpleData name="X_CENTROID">898625</SimpleData>
<SimpleData name="Y_CENTROID">6451597</SimpleData>
<SimpleData name="Z_MOYEN">1234</SimpleData>
<SimpleData name="SUPERFICIE">3371</SimpleData>
<SimpleData name="POPULATION">2973</SimpleData>
<SimpleData name="CODE_ARR">1</SimpleData>
<SimpleData name="CODE_DEPT">38</SimpleData>
<SimpleData name="NOM_DEPT">ISERE</SimpleData>
<SimpleData name="CODE_REG">84</SimpleData>
<SimpleData name="NOM_REG">AUVERGNE-RHONE-ALPES</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>5.577223028135769,45.242894349342798 5.57832596943672,45.243222059527241 5.579405352743805,45.243371022191383 5.581393281318908,45.243366554489441 5.583879807369563,45.243609083543291 5.584393415224277,45.243684593379605 5.584706363164017,45.243585461644216 5.597939571410846,45.235202758388454 5.597932009534475,45.235067797149192 5.597735530497109,45.234983175547697 5.593525407710597,45.23032598100815 5.593407141698956,45.225917867030205 5.592935859647946,45.218549457778238 5.591818418919541,45.20665188726359 5.592324469084464,45.202045519989611 5.592360387984282,45.194616726820655 5.592062190466056,45.189869583881169 5.588405135802581,45.18315444315936 5.585955275660742,45.178063494435072 5.584708204811351,45.173935642642597 5.58317010835984,45.168083001649848 5.582929680649567,45.167235419723959 5.58266313119152,45.165712771343379 5.58222103751657,45.164689677638918 5.581670213054493,45.163986213256557 5.580207623453069,45.161160611061874 5.578947247375383,45.158519508031873 5.578785449469628,45.157938569461315 5.578466103115896,45.15551714841677 5.578405646819617,45.154483422388317 5.577928367445298,45.152832310190618 5.576422825654472,45.147519415266053 5.575055817042497,45.142306016064268 5.574010929727948,45.138442812442122 5.569886182007006,45.137293813512301 5.567431609863881,45.136644956438062 5.559512994676524,45.131968530965842 5.552488239743422,45.12523964839076 5.549925256615055,45.11918676788418 5.548942155727791,45.116267902375498 5.54809183826008,45.113636077924021 5.54304261824092,45.103915702437661 5.541186817821163,45.101484251797203 5.539607786090492,45.099233848807309 5.539254012339214,45.098614007454486 5.537988337271168,45.098695988165893 5.525330845617684,45.100291557757032 5.516559551312187,45.102076361315767 5.515673588077414,45.102146809640558 5.510960672585581,45.101436008987868 5.503655622743139,45.099816656819648 5.502498984104886,45.099579584852449 5.500714091434282,45.099486321764374 5.495946886320536,45.099486883613594 5.493215842703018,45.099511076201516 5.492329890741765,45.09958133898413 5.491964615581535,45.099861562497225 5.490817838869063,45.100929476693878 5.490763593578549,45.101110858312595 5.490769591583746,45.105927554983744 5.490833616150495,45.107050382628692 5.49194827048531,45.112421555600562 5.492205637544673,45.120704529973253 5.491850471979054,45.123640236865867 5.492087604562631,45.128044611271768 5.493441844917415,45.137774197940558 5.493606714068908,45.138445252930254 5.494173374852235,45.140589232267239 5.49584150526466,45.14442200079219 5.496571863993317,45.146066839051002 5.498716737985253,45.149336678837628 5.502331360906916,45.153834734559432 5.503709158680629,45.155685724457776 5.504333877845138,45.156613105210369 5.507363307441096,45.161981784085413 5.507996692262547,45.163269300471576 5.508157769366574,45.163850342151378 5.508790876733881,45.166037828080889 5.509806786947887,45.1684392178013 5.511570088791844,45.171513848793282 5.513801466466343,45.17539050162415 5.516535689990693,45.179734146853228 5.518638050551481,45.181978547224986 5.521184372654164,45.184966918788639 5.524699007997207,45.18933150609115 5.527267099507565,45.193264289042801 5.527552392296414,45.19379655621016 5.52798211441999,45.194760677516605 5.529131584243736,45.196902161978144 5.532065216609396,45.204074259159512 5.533315792715549,45.209305256325443 5.534246960643453,45.213644414855466 5.535652150394507,45.218902528006922 5.538852924686776,45.227250430001639 5.544802951534512,45.235190644397115 5.544935664193075,45.235276809833536 5.545374693549105,45.235174015847569 5.552065741575315,45.236835774382897 5.566478805561787,45.238372275208668 5.568866403881952,45.238356141784003 5.570284267242009,45.238630740324432 5.571836941242355,45.239035551975405 5.57462433441365,45.2402209101907 5.577077302110182,45.242583293815095 5.577223028135769,45.242894349342798</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#COMMUNE">
<SimpleData name="ID_GEOFLA">COMMUNE00000000000000005</SimpleData>
<SimpleData name="CODE_COM">890</SimpleData>
<SimpleData name="INSEE_COM">62890</SimpleData>
<SimpleData name="NOM_COM">WILLEMAN</SimpleData>
<SimpleData name="STATUT">Commune simple</SimpleData>
<SimpleData name="X_CHF_LIEU">640049</SimpleData>
<SimpleData name="Y_CHF_LIEU">7028672</SimpleData>
<SimpleData name="X_CENTROID">640115</SimpleData>
<SimpleData name="Y_CENTROID">7029900</SimpleData>
<SimpleData name="Z_MOYEN">79</SimpleData>
<SimpleData name="SUPERFICIE">1023</SimpleData>
<SimpleData name="POPULATION">178</SimpleData>
<SimpleData name="CODE_ARR">4</SimpleData>
<SimpleData name="CODE_DEPT">62</SimpleData>
<SimpleData name="NOM_DEPT">PAS-DE-CALAIS</SimpleData>
<SimpleData name="CODE_REG">32</SimpleData>
<SimpleData name="NOM_REG">NORD-PAS-DE-CALAIS-PICARDIE</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>2.151357610477108,50.342723579428736 2.150582398840049,50.343853128809613 2.150439420398362,50.344345961981944 2.147781898036236,50.348429901247719 2.144643960903647,50.352848920107654 2.142170362713468,50.354312287967623 2.139785273502974,50.354442932204655 2.139147310728909,50.356057285129864 2.136459688875384,50.361894178627317 2.136303634967463,50.362073550534305 2.136457891197435,50.362163514907749 2.143309717417935,50.367975295072092 2.149574739686743,50.375379804640581 2.151353800635636,50.377701211726055 2.152307917736184,50.378321866071232 2.155756214194353,50.379913059929052 2.154864354931062,50.380685355552338 2.155973798477377,50.381259457705227 2.156409086307008,50.380669881870404 2.157182705972685,50.37999822017963 2.158308050333875,50.379282265278022 2.159644626590358,50.378610832073001 2.166473449179359,50.37565036238319 2.167106098271396,50.375426588179472 2.167893230445291,50.375114070985006 2.168055448620143,50.374896996422471 2.168526372902896,50.37426272358401 2.169092409895663,50.373051795846251 2.169942448266939,50.370531964916502 2.170719245301723,50.368962416427962 2.175080979569476,50.369372312649269 2.183859825720376,50.370773789773402 2.18505079929214,50.370999825609218 2.185191902200479,50.370954968509238 2.18564361921614,50.370190318886401 2.184787545948869,50.370002412843633 2.183708661363136,50.369617304240514 2.182463727449356,50.36830454074083 2.181402963860765,50.366544971983508 2.182476664280656,50.364123484539761 2.185726357443533,50.356526912933504 2.186427269755563,50.356662618447764 2.186638577991434,50.356438655774838 2.187202454197396,50.355496954539362 2.188401939261542,50.353075312390636 2.186319206527587,50.348124388463035 2.184784410495321,50.343586432428438 2.184713679145266,50.343361503403536 2.18317169343704,50.343538954992638 2.166941973276032,50.344953195994378 2.152128396725606,50.342859066974349 2.151357610477108,50.342723579428736</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
</Folder>
</Document></kml>
到目前为止我尝试的是提取与属性ID_GEOFLA
匹配的节点值;但这没有用:
CREATE OR REPLACE PROCEDURE load_xml (p_dir IN VARCHAR2,
p_filename IN VARCHAR2) AS
l_bfile BFILE := BFILENAME(p_dir, p_filename);
l_clob CLOB;
xml_data xmltype;
ID_GEOFLA varchar2(255);
BEGIN
DBMS_LOB.createtemporary (l_clob, TRUE);
DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
DBMS_LOB.loadfromfile(l_clob, l_bfile, DBMS_LOB.getlength(l_bfile));
DBMS_LOB.fileclose(l_bfile);
xml_data :=XMLTYPE.createXML(l_clob);
for x in (
select a.ID
from
XMLTABLE('/Document/Folder/Placemark/ExtendedData/SchemaData'
PASSING xml_data
COLUMNS ID VARCHAR2(100) PATH '//SimpleData/text()'
) a) loop
dbms_output.put_line(x.ID);
end loop;
DBMS_LOB.freetemporary (l_clob);
END;
/
如何将XML数据存入我的表格?
答案 0 :(得分:1)
你有多个地标需要XMLTable XPath来引用它们;然后是列路径来引用每个节点,指定相关的属性:
xmltable(xmlnamespaces(default 'http://www.opengis.net/kml/2.2'),
'/kml/Document/Folder/Placemark'
passing xmltype(l_clob)
columns ide_geo varchar2(24) path 'ExtendedData/SchemaData/SimpleData[@name="ID_GEOFLA"]',
cod_com varchar2(3) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_COM"]',
cod_vil varchar2(5) path 'ExtendedData/SchemaData/SimpleData[@name="INSEE_COM"]',
nom_com varchar2(50) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_COM"]',
alt_moy number(4,0) path 'ExtendedData/SchemaData/SimpleData[@name="Z_MOYEN"]',
sup_hec number(12,0) path 'ExtendedData/SchemaData/SimpleData[@name="SUPERFICIE"]',
nbr_pop number(10,0) path 'ExtendedData/SchemaData/SimpleData[@name="POPULATION"]',
cod_arr varchar2(1) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_ARR"]',
cod_dep varchar2(2) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_DEPT"]',
nom_dep varchar2(30) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_DEPT"]',
cod_reg varchar2(2) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_REG"]',
nom_reg varchar2(35) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_REG"]',
txt_pol clob path 'Polygon/outerBoundaryIs/LinearRing/coordinates'
);
还要注意包含/kml
根节点和默认命名空间的声明。
调整您的过程以使用从BFILE加载的CLOB,并使用单个insert ... select
(不需要游标循环),您可以执行以下操作:
create or replace procedure load_xml (p_dir in varchar2,
p_filename in varchar2)
as
l_clob clob;
l_bfile bfile := bfilename(p_dir, p_filename);
l_dest_offset pls_integer := 1;
l_src_offset pls_integer := 1;
l_lang_context pls_integer := 0;
l_warning pls_integer;
begin
dbms_lob.createtemporary (l_clob, true);
dbms_lob.fileopen(l_bfile, dbms_lob.file_readonly);
dbms_lob.loadclobfromfile(dest_lob=>l_clob,
src_bfile=>l_bfile,
amount=>dbms_lob.lobmaxsize,
dest_offset=>l_dest_offset,
src_offset=>l_src_offset,
bfile_csid=>0,
lang_context=>l_lang_context,
warning=>l_warning);
dbms_lob.fileclose(l_bfile);
insert into lie_geof (ide_geo, cod_com, cod_vil, nom_com, alt_moy, sup_hec,
nbr_pop, cod_arr, cod_dep, nom_dep, cod_reg, nom_reg, txt_pol)
select ide_geo, cod_com, cod_vil, nom_com, alt_moy, sup_hec,
nbr_pop, cod_arr, cod_dep, nom_dep, cod_reg, nom_reg, txt_pol
from xmltable(xmlnamespaces(default 'http://www.opengis.net/kml/2.2'),
'/kml/Document/Folder/Placemark'
passing xmltype(l_clob)
columns ide_geo varchar2(24) path 'ExtendedData/SchemaData/SimpleData[@name="ID_GEOFLA"]',
cod_com varchar2(3) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_COM"]',
cod_vil varchar2(5) path 'ExtendedData/SchemaData/SimpleData[@name="INSEE_COM"]',
nom_com varchar2(50) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_COM"]',
alt_moy number(4,0) path 'ExtendedData/SchemaData/SimpleData[@name="Z_MOYEN"]',
sup_hec number(12,0) path 'ExtendedData/SchemaData/SimpleData[@name="SUPERFICIE"]',
nbr_pop number(10,0) path 'ExtendedData/SchemaData/SimpleData[@name="POPULATION"]',
cod_arr varchar2(1) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_ARR"]',
cod_dep varchar2(2) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_DEPT"]',
nom_dep varchar2(30) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_DEPT"]',
cod_reg varchar2(2) path 'ExtendedData/SchemaData/SimpleData[@name="CODE_REG"]',
nom_reg varchar2(35) path 'ExtendedData/SchemaData/SimpleData[@name="NOM_REG"]',
txt_pol clob path 'Polygon/outerBoundaryIs/LinearRing/coordinates'
);
dbms_lob.freetemporary (l_clob);
end;
/
...当你的文件运行时,获取:
select * from lie_geof;
IDE_GEO COD COD_V NOM_COM ALT_MOY SUP_HEC NBR_POP C CO NOM_DEP CO NOM_REG TXT_POL
------------------------ --- ----- -------------------------------------------------- ---------- ---------- ---------- - -- ------------------------------ -- ----------------------------------- --------------------------------------------------------------------------------
COMMUNE00000000000000001 216 32216 LOURTIES-MONBRUN 252 966 139 3 32 GERS 76 LANGUEDOC-ROUSSILLON-MIDI-PYRENEES 0.523147623541907,43.45799199978569 0.523016926446493,43.458214941462735 0.52281
COMMUNE00000000000000002 033 47033 BOUDY-DE-BEAUREGARD 112 1019 414 3 47 LOT-ET-GARONNE 75 AQUITAINE-LIMOUSIN-POITOU-CHARENTES 0.662777282430262,44.533218568792947 0.662625822063777,44.533683684987352 0.6641
COMMUNE00000000000000003 009 32009 ARMOUS-ET-CAU 221 932 95 3 32 GERS 76 LANGUEDOC-ROUSSILLON-MIDI-PYRENEES 0.211253773793326,43.587275605450763 0.211662108609333,43.586825129365288 0.2114
COMMUNE00000000000000004 225 38225 AUTRANS-MEAUDRE EN VERCORS 1234 3371 2973 1 38 ISERE 84 AUVERGNE-RHONE-ALPES 5.577223028135769,45.242894349342798 5.57832596943672,45.243222059527241 5.57940
COMMUNE00000000000000005 890 62890 WILLEMAN 79 1023 178 4 62 PAS-DE-CALAIS 32 NORD-PAS-DE-CALAIS-PICARDIE 2.151357610477108,50.342723579428736 2.150582398840049,50.343853128809613 2.1504