我想为表后面的列聚合多个 XMLELEMENT 并返回一个 xml 文件。
我想返回以下格式的 xml:
<employee>
<id>FMCSC00015</id>
<year>2016</year>
<month>1</month>
<head_name>BASIC PAY</head_name>
<amount>35600</amount>
<head_name>BANK LOAN-4</head_name>
<amount>23490</amount>
<head_name>RESEARCH ALLOWANCE</head_name>
<amount>1500</amount>
<head_name>MOTOR GARAGE</head_name>
<amount>500.5</amount>
<head_name>CLUB</head_name>
<amount>207</amount>
.........so on
<employee>
但是我在汇总 2 列 [head_name 和 amount] 时遇到了困难。这是我的甲骨文代码:
select xmlElement( "employee",
xmlelement("id", e.PAYMSTR_EMPID),
xmlelement("year", e.PAYMSTR_SALYR),
xmlelement("month", e.PAYMSTR_SALMT),
XMLAGG(
XMLELEMENT(" ",
XMLELEMENT("head_name", e.PAYMSTR_SALHDNM ),
XMLELEMENT("amount", e.PAYMSTR_AMOUNT ) )
)
) as result
from TBL_PAYROLL_MASTER_FILE e
where e.PAYMSTR_EMPID = 'FMCSC00015'
group by e.PAYMSTR_EMPID,e.PAYMSTR_SALYR, e.PAYMSTR_SALMT;
正如你所看到的,因为我在 XMLAGG 的第一个 XMLELEMENT 中使用了空格,它仍然会创建具有以下输出 xml 的空标签:
<employee>
<id>FMCSC00015</id>
<year>2016</year>
<month>1</month>
<>
<head_name>BASIC PAY</head_name>
<amount>35600</amount>
</>
<>
<head_name>BANK LOAN-4</head_name>
<amount>23490</amount>
</>
<>
<head_name>RESEARCH ALLOWANCE</head_name>
<amount>1500</amount>
</>
<>
<head_name>MOTOR GARAGE</head_name>
<amount>500.5</amount>
</>
<>
<head_name>CLUB</head_name>
<amount>207</amount>
.........so on
<employee>
我怎样才能避免这些额外的空标签并获得我适当的 xml 格式。谢谢