xml与oralce的导入导出
2009-03-09 17:56
357 查看
直接在sql中运行:
insert:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- get all the sales employees into an xml document
7 select xmlelement("ROWSET",
8 xmlagg(
9 xmlelement("ROW",
10 xmlforest(e.empno,e.ename,e.job,e.mgr,
11 e.hiredate,e.sal,e.comm,e.deptno)
12 )
13 )
14 )
15 into l_sales_emp
16 from emp e, dept d
17 where d.deptno = e.deptno
18 and d.dname='SALES';
19
20 -- setup our dbms_xmlstore context
21 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
22 l_rows := dbms_xmlstore.insertxml(
23 L_ctx, l_sales_emp.getClobVal());
24
25 -- how many rows were inserted?
26 dbms_output.put_line(l_rows || ' rows inserted into SALES_EMP.');
27
28 -- clean up
29 dbms_xmlstore.closecontext(l_ctx);
30 end;
update:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- simulate the updates to make
7 l_sales_emp := xmltype('<?xml version="1.0"?>
8 <ROWSET>
9 <ROW>
10 <EMPNO>7499</EMPNO><ENAME>ALLEN</ENAME><JOB>MANAGER</JOB>
<MGR>7698</MGR><SAL>2600</SAL>
11 </ROW>
12 <ROW>
13 <EMPNO>7521</EMPNO><ENAME>WARD</ENAME><JOB>MANAGER</JOB>
<MGR>7698</MGR><SAL>2250</SAL>
14 </ROW>
15 </ROWSET>');
16
17 -- setup our dbms_xmlstore context
18 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
19
20 -- setup the columns to be updated
21 dbms_xmlstore.clearupdatecolumnlist(l_ctx);
22 dbms_xmlstore.setupdatecolumn(l_ctx, 'ENAME');
23 dbms_xmlstore.setupdatecolumn(l_ctx, 'JOB');
24 dbms_xmlstore.setupdatecolumn(l_ctx, 'MGR');
25 dbms_xmlstore.setupdatecolumn(l_ctx, 'SAL');
26
27 -- setup the key columns to update by
28 dbms_xmlstore.setkeycolumn(l_ctx, 'EMPNO');
29
30 -- perform the update
31 l_rows := dbms_xmlstore.updatexml(l_ctx, l_sales_emp.getClobVal());
32
33 -- how many rows were updated?
34 dbms_output.put_line(l_rows || ' rows updated in SALES_EMP.');
35
36 -- clean up
37 dbms_xmlstore.closecontext(l_ctx);
38 end;
delete:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- simulate the updates to make
7 l_sales_emp := xmltype('<?xml version="1.0"?>
8 <ROWSET>
9 <ROW>
10 <EMPNO>7499</EMPNO>
11 </ROW>
12 <ROW>
13 <EMPNO>7698</EMPNO>
14 </ROW>
15 </ROWSET>');
16
17 -- setup our dbms_xmlstore context
18 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
19
20 -- setup the key column to delete by
21 dbms_xmlstore.setkeycolumn(l_ctx, 'EMPNO');
22
23 -- perform the delete
24 l_rows := dbms_xmlstore.deletexml(l_ctx, l_sales_emp.getClobVal());
25
26 -- how many rows were deleted?
27 dbms_output.put_line(l_rows || ' rows deleted fm SALES_EMP.');
28
29 -- clean up
30 dbms_xmlstore.closecontext(l_ctx);
31 end;
生成xml文件
SELECT xmlgen.getXml(
'SELECT empno "EMP_NO"
, ename "NAME"
, deptno "DEPT_NO"
FROM emp
WHERE deptno = 10'
, 0
) FROM dual;
insert:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- get all the sales employees into an xml document
7 select xmlelement("ROWSET",
8 xmlagg(
9 xmlelement("ROW",
10 xmlforest(e.empno,e.ename,e.job,e.mgr,
11 e.hiredate,e.sal,e.comm,e.deptno)
12 )
13 )
14 )
15 into l_sales_emp
16 from emp e, dept d
17 where d.deptno = e.deptno
18 and d.dname='SALES';
19
20 -- setup our dbms_xmlstore context
21 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
22 l_rows := dbms_xmlstore.insertxml(
23 L_ctx, l_sales_emp.getClobVal());
24
25 -- how many rows were inserted?
26 dbms_output.put_line(l_rows || ' rows inserted into SALES_EMP.');
27
28 -- clean up
29 dbms_xmlstore.closecontext(l_ctx);
30 end;
update:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- simulate the updates to make
7 l_sales_emp := xmltype('<?xml version="1.0"?>
8 <ROWSET>
9 <ROW>
10 <EMPNO>7499</EMPNO><ENAME>ALLEN</ENAME><JOB>MANAGER</JOB>
<MGR>7698</MGR><SAL>2600</SAL>
11 </ROW>
12 <ROW>
13 <EMPNO>7521</EMPNO><ENAME>WARD</ENAME><JOB>MANAGER</JOB>
<MGR>7698</MGR><SAL>2250</SAL>
14 </ROW>
15 </ROWSET>');
16
17 -- setup our dbms_xmlstore context
18 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
19
20 -- setup the columns to be updated
21 dbms_xmlstore.clearupdatecolumnlist(l_ctx);
22 dbms_xmlstore.setupdatecolumn(l_ctx, 'ENAME');
23 dbms_xmlstore.setupdatecolumn(l_ctx, 'JOB');
24 dbms_xmlstore.setupdatecolumn(l_ctx, 'MGR');
25 dbms_xmlstore.setupdatecolumn(l_ctx, 'SAL');
26
27 -- setup the key columns to update by
28 dbms_xmlstore.setkeycolumn(l_ctx, 'EMPNO');
29
30 -- perform the update
31 l_rows := dbms_xmlstore.updatexml(l_ctx, l_sales_emp.getClobVal());
32
33 -- how many rows were updated?
34 dbms_output.put_line(l_rows || ' rows updated in SALES_EMP.');
35
36 -- clean up
37 dbms_xmlstore.closecontext(l_ctx);
38 end;
delete:
declare
2 l_sales_emp xmltype;
3 l_ctx dbms_xmlstore.ctxtype;
4 l_rows pls_integer;
5 begin
6 -- simulate the updates to make
7 l_sales_emp := xmltype('<?xml version="1.0"?>
8 <ROWSET>
9 <ROW>
10 <EMPNO>7499</EMPNO>
11 </ROW>
12 <ROW>
13 <EMPNO>7698</EMPNO>
14 </ROW>
15 </ROWSET>');
16
17 -- setup our dbms_xmlstore context
18 l_ctx := dbms_xmlstore.newcontext('SALES_EMP');
19
20 -- setup the key column to delete by
21 dbms_xmlstore.setkeycolumn(l_ctx, 'EMPNO');
22
23 -- perform the delete
24 l_rows := dbms_xmlstore.deletexml(l_ctx, l_sales_emp.getClobVal());
25
26 -- how many rows were deleted?
27 dbms_output.put_line(l_rows || ' rows deleted fm SALES_EMP.');
28
29 -- clean up
30 dbms_xmlstore.closecontext(l_ctx);
31 end;
生成xml文件
SELECT xmlgen.getXml(
'SELECT empno "EMP_NO"
, ename "NAME"
, deptno "DEPT_NO"
FROM emp
WHERE deptno = 10'
, 0
) FROM dual;
相关文章推荐
- 在Oracle表数据和xml文件间相互导入导出的PL/SQL 过程
- Oralce导入\导出
- DataGridView 的导入和导出到XML 类
- Sql 数据导出到XMl 与 从XML导入到数据库
- SQL Server大容量导入和导出 XML 文档的示例
- ASP.NET环境下XML导出导入数据方法
- datawindow直接导入导出xml
- oracle 11g 含xmlType类型表的导入导出
- VC++ 下使用 xml 文件导入导出数据
- oralce数据库的导入导出
- 大容量导入和导出 XML 文档的示例
- IIS6批量添加主机头 IIS6批量绑定主机头(利用IIS6导入导出XML)
- oralce imp导入报错imp-00013只有dba才能导入由其他dba导出的文件
- Oralce导入导出表数据
- XML 导入导出数据库
- Oralce 数据导出、导入
- PB中的DW导入导出XML确实好用
- 利用外部命令Oralce数据库导入导出
- 将数据导出到xml,并从xml导入数据
- Oracle 导出导入XML