代码之家  ›  专栏  ›  技术社区  ›  saipanman

XML字符串作为clob传递给oracle存储过程

  •  0
  • saipanman  · 技术社区  · 12 年前

    基本上,我试图将一个xml字符串传递给一个存储过程。

    我第一次尝试使用以下方法读取和解析XML,效果很好:

    select * FROM xmltable('//list//model.ProfilingSync'
        passing xmlType.createxml('<list>
            <model.ProfilingSync>
                <screDocId>106</screDocId>
                <evalStatCd>B</evalStatCd>
                <evalChgDt>2014-2-13 9:41:49. 260034000</evalChgDt>
                <ssn>000001060</ssn>
                <evalRptIndivCd>A</evalRptIndivCd>
                <rankAb>WO1</rankAb>
                <indTypCd>A</indTypCd>
                <civPayPlanCd>AB</civPayPlanCd>
                <performanceTypCd/>
                <performanceCd/>
                <redactPerfCd/>
                <civPayGrLvlNr>AB</civPayGrLvlNr>
            </model.ProfilingSync>
            <model.ProfilingSync>
                <screDocId>106</screDocId>
                <evalStatCd>B</evalStatCd>
                <evalChgDt>2014-2-13 9:41:49. 260034000</evalChgDt>
                <ssn>724629831</ssn>
                <evalRptIndivCd>B</evalRptIndivCd>
                <rankAb/>
                <indTypCd>A</indTypCd>
                <civPayPlanCd>ES</civPayPlanCd>
                <performanceTypCd>100</performanceTypCd>
                <performanceCd>1000</performanceCd>
                <redactPerfCd>1000</redactPerfCd>
                <civPayGrLvlNr>6</civPayGrLvlNr>
            </model.ProfilingSync>
            <model.ProfilingSync>
                <screDocId>106</screDocId>
                <evalStatCd>B</evalStatCd>
                <evalChgDt>2014-2-13 9:41:49. 260034000</evalChgDt>
                <ssn>001623791</ssn>
                <evalRptIndivCd>D</evalRptIndivCd>
                <rankAb>GEN</rankAb>
                <indTypCd>A</indTypCd>
                <civPayPlanCd>AB</civPayPlanCd>
                <performanceTypCd>130</performanceTypCd>
                <performanceCd>1160</performanceCd>
                <redactPerfCd/>
                <civPayGrLvlNr>AB</civPayGrLvlNr>
            </model.ProfilingSync>
        </list>') 
        columns SRC_DOC_ID NUMBER path '//screDocId',
                EVAL_STAT_CD varchar(4) path '//evalStatCd',
                EVAL_CHG_DT VARCHAR(200) path '//evalChgDt',
                SSN VARCHAR(9) path '//ssn',
                EVAL_RPT_INDIV_CD VARCHAR(4) path '//evalRptIndivCd',
                RANK_AB VARCHAR(4) path '//rankAb',
                PERFORMANCE_TYP_CD NUMBER path '//performanceTypCd',
                PERFORMANCE_CD NUMBER path '//performanceCd',
                REDACT_PERF_CD VARCHAR(4) path '//redactPerfCd',
                IND_TYP_CD VARCHAR(4) path '//indTypCd',
                CIV_PAY_PLAN_CD VARCHAR(4) path '//civPayPlanCd',
                CIV_PAY_GR_LVL_NR VARCHAR(4) path '//civPayGrLvlNr') my_profiling_xml_table;
    

    下面根据上面的示例提供的存储过程也可以很好地编译:

    create or replace PROCEDURE CU_SEPS_PROFILING_IMPORT ( P_XML_STRING IN CLOB
    , P_RECORDSET OUT SYS_REFCURSOR
    ) /* Returns a list of evals with person info that have been completed from today back to the submitted date. VAR RC REFCURSOR; EXECUTE CU_SEPS_PROFILING_IMPORT ('P_XML_STRING',P_RECORDSET => :RC) print :rc; */
    AS BEGIN OPEN P_RECORDSET FOR
    SELECT * FROM xmltable('//list//model.ProfilingSync' passing XMLTYPE(P_XML_STRING) columns SRC_DOC_ID xmltype path '//screDocId', EVAL_STAT_CD xmltype path '//evalStatCd', EVAL_CHG_DT xmltype path '//evalChgDt', SSN xmltype path '//ssn', EVAL_RPT_INDIV_CD xmltype path '//evalRptIndivCd', RANK_AB xmltype path '//rankAb', PERFORMANCE_TYP_CD xmltype path '//performanceTypCd', PERFORMANCE_CD xmltype path '//performanceCd', REDACT_PERF_CD xmltype path '//redactPerfCd', IND_TYP_CD xmltype path '//indTypCd', CIV_PAY_PLAN_CD xmltype path '//civPayPlanCd', CIV_PAY_GR_LVL_NR xmltype path '//civPayGrLvlNr') my_profiling_xml_table; END CU_SEPS_PROFILING_IMPORT;

    然而,当我尝试测试程序时,问题就开始了,我希望有人能发现我的错误。

    VAR RC REFCURSOR;
    EXECUTE CU_SEPS_PROFILING_IMPORT ('<list>
    <model.ProfilingSync>
        <screDocId>106</screDocId>
        <evalStatCd>B</evalStatCd>
        <evalChgDt>204-2-13 9:41:49. 260034000</evalChgDt>
        <ssn>000001060</ssn>
        <evalRptIndivCd>A</evalRptIndivCd>
        <rankAb>WO1</rankAb>
        <indTypCd>A</indTypCd>
        <civPayPlanCd>AB</civPayPlanCd>
        <performanceTypCd/>
        <performanceCd/>
        <redactPerfCd/>
        <civPayGrLvlNr>AB</civPayGrLvlNr>
    </model.ProfilingSync>
    <model.ProfilingSync>
        <screDocId>106</screDocId>
        <evalStatCd>B</evalStatCd>
        <evalChgDt>2014-2-13 9:41:49. 260034000</evalChgDt>
        <ssn>724629831</ssn>
        <evalRptIndivCd>B</evalRptIndivCd>
        <rankAb/>
        <indTypCd>A</indTypCd>
        <civPayPlanCd>ES</civPayPlanCd>
        <performanceTypCd>100</performanceTypCd>
        <performanceCd>1000</performanceCd>
        <redactPerfCd>1000</redactPerfCd>
        <civPayGrLvlNr>6</civPayGrLvlNr>
    </model.ProfilingSync>
    <model.ProfilingSync>
        <screDocId>106</screDocId>
        <evalStatCd>B</evalStatCd>
        <evalChgDt>2014-2-13 9:41:49. 260034000</evalChgDt>
        <ssn>001623791</ssn>
        <evalRptIndivCd>D</evalRptIndivCd>
        <rankAb>GEN</rankAb>
        <indTypCd>A</indTypCd>
        <civPayPlanCd>AB</civPayPlanCd>
        <performanceTypCd>130</performanceTypCd>
        <performanceCd>1160</performanceCd>
        <redactPerfCd/>
        <civPayGrLvlNr>AB</civPayGrLvlNr>
    </model.ProfilingSync>
    </list>', p_recordset => :RC);
    print :rc;
    

    此时,我得到以下错误:

    Error starting at line 3 in command:
    EXECUTE CU_SEPS_PROFILING_IMPORT ('<list>
    Error report:
    ORA-06550: line 1, column 33:
    PLS-00103: Encountered the symbol "<list>; END;" when expecting one of the following:
    
       ( ) - + case mod new not null <an identifier>
       <a double-quoted delimited-identifier> <a bind variable>
       table continue avg count current exists max min prior sql
       stddev sum variance execute multiset the both leading
       trailing forall merge year month day hour minute second
       timezone_hour timezone_minute timezone_region timezone_abbr
       time timestamp interval date
       <a string literal with character set spe
     06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    

    提前感谢您的帮助!

    1 回复  |  直到 12 年前
        1
  •  1
  •   user272735    12 年前

    EXECUTE 是一个SQL*Plus命令,需要在单行中。问题不在于空格,而在于换行符。