declare
v_clob clob;
v_varchar VARCHAR2(32767);
x xmltype;
l number;
begin
v_varchar := '
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7368</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7379</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7309</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7319</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7329</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7499</empno>
<ename>ALLEN</ename>
<job>SALESMAN</job>
<hiredate>20-FEB-1981</hiredate>
</employee>
';
l:=LENGTH(v_varchar);
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
DBMS_LOB.WRITEAPPEND(v_clob,length('<employees>'),'<employees>');
For i in 1..30 loop
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
end loop;
DBMS_LOB.WRITEAPPEND(v_clob,length('</employees>'),'</employees>');
dbms_output.put_line(DBMS_LOB.GETLENGTH(v_clob));
x := xmltype.createxml(v_clob);
FOR cur_rec IN (
SELECT xt.*
FROM XMLTABLE('/employees/employee'
PASSING x
COLUMNS
empno VARCHAR2(4) PATH 'empno',
ename VARCHAR2(10) PATH 'ename',
job VARCHAR2(9) PATH 'job',
hiredate VARCHAR2(11) PATH 'hiredate'
) xt)
LOOP
DBMS_OUTPUT.put_line('empno=' || cur_rec.empno ||
' ename=' || cur_rec.ename ||
' job=' || cur_rec.job||
' hiredate=' || cur_rec.hiredate);
END LOOP;
end ;
v_clob clob;
v_varchar VARCHAR2(32767);
x xmltype;
l number;
begin
v_varchar := '
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7369</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7368</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7379</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7309</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7319</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7329</empno>
<ename>SMITH</ename>
<job>CLERK</job>
<hiredate>17-DEC-1980</hiredate>
</employee>
<employee>
<empno>7499</empno>
<ename>ALLEN</ename>
<job>SALESMAN</job>
<hiredate>20-FEB-1981</hiredate>
</employee>
';
l:=LENGTH(v_varchar);
DBMS_LOB.CREATETEMPORARY(v_clob, TRUE);
DBMS_LOB.WRITEAPPEND(v_clob,length('<employees>'),'<employees>');
For i in 1..30 loop
DBMS_LOB.WRITEAPPEND(v_clob, LENGTH(v_varchar), v_varchar);
end loop;
DBMS_LOB.WRITEAPPEND(v_clob,length('</employees>'),'</employees>');
dbms_output.put_line(DBMS_LOB.GETLENGTH(v_clob));
x := xmltype.createxml(v_clob);
FOR cur_rec IN (
SELECT xt.*
FROM XMLTABLE('/employees/employee'
PASSING x
COLUMNS
empno VARCHAR2(4) PATH 'empno',
ename VARCHAR2(10) PATH 'ename',
job VARCHAR2(9) PATH 'job',
hiredate VARCHAR2(11) PATH 'hiredate'
) xt)
LOOP
DBMS_OUTPUT.put_line('empno=' || cur_rec.empno ||
' ename=' || cur_rec.ename ||
' job=' || cur_rec.job||
' hiredate=' || cur_rec.hiredate);
END LOOP;
end ;
No comments:
Post a Comment