2

我必须制作符合我无法控制的格式的 XML。它由一个名为 DateRange 的标头和查询中的记录组成。我可以生成几乎与格式匹配的 XML,除了我的版本在元素中包含记录,在本例中为 DIV:

select
    XMLRoot(
        XMLElement(
            "PayrollAdjustments",
                XMLForest(
                    XMLForest(
                        '2013-09-15' as "From",
                        '2013-09-21' as "To"                    
                    ) as "DateRange",
                    XMLAgg(                  
                        XMLForest(
                            XMLForest(
                                EMPLOYEE as "EmployeeId",
                                STORE AS "StoreNumber",
                                DEPARTMENT AS "Department",
                                WORKCODE AS "AdjustCode",
                                PAYROLL_DATE AS "PayDate",
                                HOURS as "Hours",
                                0 as "Amount"
                            ) AS "PayAdjustment"
                        )   
                    ) AS div
                )
            ),
            VERSION '1.0" encoding="utf-8',
            STANDALONE YES
        ).getClobVal()
from timecard_payroll
where start_date = '2013-09-15'
and end_date = '2013-09-21'
and hours > 0;

这是输出的样子,您可以看到记录位于名为 DIV 的元素中:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PayrollAdjustments>
    <DateRange>
        <From>2013-09-15</From>
        <To>2013-09-21</To>
    </DateRange>
    <DIV>
        <PayAdjustment>
            <EmployeeId>262699</EmployeeId>
            <StoreNumber>8159</StoreNumber>
            <Department>1</Department>
            <AdjustCode>91</PayAdjustCode>
            <PayDate>2013-09-16</PayDate>
            <Hours>8.0000</Hours>
            <Amount>0</Amount>
        </PayAdjustment>
        <PayAdjustment>
            <EmployeeId>262916</EmployeeId>
            <StoreNumber>8294</StoreNumber>
            <Department>5</Department>
            <AdjustCode>91</AdjustCode>
            <PayDate>2013-09-19</PayDate>
            <Hours>8.0000</Hours>
            <Amount>0</Amount>
        </PayAdjustment>
    </DIV>  
</PayrollAdjustments>

如何更改我的查询以摆脱 DIV 元素,使其看起来像这样?:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<PayrollAdjustments>
    <DateRange>
        <From>2013-09-15</From>
        <To>2013-09-21</To>
    </DateRange>        
    <PayAdjustment>
        <EmployeeId>262699</EmployeeId>
        <StoreNumber>8159</StoreNumber>
        <Department>1</Department>
        <AdjustCode>91</PayAdjustCode>
        <PayDate>2013-09-16</PayDate>
        <Hours>8.0000</Hours>
        <Amount>0</Amount>
    </PayAdjustment>
    <PayAdjustment>
        <EmployeeId>262916</EmployeeId>
        <StoreNumber>8294</StoreNumber>
        <Department>5</Department>
        <AdjustCode>91</AdjustCode>
        <PayDate>2013-09-19</PayDate>
        <Hours>8.0000</Hours>
        <Amount>0</Amount>
    </PayAdjustment>          
</PayrollAdjustments>

提前致谢

4

1 回答 1

1

尝试XMLConcat结合XMLSequenceType

select
    XMLRoot(
        XMLElement(
            "PayrollAdjustments",
                XMLForest(
                    XMLForest(
                        '2013-09-15' as "From",
                        '2013-09-21' as "To"                    
                    ) as "DateRange",
                    XMLConcat(XMLSequenceType(XMLAgg(XMLElement("PayAdjustment",
                            XMLForest(
                                EMPLOYEE as "EmployeeId",
                                STORE AS "StoreNumber",
                                DEPARTMENT AS "Department",
                                WORKCODE AS "AdjustCode",
                                PAYROLL_DATE AS "PayDate",
                                HOURS as "Hours",
                                0 as "Amount"
                            ) AS "PayAdjustment"
                    )))
                )
            ),
            VERSION '1.0" encoding="utf-8',
            STANDALONE YES
        ).getClobVal()
from timecard_payroll
where start_date = '2013-09-15'
and end_date = '2013-09-21'
and hours > 0;
于 2013-09-30T14:54:03.360 回答