å¨oracleä¸æä¾äºè®¸å¤å
ç½®çç¨åºå
ï¼å®ä»¬ç¨äºæ©å±æ°æ®åºçåè½ãå¨å¼ååºç¨ç¨åºæ¶ï¼å¯ä»¥å©ç¨è¿äºç¨åºå
ãæ°æ®åºç¨æ·sysæ¥æoracleæä¾çææç¨åºå
ãä»ä»¬è¢«å®ä¹ä¸ºå
±æåä¹è¯ï¼å¹¶å°æ§è¡æéæäºäºpublicç¨æ·ç»ï¼ä»»ä½ç¨æ·é½å¯ä»¥è®¿é®å®ä»¬ãå
¶ä¸DBMS_XMLQUERYå
ç¨äºå°æ¥è¯¢ç»æ转æ¢ä¸ºXMLæ ¼å¼ï¼DBMS_LOBç¨åºå
å
å«é¨å¤ç大å对象çè¿ç¨åå½æ°ãä¸é¢æ们çä¸ä¸DBMS_XMLQUERYåDBMS_LOBçç¨æ³ï¼
SQL> DECLARE
result CLOB;
xmlstr VARCHAR2(32767);
line VARCHAR2(2000);
line_no INTEGER :=1;
BEGIN
result :=DBMS_XMLQUERY.getXml('select empno,empname from employee');
xmlstr :=DBMS_LOB.SUBSTR(result,32767);
LOOP
EXIT WHEN xmlstr IS NULL;
line :=SUBSTR(xmlstr,1,INSTR(xmlstr,CHR(10)-1));
DBMS_OUTPUT.PUT_LINE(line_no || ':' || line);
xmlstr :=SUBSTR(xmlstr,INSTR(xmlstr,CHR(10)+1));
line_no :=line_no + 1;
END LOOP;
END;
å¨ä¸é¢çä¾åä¸æ们声æäºä¸ä¸ªCLOBæ°æ®ç±»åçresultåéï¼ä»¥åVARCHAR2ç±»åçxmlstråline两个åéãå
¶ä¸ï¼getXmlå½æ°ç¨äºå°æ¥è¯¢ç»æ转æ¢ä¸ºXMLæ ¼å¼ï¼SUBSTRå½æ°æ£ç´¢åå符串ï¼32767å¼æå®è¦ä»CLOBæ°æ®ç±»å读åçæ大åèæ°ãæ£ç´¢å°çå符串åå¨xmlstråéä¸ãLOOPå循ç¯æ§è¡ï¼æ¯æ¬¡ä»xmlsträ¸è¯»åä¸è¡ãINSTRå½æ°è¿åä¸ä¸ªå符串å¨å¦ä¸ä¸ªå符串é¦æ¬¡åºç°çä½ç½®ãå¨æ¤ï¼è¯¥å½æ°è¿åæ¢è¡ç¬¦å¨å符串ä¸çä½ç½®ï¼ç´å°éå°ä¸ä¸è¡ã
大家è§å¾ä¾åçç»æè½ä¸è½è¯»åºæ们é¢æçç»æå¢ï¼è¯è¯å°±ç¥éäºï¼ï¼ï¼
ç»æå¦ä¸ï¼
< ?xml version='1.0'?>
< ROWSET>
< ROW num="1">
< EMPNO>E001</EMPNO>
< EMPNAME>Jane</EMPNAME>
< /ROW>
<ROW num="2">
< EMPNO>E002</EMPNO>
< EMPNAME>John</EMPNAME>
< /ROW>
< ROW num="3">
< EMPNO>E003</EMPNO>
< EMPNAME>Joe</EMPNAME>
< /ROW>
< /ROWSET>
温馨提示:答案为网友推荐,仅供参考