szhswl
宋针还的个人空间
存储过程读取xml文件实例:
 1PROCEDURE EXECUTE_DATESERV IS
 2  BEGIN
 3    DECLARE
 4      DIR         VARCHAR2(50);
 5      SERVFILE    VARCHAR2(20);
 6      V_XP        XMLPARSER.PARSER;
 7      V_DOC       XMLDOM.DOMDOCUMENT;
 8      V_MAPPINGS  XMLDOM.DOMNODELIST;
 9      V_MAPLEN    NUMBER(3);
10      V_TABLE     XMLDOM.DOMNODELIST;
11      V_TABLELEN  NUMBER(3);
12      V_FIELD     XMLDOM.DOMNODELIST;
13      V_MAPITEM   XMLDOM.DOMNODE;
14      V_TABLEITEM XMLDOM.DOMNODE;     NNM         XMLDOM.DOMNAMEDNODEMAP;
15      V_BO        VARCHAR2(20);
16      V_VALID     VARCHAR2(20);
17      V_FIELDID   VARCHAR2(20);
18      V_BOOLEAN   NUMBER(2);
19      V_TEXT      VARCHAR2(200);
20    BEGIN
21      DIR      := '/oracle/szh';
22      SERVFILE := 'dateserv.xml';
23      V_XP     := XMLPARSER.NEWPARSER;
24      XMLPARSER.SETVALIDATIONMODE(V_XP, FALSE);
25      XMLPARSER.SETBASEDIR(V_XP, DIR);
26      XMLPARSER.PARSE(V_XP, DIR || '/' || SERVFILE);
27      V_DOC := XMLPARSER.GETDOCUMENT(V_XP);
28      XMLPARSER.FREEPARSER(V_XP);
29      V_MAPPINGS := XMLDOM.GETELEMENTSBYTAGNAME(V_DOC, 'mappings');
30      V_MAPLEN   := XMLDOM.GETLENGTH(V_MAPPINGS);
31      FOR V_I IN 0 .. V_MAPLEN - 1 LOOP
32        V_MAPITEM  := XMLDOM.ITEM(V_MAPPINGS, V_I);
33        V_TABLE    := XMLDOM.GETCHILDNODES(V_MAPITEM);
34        V_TABLELEN := XMLDOM.GETLENGTH(V_TABLE);
35        FOR V_J IN 0 .. V_TABLELEN - 1 LOOP
36          V_TABLEITEM := XMLDOM.ITEM(V_TABLE, V_J);
37          IF XMLDOM.GETNODENAME(V_TABLEITEM) = 'table' THEN
38            NNM  := XMLDOM.GETATTRIBUTES(V_TABLEITEM);
39            V_BO := XMLDOM.GETNODEVALUE(XMLDOM.ITEM(NNM, 0));
40          END IF;
41          V_FIELD   := XMLDOM.GETCHILDNODES(V_TABLEITEM);
42          V_FIELDID := XMLDOM.GETNODEVALUE(XMLDOM.GETFIRSTCHILD(XMLDOM.ITEM(V_FIELD,
43                                                                            0)));
44          V_VALID   := XMLDOM.GETNODEVALUE(XMLDOM.GETFIRSTCHILD(XMLDOM.ITEM(V_FIELD,
45                                                                            1)));
46          PRO_SZH_SEQ.UPDATE_ENDDATE(V_BO,
47                                     V_FIELDID,
48                                     V_VALID,
49                                     V_BOOLEAN,
50                                     V_TEXT);
51          IF V_BOOLEAN <> 1 THEN
52            EXECUTE_INSERT_ERROR('pk_szh_date.excute_dateserv error :' ||
53                                 V_TEXT);
54          END IF;
55        END LOOP;
56      END LOOP;
57      XMLDOM.FREEDOCUMENT(V_DOC);
58    END;
59    NULL;
60  END EXECUTE_DATESERV;
过程相应的XML文件:
 1<?xml version="1.0" encoding="ISO-8859-1"?>
 2<mappings>    
 3    <table name="enrollcon" >
 4        <field>enddate</field>
 5        <valid>valid</valid>
 6    </table>
 7    <table name="precautcon" >
 8        <field>enddate</field>
 9        <valid>valid</valid>
10    </table>
11    <table name="jrbill" >
12        <field>endtime</field>
13        <valid>validflag</valid>
14    </table>
15    <table name="jr97" >
16        <field>endtime</field>
17        <valid>validflag</valid>
18    </table>
19    <table name="mer" >
20        <field>exitdate</field>
21        <valid>valid</valid>
22    </table>
23    <table name="merabate" >
24        <field>enddate</field>
25        <valid>valid</valid>
26    </table>
27    <table name="booking" >
28        <field>obligatedate</field>
29        <valid>valid</valid>
30    </table>
31</mappings>
如果报错ORA-20100:Error occurred while parsing: No such file or directory,在服务器端首先把文件的读取权限授予运行存储过程的用户,如:
GRANT READ[,WRITE] ON DIRECTORY directory TO username;
实例:grant read, write on directory exp_dir to user;



---------------------------------------------------------------------------------------------------------------------------------
说人之短,乃护己之短。夸己之长,乃忌人之长。皆由存心不厚,识量太狭耳。能去此弊,可以进德,可以远怨。
http://www.blogjava.net/szhswl
------------------------------------------------------------------------------------------------------ ----------------- ---------
posted on 2007-12-05 11:13 宋针还 阅读(838) 评论(0)  编辑  收藏 所属分类: 存储过程

只有注册用户登录后才能发表评论。


网站导航: