Reputation: 11
I am getting only this output. How can I transform this to get only scb:messageSender? I want to extract ony partial text. The 2 json files are as below. The 2 jsons needs to be compared against each other using key value pairs and get this compared. How to get this done? am getting only this output. How can I transform this to get only scb:messageSender? I want to extract ony partial text. The 2 json files are as below. The 2 jsons needs to be compared against each other using key value pairs and get this compared. How to get this done?
Here is my code:
WITH header1 AS (
SELECT
txctry as header_txctry,
jt1.instgchanl as header_instgchnl,
msgid, credttm, nboftxs, ctrlsum, reqdpmttp, instrprty, cdtdbtind, actntp, msgdefidr
FROM
json_data_table,
JSON_TABLE ( json1, '$.header'
COLUMNS (
txctry VARCHAR2 ( 10 ) PATH '$.txCtry',
instgchanl VARCHAR2 ( 10 ) PATH '$.instgChanl',
msgid VARCHAR2 ( 50 ) PATH '$.msgId',
credttm VARCHAR2 ( 50 ) PATH '$.creDtTm',
nboftxs VARCHAR2 ( 10 ) PATH '$.nbOfTxs',
ctrlsum VARCHAR2 ( 20 ) PATH '$.ctrlSum',
reqdpmttp VARCHAR2 ( 10 ) PATH '$.reqdPmtTp',
instrprty VARCHAR2 ( 10 ) PATH '$.instrPrty',
cdtdbtind VARCHAR2 ( 10 ) PATH '$.cdtDbtInd',
actntp VARCHAR2 ( 10 ) PATH '$.actnTp',
msgdefidr VARCHAR2 ( 50 ) PATH '$.msgDefIdr'
)
)
jt1
), header2 AS (
SELECT
txctry as header_txctry,
jt2.instgchanl as header_instgchnl,
msgid, credttm, nboftxs, ctrlsum, reqdpmttp, instrprty, cdtdbtind, actntp, msgdefidr
FROM
json_data_table,
JSON_TABLE ( json2, '$.header'
COLUMNS (
txctry VARCHAR2 ( 10 ) PATH '$.txCtry',
instgchanl VARCHAR2 ( 10 ) PATH '$.instgChanl',
msgid VARCHAR2 ( 50 ) PATH '$.msgId',
credttm VARCHAR2 ( 50 ) PATH '$.creDtTm',
nboftxs VARCHAR2 ( 10 ) PATH '$.nbOfTxs',
ctrlsum VARCHAR2 ( 20 ) PATH '$.ctrlSum',
reqdpmttp VARCHAR2 ( 10 ) PATH '$.reqdPmtTp',
instrprty VARCHAR2 ( 10 ) PATH '$.instrPrty',
cdtdbtind VARCHAR2 ( 10 ) PATH '$.cdtDbtInd',
actntp VARCHAR2 ( 10 ) PATH '$.actnTp',
msgdefidr VARCHAR2 ( 50 ) PATH '$.msgDefIdr'
)
)
jt2
), data1 AS (
SELECT
jt1.txctry as data_txctry,
txcitycd,
jt1.instgchanl as data_instgchanl,
instgSubChanl,
endtoendid,
uetr,instgChanlRef,reqdPmtTp ,ctgyPurpPrty ,sndrPurpCd ,reqdExctnDt ,dtPrtyInd ,
instdAmt , instdCcy ,prtyInd ,acctId ,ccy ,dbtrAgt_BICFI ,cdtrAgt_BICFI ,anyBIC ,cd ,instrInf ,incmgClrMsg
FROM
json_data_table,
JSON_TABLE ( json1, '$.data[*]'
COLUMNS (
txctry VARCHAR2 ( 10 ) PATH '$.txCtry',
txcitycd VARCHAR2 ( 10 ) PATH '$.txCityCd',
--data.chanl
instgchanl VARCHAR2 ( 10 ) PATH '$.chanl.instgChanl',
instgSubChanl VARCHAR2 ( 10 ) PATH '$.chanl.instgSubChanl',
--pmtId
instgchanlref VARCHAR2 ( 50 ) PATH '$.pmtId.instgChanlRef',
endtoendid VARCHAR2 ( 50 ) PATH '$.pmtId.endToEndId',
uetr VARCHAR2 ( 200 ) PATH '$.pmtId.UETR',
--pmtTpInf
reqdPmtTp VARCHAR2 ( 50 ) PATH '$.pmtTpInf.reqdPmtTp',
ctgyPurpPrty VARCHAR2 ( 50 ) PATH '$.pmtTpInf.ctgyPurpPrty',
--purp
sndrPurpCd VARCHAR2 ( 50 ) PATH '$.purp.sndrPurpCd',
--sttlmDtTmInf
reqdExctnDt VARCHAR2 ( 50 ) PATH '$.sttlmDtTmInf.reqdExctnDt',
dtPrtyInd VARCHAR2 ( 50 ) PATH '$.sttlmDtTmInf.dtPrtyInd',
--amt
instdAmt VARCHAR2 ( 50 ) PATH '$.amt.instdAmt',
instdCcy VARCHAR2 ( 50 ) PATH '$.amt.instdCcy',
prtyInd VARCHAR2 ( 50 ) PATH '$.amt.prtyInd',
--reqdDbtAcctInf
acctId VARCHAR2 ( 50 ) PATH '$.reqdDbtAcctInf.acctId',
ccy VARCHAR2 ( 50 ) PATH '$.reqdDbtAcctInf.ccy',
--dbtrAgt
dbtrAgt_BICFI VARCHAR2 ( 50 ) PATH '$.dbtrAgt.BICFI',
--cdtrAgt
cdtrAgt_BICFI VARCHAR2 ( 50 ) PATH '$.cdtrAgt.BICFI',
--cdtr
anyBIC VARCHAR2 ( 50 ) PATH '$.cdtr.orgId.anyBIC',
--instrForNxtAgt
cd VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.cd',
instrInf VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.instrInf',
--cd VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.cd',
--instrInf VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.instrInf',
--splmtryData
incmgClrMsg VARCHAR2 ( 1000 ) PATH '$.splmtryData.incmgClrMsg'
)
)
jt1
), data2 AS (
SELECT
jt2.txctry as data_txctry,
txcitycd,
jt2.instgchanl as data_instgchanl,
instgSubChanl,
endtoendid,
uetr,instgChanlRef,reqdPmtTp ,ctgyPurpPrty ,sndrPurpCd ,reqdExctnDt ,dtPrtyInd ,
instdAmt , instdCcy ,prtyInd ,acctId ,ccy ,dbtrAgt_BICFI ,cdtrAgt_BICFI ,anyBIC ,cd ,instrInf ,incmgClrMsg
FROM
json_data_table,
JSON_TABLE ( json2, '$.data[*]'
COLUMNS (
txctry VARCHAR2 ( 10 ) PATH '$.txCtry',
txcitycd VARCHAR2 ( 10 ) PATH '$.txCityCd',
--data.chanl
instgchanl VARCHAR2 ( 10 ) PATH '$.chanl.instgChanl',
instgSubChanl VARCHAR2 ( 10 ) PATH '$.chanl.instgSubChanl',
--pmtId
instgchanlref VARCHAR2 ( 50 ) PATH '$.pmtId.instgChanlRef',
endtoendid VARCHAR2 ( 50 ) PATH '$.pmtId.endToEndId',
uetr VARCHAR2 ( 200 ) PATH '$.pmtId.UETR' ,
--pmtTpInf
reqdPmtTp VARCHAR2 ( 50 ) PATH '$.pmtTpInf.reqdPmtTp',
ctgyPurpPrty VARCHAR2 ( 50 ) PATH '$.pmtTpInf.ctgyPurpPrty',
--purp
sndrPurpCd VARCHAR2 ( 50 ) PATH '$.purp.sndrPurpCd',
--sttlmDtTmInf
reqdExctnDt VARCHAR2 ( 50 ) PATH '$.sttlmDtTmInf.reqdExctnDt',
dtPrtyInd VARCHAR2 ( 50 ) PATH '$.sttlmDtTmInf.dtPrtyInd',
--amt
instdAmt VARCHAR2 ( 50 ) PATH '$.amt.instdAmt',
instdCcy VARCHAR2 ( 50 ) PATH '$.amt.instdCcy',
prtyInd VARCHAR2 ( 50 ) PATH '$.amt.prtyInd',
--reqdDbtAcctInf
acctId VARCHAR2 ( 50 ) PATH '$.reqdDbtAcctInf.acctId',
ccy VARCHAR2 ( 50 ) PATH '$.reqdDbtAcctInf.ccy',
--dbtrAgt
dbtrAgt_BICFI VARCHAR2 ( 50 ) PATH '$.dbtrAgt.BICFI',
--cdtrAgt
cdtrAgt_BICFI VARCHAR2 ( 50 ) PATH '$.cdtrAgt.BICFI',
--cdtr
anyBIC VARCHAR2 ( 50 ) PATH '$.cdtr.orgId.anyBIC',
--instrForNxtAgt
cd VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.cd',
instrInf VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.instrInf',
--cd VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.cd',
--instrInf VARCHAR2 ( 50 ) PATH '$.instrForNxtAgt.instrInf',
--splmtryData
incmgClrMsg VARCHAR2 ( 1000 ) PATH '$.splmtryData.incmgClrMsg'
)
)
jt2
), instr1 AS (
SELECT
jt1.cd AS code,
jt1.instrinf AS instruction
FROM
json_data_table,
JSON_TABLE ( json1, '$.data[*].instrForNxtAgt[*]'
COLUMNS (
cd VARCHAR2 ( 10 ) PATH '$.cd',
instrinf VARCHAR2 ( 100 ) PATH '$.instrInf'
)
)
jt1
), instr2 AS (
SELECT
jt2.cd AS code,
jt2.instrinf AS instruction
FROM
json_data_table,
JSON_TABLE ( json2, '$.data[*].instrForNxtAgt[*]'
COLUMNS (
cd VARCHAR2 ( 10 ) PATH '$.cd',
instrinf VARCHAR2 ( 100 ) PATH '$.instrInf'
)
)
jt2
) -- Final comparison
SELECT
'header.txCtry' AS key_name,
h1.header_txctry AS json1_value,
h2.header_txctry AS json2_value,
CASE
WHEN h1.header_txctry != h2.header_txctry THEN
'Different'
ELSE
'Same'
END AS difference
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.instgChanl',
h1.header_instgchnl,
h2.header_instgchnl,
CASE
WHEN h1.header_instgchnl != h2.header_instgchnl THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.msgId',
h1.msgid,
h2.msgid,
CASE
WHEN h1.msgid != h2.msgid THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.creDtTm',
h1.credttm,
h2.credttm,
CASE
WHEN h1.credttm != h2.credttm THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.nbOfTxs',
h1.nboftxs,
h2.nboftxs,
CASE
WHEN h1.nboftxs != h2.nboftxs THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.ctrlSum',
h1.ctrlSum,
h2.ctrlSum,
CASE
WHEN h1.ctrlSum != h2.ctrlSum THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
UNION ALL
SELECT
'header.reqdPmtTp',
h1.reqdPmtTp,
h2.reqdPmtTp,
CASE
WHEN h1.reqdPmtTp != h2.reqdPmtTp THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
----instrPrty
UNION ALL
SELECT
'header.instrPrty',
h1.instrPrty,
h2.instrPrty,
CASE
WHEN h1.instrPrty != h2.instrPrty THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
----cdtDbtInd
UNION ALL
SELECT
'header.cdtDbtInd',
h1.cdtDbtInd,
h2.cdtDbtInd,
CASE
WHEN h1.cdtDbtInd != h2.cdtDbtInd THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
----actnTp
UNION ALL
SELECT
'header.actnTp',
h1.actnTp,
h2.actnTp,
CASE
WHEN h1.actnTp != h2.actnTp THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
----msgDefIdr
UNION ALL
SELECT
'header.msgDefIdr',
h1.msgDefIdr,
h2.msgDefIdr,
CASE
WHEN h1.msgDefIdr != h2.msgDefIdr THEN
'Different'
ELSE
'Same'
END
FROM
header1 h1
JOIN header2 h2 ON 1 = 1
--txCtry
UNION ALL
SELECT
'data.txCtry',
d1.data_txctry,
d2.data_txctry,
CASE
WHEN d1.data_txctry != d2.data_txctry THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1
--txCityCd
UNION ALL
SELECT
'data.txCityCd',
d1.txcitycd,
d2.txcitycd,
CASE
WHEN d1.txcitycd != d2.txcitycd THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1
UNION ALL
SELECT
'data.data_instgchanl',
d1.data_instgchanl,
d2.data_instgchanl,
CASE
WHEN d1.data_instgchanl != d2.data_instgchanl THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare data_instgchanl
UNION ALL
SELECT
'data.instgSubChanl',
d1.instgSubChanl,
d2.instgSubChanl,
CASE
WHEN d1.instgSubChanl != d2.instgSubChanl THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare instgSubChanl
UNION ALL
SELECT
'data.instgChanlRef',
d1.instgchanlref,
d2.instgchanlref,
CASE
WHEN d1.instgchanlref != d2.instgchanlref THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1
UNION ALL
SELECT
'data.endToEndId',
d1.endtoendid,
d2.endtoendid,
CASE
WHEN d1.endtoendid != d2.endtoendid THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare endtoendid
UNION ALL
SELECT
'data.uetr',
d1.uetr,
d2.uetr,
CASE
WHEN d1.uetr != d2.uetr THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'instrForNxtAgt: ' || i1.code,
i1.instruction,
i2.instruction,
CASE
WHEN i1.instruction != i2.instruction THEN
'Different'
ELSE
'Same'
END
FROM
instr1 i1
JOIN instr2 i2 ON i1.code = i2.code
UNION ALL
SELECT
'data.reqdPmtTp ',
d1.reqdPmtTp ,
d2.reqdPmtTp ,
CASE
WHEN d1.reqdPmtTp != d2.reqdPmtTp THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.ctgyPurpPrty ',
d1.ctgyPurpPrty ,
d2.ctgyPurpPrty ,
CASE
WHEN d1.ctgyPurpPrty != d2.ctgyPurpPrty THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.sndrPurpCd ',
d1.sndrPurpCd ,
d2.sndrPurpCd ,
CASE
WHEN d1.sndrPurpCd != d2.sndrPurpCd THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.reqdExctnDt ',
d1.reqdExctnDt ,
d2.reqdExctnDt ,
CASE
WHEN d1.reqdExctnDt != d2.reqdExctnDt THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.dtPrtyInd ',
d1.dtPrtyInd ,
d2.dtPrtyInd ,
CASE
WHEN d1.dtPrtyInd != d2.dtPrtyInd THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.instdAmt ',
d1.instdAmt ,
d2.instdAmt ,
CASE
WHEN d1.instdAmt != d2.instdAmt THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.instdCcy ',
d1.instdCcy ,
d2.instdCcy ,
CASE
WHEN d1.instdCcy != d2.instdCcy THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.prtyInd ',
d1.prtyInd ,
d2.prtyInd ,
CASE
WHEN d1.prtyInd != d2.prtyInd THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.acctId ',
d1.acctId ,
d2.acctId ,
CASE
WHEN d1.acctId != d2.acctId THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.ccy ',
d1.ccy ,
d2.ccy ,
CASE
WHEN d1.ccy != d2.ccy THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.dbtrAgt_BICFI ',
d1.dbtrAgt_BICFI ,
d2.dbtrAgt_BICFI ,
CASE
WHEN d1.dbtrAgt_BICFI != d2.dbtrAgt_BICFI THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.cdtrAgt_BICFI ',
d1.cdtrAgt_BICFI ,
d2.cdtrAgt_BICFI ,
CASE
WHEN d1.cdtrAgt_BICFI != d2.cdtrAgt_BICFI THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.anyBIC ',
d1.anyBIC ,
d2.anyBIC ,
CASE
WHEN d1.anyBIC != d2.anyBIC THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.cd ',
d1.cd ,
d2.cd ,
CASE
WHEN d1.cd != d2.cd THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.instrInf ',
d1.instrInf ,
d2.instrInf ,
CASE
WHEN d1.instrInf != d2.instrInf THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1 -- Compare uetr
UNION ALL
SELECT
'data.incmgClrMsg ',
d1.incmgClrMsg ,
d2.incmgClrMsg ,
CASE
WHEN d1.incmgClrMsg != d2.incmgClrMsg THEN
'Different'
ELSE
'Same'
END
FROM
data1 d1
JOIN data2 d2 ON 1 = 1;
Upvotes: 0
Views: 79