dbms_xmlgen.getxml在Oracle

时间:2019-04-17 13:48:46

标签: xml oracle plsql dbms-xmlgen

当我分别在SQL查询中运行dbms_xmlgen.getxml函数时,它为我提供xml输出,但是当我在过程中运行时,它为我提供了空输出。
您能告诉我错误在哪里吗?

下面是我不使用PL / SQL单独运行的代码

select dbmX_xmlgen.getxml('select 
wmgs.SRC_NUM,
SRC_ID,
HS.X_START_DATE,
pd_INT_ID,
pd.X_R_RATE_KEY,
COND.DESC_TEXT,
pd.NAME,
Relatedpd.NAME ,
Relatedpd.PART_NUM,
pd.EFF_START_DATE,
pd.TYPE,
PAY.NAME ,
PAY.TYPE
from 
alpha.X_SRC wmgs,
alpha.X_pd_INT_SRC HS,
alpha.X_pd_INT pd,
alpha.X_CONDITION COND,
alpha.X_pd_INT Relatedpd,
alpha.X_pd_INT_XM Pay
where
wmgs.ROW_ID = HS.SRC_ID (+)
AND HS.pd_INT_ID = pd.ROW_ID (+)
AND HS.AMT_CURCY_CD = COND.ROW_ID (+)
AND pd.X_REL_pd_ID = Relatedpd.CFG_MODEL_ID (+)
AND pd.ROW_ID=PAY.PAR_ROW_ID (+)
AND wmgs.SRC_NUM=''CAQZ''
AND (HS.X_START_DATE >= to_date(''01/01/2000'',''dd/mm/yyyy'') OR pd.EFF_START_DATE >= to_date(''01/01/2010'',''dd/mm/yyyy'')) 
AND (HS.AMT_DATE <= to_date(''01/01/2099'',''dd/mm/yyyy'') OR pd.EFF_END_DATE<= to_date(''01/01/2099'',''dd/mm/yyyy''))
')xml from dual;

下面是我在过程中运行的代码

create or replace procedure alpha.test1(p_start_date IN DATE, p_end_date IN DATE, p_src_num IN VARCHAR2, p_xml_out OUT CLOB) 

IS
v_xml CLOB;
ctx dbms_xmlgen.ctxhandle;


BEGIN

ctx := dbms_xmlgen.newcontext
('select 
wmgs.SRC_NUM,
SRC_ID,
HS.X_START_DATE,
pd_INT_ID,
pd.X_R_RATE_KEY,
COND.DESC_TEXT,
pd.NAME,
Relatedpd.NAME ,
Relatedpd.PART_NUM,
pd.EFF_START_DATE,
pd.TYPE,
PAY.NAME ,
PAY.TYPE
from 
alpha.X_SRC wmgs,
alpha.X_pd_INT_SRC HS,
alpha.X_pd_INT pd,
alpha.X_CONDITION COND,
alpha.X_pd_INT Relatedpd,
alpha.X_pd_INT_XM Pay
where
wmgs.ROW_ID = HS.SRC_ID (+)
AND HS.pd_INT_ID = pd.ROW_ID (+)
AND HS.AMT_CURCY_CD = COND.ROW_ID (+)
AND pd.X_REL_pd_ID = Relatedpd.CFG_MODEL_ID (+)
AND pd.ROW_ID=PAY.PAR_ROW_ID (+)
AND wmgs.SRC_NUM='''|| p_src_num ||'''
AND (HS.X_START_DATE >= to_date('''||p_start_date||''',''dd/mm/yyyy'') OR PROD.EFF_START_DT >= to_date('''||p_start_date||''',''dd/mm/yyyy'')) 
AND (HS.AMT_DATE <= to_date('''||p_end_date||''',''dd/mm/yyyy'') OR PROD.EFF_END_DT<= to_date('''||p_end_date||''',''dd/mm/yyyy''))
');

dbms_xmlgen.SETNULLHANDLING (ctx, 2);

v_xml := dbms_xmlgen.getxml(ctx);

p_xml_out := v_xml;

END;
/

1 个答案:

答案 0 :(得分:0)

我不确定这是否是您要寻找的,但是您可以使用pl sql的内部xml函数

然后看起来像这样:

    DECLARE
    vxml   CLOB;
BEGIN
SELECT XMLELEMENT ( "ROOT",
                          xmlagg ( xmlelement( "data",
                                                XMLELEMENT(
                                                    "SRC_NUM", wmgs.src_num
                                                ) , XMLELEMENT(
                                                    "SRC_ID", SRC_ID
                                                ), XMLELEMENT(
                                                    "X_START_DATE", HS.X_START_DATE
                                                ), XMLELEMENT(
                                                    "pd_INT_ID", pd.pd_INT_ID
                                                ), XMLELEMENT(
                                                    "X_R_RATE_KEY", pd.X_R_RATE_KEY
                                                )
 )))
into vxml
from alpha.x_src wmgs,
alpha.x_pd_int_src hs,
alpha.x_pd_int pd,
alpha.x_condition cond,
alpha.x_pd_int relatedpd,
alpha.x_pd_int_xm pay; 

END;