我有一个使用SQLDeveloper的SELECT查询,该查询使用许多情况来提取应用程序编号的结果。但是,单个申请号可能会出现多种情况。我们正在生成一个XML文件,我们需要将每种情况作为换行。该查询只是将所有信息捆绑到一行中。
以下是查询:
select XMLElement("wo-national-office-event",
XMLAttributes('US' as "office-code",
tbl3.PERCENT_NUMBER as "international-application",
trim(tbl3.DN_Another_Identifier) as "national-application",
CASE WHEN TBL_1.FILE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN 'E' END as "event-type",
CASE WHEN ISSUE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN 'G' END as "event-type",
CASE WHEN TBL_2.PUBLICATION_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN 'P' END as "event-type",
CASE WHEN TBL_1.FILE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN to_char(TBL_1.FILE_DATE, 'yyyymmdd') END as "event-date",
CASE WHEN ISSUE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN to_char(ISSUE_DATE, 'yyyymmdd' END) as "event-date",
CASE WHEN TBL_2.PUBLICATION_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN TO_char(TBL_2.PUBLICATION_DATE, 'yyyymmdd' END) as "event-date",
CASE WHEN ISSUE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN patent_no END) as "publication-number",
CASE WHEN TBL_2.PUBLICATION_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN TBL_2.PUBLICATION_YEAR || TBL_2.PUBLICATION_NUMBER END as "publication-number",
CASE WHEN TBL_2.PUBLICATION_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY') THEN TBL_2.PUBLICATION_CODE END as "publication-code"
)
) as RESULT
from
TBL_1, TBL_2, TBL_3 tbl3 where
TBL_1.Some_Identifier = tbl3.Dn_Another_Identifier
and SOME_INDICATOR = 'Y'
and Some_Identifier like '15%'
and TBL_1.FKEY_ID = TBL_2.FKEY_ID
and (TBL_1.FILE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY')
or ISSUE_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY')
or TBL_2.PUBLICATION_DATE between to_date('2/01/2019','MM/DD/YYYY') and to_date('3/01/2019','MM/DD/YYYY'));
以下是结果:
Query Order: A B C D X1 Y1 X2 Y2 X3 Y3 X4 Y4 E
<wo-national-office-event office-code="US" international-application="AAA/111/AAA" national-application="12345" event-type="G" event-type="P" event-date="20190226" event-date="20190214" publication-number="654321" publication-number="123456" publication-code="B12"/>
我想要达到的结果:
Query order:
A B C D X1 X2 X3 X4
A B C D Y1 Y2 Y3 Y4 E
<wo-national-office-event office-code="US" international-application="AAA/111/AAA" national-application="12345" event-type="G" event-date="20190226" publication-number="654321"/>
<wo-national-office-event office-code="US" international-application="AAA/111/AAA" national-application="12345" event-type="P" event-date="20190214" publication-number="123456" publication-code="B12"/>
我正在查看PIVOT命令,但是我需要记录多次打印,同时保留其XML格式。