问题
We have a generic table that holds multiple records (DDL and DML below):
CREATE TABLE "XXAB_ZZ_VAT_TRX_GT"
( "AB_INFO_V1" VARCHAR2(240 BYTE),
"AB_INFO_V2" VARCHAR2(240 BYTE),
"AB_INFO_V3" VARCHAR2(240 BYTE),
"AB_INFO_V4" VARCHAR2(240 BYTE),
"AB_INFO_V5" VARCHAR2(240 BYTE),
"AB_INFO_V6" VARCHAR2(1996 BYTE),
"AB_INFO_V7" VARCHAR2(240 BYTE),
"AB_INFO_V8" VARCHAR2(240 BYTE),
"AB_INFO_V9" VARCHAR2(1996 BYTE),
"AB_INFO_V10" VARCHAR2(1996 BYTE),
"AB_INFO_V11" VARCHAR2(150 BYTE),
"AB_INFO_V12" VARCHAR2(150 BYTE),
"AB_INFO_V13" VARCHAR2(150 BYTE),
"AB_INFO_V14" VARCHAR2(150 BYTE),
"AB_INFO_V15" VARCHAR2(1996 BYTE),
"AB_INFO_V16" VARCHAR2(150 BYTE),
"AB_INFO_V17" VARCHAR2(1996 BYTE),
"AB_INFO_V18" VARCHAR2(150 BYTE),
"AB_INFO_V19" VARCHAR2(150 BYTE),
"AB_INFO_V20" VARCHAR2(150 BYTE),
"AB_INFO_V21" VARCHAR2(150 BYTE),
"AB_INFO_V22" VARCHAR2(150 BYTE),
"AB_INFO_V23" VARCHAR2(150 BYTE),
"AB_INFO_V24" VARCHAR2(150 BYTE),
"AB_INFO_V25" VARCHAR2(150 BYTE),
"AB_INFO_V26" VARCHAR2(150 BYTE),
"AB_INFO_V27" VARCHAR2(150 BYTE),
"AB_INFO_V28" VARCHAR2(150 BYTE),
"AB_INFO_V29" VARCHAR2(150 BYTE),
"AB_INFO_V30" VARCHAR2(150 BYTE),
"AB_INFO_V31" VARCHAR2(150 BYTE),
"AB_INFO_V32" VARCHAR2(1996 BYTE),
"AB_INFO_V33" VARCHAR2(150 BYTE),
"AB_INFO_V34" VARCHAR2(150 BYTE),
"AB_INFO_V35" VARCHAR2(150 BYTE),
"AB_INFO_V36" VARCHAR2(150 BYTE),
"AB_INFO_V37" VARCHAR2(150 BYTE),
"AB_INFO_V38" VARCHAR2(150 BYTE),
"AB_INFO_V39" VARCHAR2(150 BYTE),
"AB_INFO_V40" VARCHAR2(150 BYTE),
"AB_INFO_N1" NUMBER,
"AB_INFO_N2" NUMBER,
"AB_INFO_N3" NUMBER,
"AB_INFO_N4" NUMBER,
"AB_INFO_N5" NUMBER,
"AB_INFO_N6" NUMBER,
"AB_INFO_N7" NUMBER,
"AB_INFO_N8" NUMBER,
"AB_INFO_N9" NUMBER,
"AB_INFO_N10" NUMBER,
"AB_INFO_N11" NUMBER,
"AB_INFO_N12" NUMBER,
"AB_INFO_N13" NUMBER,
"AB_INFO_N14" NUMBER,
"AB_INFO_N15" NUMBER,
"AB_INFO_N16" NUMBER,
"AB_INFO_N17" NUMBER,
"AB_INFO_N18" NUMBER,
"AB_INFO_N19" NUMBER,
"AB_INFO_N20" NUMBER,
"AB_INFO_N21" NUMBER,
"AB_INFO_N22" NUMBER,
"AB_INFO_N23" NUMBER,
"AB_INFO_N24" NUMBER,
"AB_INFO_N25" NUMBER,
"AB_INFO_N26" NUMBER,
"AB_INFO_N27" NUMBER,
"AB_INFO_N28" NUMBER,
"AB_INFO_N29" NUMBER,
"AB_INFO_N30" NUMBER,
"AB_INFO_D1" DATE,
"AB_INFO_D2" DATE,
"AB_INFO_D3" DATE,
"AB_INFO_D4" DATE,
"AB_INFO_D5" DATE,
"AB_INFO_D6" DATE,
"AB_INFO_D7" DATE,
"AB_INFO_D8" DATE,
"AB_INFO_D9" DATE,
"AB_INFO_D10" DATE,
"AB_INFO_D11" DATE,
"AB_INFO_D12" DATE,
"AB_INFO_D13" DATE,
"AB_INFO_D14" DATE,
"AB_INFO_D15" DATE
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 65536 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSTEM" ;
Below are the records:
SET DEFINE OFF;
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:B_MPV_PROWIZJA','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,856625,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','64','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:','tns:',null,null,null,'Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,900,90,857621,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','64','Business World',null,'tns:K_20','tns:K_17','643815678',' INPUT_VAT','POLAND VAT-KA',null,'643815678','tns:','tns:',null,null,null,'Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,400,44,857621,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','64','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:','tns:',null,null,null,'Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,2500,300,857621,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:EE','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,500,55,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:IMP','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,300,33,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:MR_T','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,200,22,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:EE','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,0,0,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:IMP','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,0,0,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','161','Computer Service and Rentals',null,'tns:K_20','tns:K_17','brak',' INPUT_VAT','POLAND VAT-KA',null,null,'tns:MR_T','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','301 Summit Hill Drive 37401 Chattanooga US Hamilton TN',null,null,'0',null,0,0,862618,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','141','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:TP','tns:GTU04',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,30,3,861618,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','141','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:TP','tns:GTU04',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,861618,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','142','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,30,3,861619,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','142','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,861619,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','143','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,218.34,21.84,861620,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','143','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,861620,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','162','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,100,10,862619,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','162','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,862619,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','163','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,100,12,862620,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','163','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,862620,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','165','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,100,12,862622,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','165','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,862622,12,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','166','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,100,10,862623,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','166','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:IMP','tns:GTU01',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,862623,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','43','Bigmart',null,'tns:K_14','tns:K_11','349173','INPUT_VAT','POLAND VAT-A',null,'349173','tns:EE','tns:',null,null,null,'Stankiewicza 390 3 50-550 Warszawa PL PL',null,null,'0',null,1,0.1,856620,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,3,0.3,856625,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_14','tns:K_11','643815678','INPUT_VAT','POLAND VAT-A',null,'643815678','tns:','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,856625,10,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_20','tns:K_17','643815678',' INPUT_VAT','POLAND VAT-KA',null,'643815678','tns:EE','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,2,0.22,856625,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_20','tns:K_17','643815678',' INPUT_VAT','POLAND VAT-KA',null,'643815678','tns:EE','tns:',null,'WEW','ORA_JEPL_DOCUMENT_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,0,0,856625,11,null,null,null);
Insert into XXAB_ZZ_VAT_TRX_GT (AB_INFO_V1,AB_INFO_V2,AB_INFO_V3,AB_INFO_V4,AB_INFO_V5,AB_INFO_V6,AB_INFO_V7,AB_INFO_V8,AB_INFO_V9,AB_INFO_V10,AB_INFO_V11,AB_INFO_V12,AB_INFO_V13,AB_INFO_V14,AB_INFO_V15,AB_INFO_V16,AB_INFO_V17,AB_INFO_V18,AB_INFO_V19,AB_INFO_V20,AB_INFO_V21,AB_INFO_N1,AB_INFO_N2,AB_INFO_N3,AB_INFO_N4,AB_INFO_N5,AB_INFO_N6,AB_INFO_N7) values ('AR','48','Business World',null,'tns:K_31','tns:','643815678','INPUT_VAT','POLAND VAT RS',null,'643815678','tns:B_MPV_PROWIZJA','tns:',null,'TRANSPORTATION','JE_PL_JPK_BUSINESS_TYPE','Stankiewicza 188 3 50-550 Warszawa PL PL',null,null,'0',null,4,0.48,856625,12,null,null,null);
The query below works in 12c, but Errors out in 11g:
SELECT
XMLAgg(Case When (Select ab_info_n26 From xxab_zz_vat_trx_gt Where ab_info_v1 = 'H' and ab_info_v27 = 'AR' ) > 0 Then
(SELECT XMLAGG(XMLCONCAT(XMLElement("tns:SprzedazWiersz",
xmlelement("tns:LpSprzedazy" , rownum),
xmlelement("tns:KodKrajuNadaniaTIN", substr(ar_trx.tax_reg_num, 0, 2)),
xmlelement("tns:NrKontrahenta" , substr(ar_trx.tax_reg_num, 2)),
xmlelement("tns:NazwaKontrahenta" , ar_trx.cust_name),
xmlelement("tns:DowodSprzedazy" , ar_trx.trx_number),
xmlelement("tns:DataWystawienia" , TO_CHAR(ar_trx.invoice_date,'RRRR-MM-DD')),
Case When ar_trx.sales_date is not null Then xmlelement("tns:DataSprzedazy" , TO_CHAR(ar_trx.sales_date,'RRRR-MM-DD')) END
-- Document Type
,(select xmlagg(xmlconcat(xmlelement("tns:TypDokumentu", ab_info_v15)))
From xxab_zz_vat_trx_gt
Where ab_info_v1 = 'AR'
and ab_info_n3 = ar_trx.trx_id
and ab_info_v16 = 'ORA_JEPL_DOCUMENT_TYPE')
-- product category code
,(SELECT xmlagg(xmlconcat(xmlelement(evalname(prd_code), 1)))
FROM (select distinct
ab_info_n3 trx_id
, ab_info_v13 prd_code
from xxab_zz_vat_trx_gt
Where ab_info_V1 = 'AR'
and ab_info_v13 <> 'tns:') d
where d.trx_id = ar_trx.trx_id
)
-- Trade Attributes
,(SELECT xmlagg(xmlconcat(xmlelement(evalname(e.TRADE_ATTRIBUTE_VALUES), 1)))
from (select distinct ab_info_n3 trx_id
, DECODE(TRADE_ATTRIBUTE_VALUES, '1', 'tns:MPP', TRADE_ATTRIBUTE_VALUES) TRADE_ATTRIBUTE_VALUES
from xxab_zz_vat_trx_gt unpivot (TRADE_ATTRIBUTE_VALUES for TRADE_ATTRIBUTES in (ab_info_v12, ab_info_v20))
Where ab_info_V1 = 'AR'
and TRADE_ATTRIBUTE_VALUES not in ('tns:', 'tns:IMP', '0')
order by case TRADE_ATTRIBUTE_VALUES
when 'tns:SW' THEN 1
when 'tns:EE' THEN 2
when 'tns:TP' THEN 3
when 'tns:TT_WNT' then 4
when 'tns:TT_D' THEN 5
when 'tns:MR_T' THEN 6
when 'tns:MR_UZ' THEN 7
when 'tns:I_42' THEN 8
when 'tns:I_63' THEN 9
when 'tns:B_SPV' THEN 10
when 'tns:B_SPV_DOSTAWA' THEN 11
when 'tns:B_MPV_PROWIZJA' THEN 12
when 'tns:MPP' THEN 13
ELSE 14 END) e
where e.trx_id = ar_trx.trx_id)
,(select xmlagg(xmlconcat(xmlelement(evalname(fnd_box.box),ROUND(sum(nvl(ar_details.amount, 0)),2))))
from (Select ab_info_n3 trx_id
, ab_info_v5 box
, ab_info_n1 amount
From xxab_zz_vat_trx_gt
Where ab_info_V1 = 'AR'
and ab_info_v5 <> 'tns:'
and ab_info_n3 = ar_trx.trx_id -- ERROR HERE
UNION ALL
Select ab_info_n3 trx_id
, ab_info_v6 box
, ab_info_n2 amount
From xxab_zz_vat_trx_gt
Where ab_info_V1 = 'AR'
and ab_info_v6 <> 'tns:'
and ab_info_n3 = ar_trx.trx_id -- ERROR HERE
) ar_details
, (SELECT 'tns:K_'||(LEVEL + 9) box
FROM dual
CONNECT BY LEVEL <= 27) fnd_box
where fnd_box.box = ar_details.box (+)
group by fnd_box.box)
)))
From ( Select distinct ab_info_n3 trx_id
, ab_info_v2 trx_number
, ab_info_d1 sales_date
, ab_info_d3 invoice_date
, ab_info_v3 cust_name
, ab_info_v17 cust_addr
, ab_info_v7 tax_reg_num
From xxab_zz_vat_trx_gt
Where ab_info_v1 = 'AR'
Order by 3,4
) ar_trx
) End)
FROM DUAL;
It errors out with ORA-00904: "AR_TRX"."TRX_ID": invalid identifier
.
I believe this is caused by the correlated subquery AR_TRX
linked to the SELECT
statement (see comments "-- ERROR HERE" above).
I need this same query to work for both 12c and 11g. Below are the versions from each Database
11g:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
PL/SQL Release 11.2.0.4.0 - Production "CORE 11.2.0.4.0 Production"
12c:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit
Production PL/SQL Release 12.1.0.2.0 - Production
I've tried using CTE (Common Table Expressions) such as the WITH clause, but it's still not working for 11g: I've read that there can only be a single-level of the Sub-Query in 11g.
Is there a workaround for 11g?
Please advise. Thank you!
回答1:
I was able to resolve this by a solution provided by an SQL Expert Chris Saxon using with WITH
CTE. I previously used it as the main driving table, but turns out, it should be at the correlation queries like below:
with ar_kbox_details as (
select ab_info_n3 trx_id,
ab_info_v5 box,
ab_info_n1 amount
from xxab_zz_vat_trx_gt
where ab_info_v1 = 'AR'
and ab_info_v5 <> 'tns:'
union all
select ab_info_n3 trx_id,
ab_info_v6 box,
ab_info_n2 amount
from xxab_zz_vat_trx_gt
where ab_info_v1 = 'AR'
and ab_info_v6 <> 'tns:'
)
SELECT XMLAGG(XMLCONCAT(XMLElement
("tns:SprzedazWiersz",
xmlelement("tns:LpSprzedazy" , rownum),
xmlelement("tns:KodKrajuNadaniaTIN", substr(ar_trx.tax_reg_num, 0, 2)),
xmlelement("tns:NrKontrahenta" , substr(ar_trx.tax_reg_num, 2)),
xmlelement("tns:NazwaKontrahenta" , ar_trx.cust_name),
xmlelement("tns:DowodSprzedazy" , ar_trx.trx_number),
xmlelement("tns:DataWystawienia" , TO_CHAR(ar_trx.invoice_date,'RRRR-MM-DD')),
Case When ar_trx.sales_date is not null Then xmlelement("tns:DataSprzedazy" , TO_CHAR(ar_trx.sales_date,'RRRR-MM-DD')) END
-- Document Type
,(select distinct xmlagg(xmlconcat(xmlelement("tns:TypDokumentu", ab_info_v15)))
From xxab_zz_vat_trx_gt
Where ab_info_v1 = 'AR'
and ab_info_n3 = ar_trx.trx_id
and ab_info_v16 = 'ORA_JEPL_DOCUMENT_TYPE')
-- product category code
,(select distinct xmlagg(xmlconcat(xmlelement(evalname(ab_info_v13), 1)))
from xxab_zz_vat_trx_gt
Where ab_info_V1 = 'AR'
and ab_info_v13 <> 'tns:'
and ab_info_n3 = ar_trx.trx_id)
-- Trade Attributes
,(select distinct xmlagg(xmlconcat(xmlelement(evalname(DECODE(TRADE_ATTRIBUTE_VALUES, '1', 'tns:MPP', TRADE_ATTRIBUTE_VALUES)), 1))
order by
case TRADE_ATTRIBUTE_VALUES
when 'tns:SW' THEN 1
when 'tns:EE' THEN 2
when 'tns:TP' THEN 3
when 'tns:TT_WNT' then 4
when 'tns:TT_D' THEN 5
when 'tns:MR_T' THEN 6
when 'tns:MR_UZ' THEN 7
when 'tns:I_42' THEN 8
when 'tns:I_63' THEN 9
when 'tns:B_SPV' THEN 10
when 'tns:B_SPV_DOSTAWA' THEN 11
when 'tns:B_MPV_PROWIZJA' THEN 12
when 'tns:MPP' THEN 13
ELSE 14 END)
from xxab_zz_vat_trx_gt unpivot (TRADE_ATTRIBUTE_VALUES for TRADE_ATTRIBUTES in (ab_info_v12, ab_info_v20))
Where ab_info_V1 = 'AR'
and TRADE_ATTRIBUTE_VALUES not in ('tns:', 'tns:IMP', '0')
and ab_info_n3 = ar_trx.trx_id
)
--KBoxes
,(select xmlagg(xmlconcat(xmlelement(evalname(fnd_box.box),ROUND(sum(nvl(akd.amount, 0)),2))))
from ar_kbox_details akd
, (SELECT 'tns:K_'||(LEVEL + 9) box
FROM dual
CONNECT BY LEVEL <= 27) fnd_box
where fnd_box.box = akd.box (+)
and ar_trx.trx_id = akd.trx_id (+)
group by fnd_box.box)
)))
From ( Select distinct
ab_info_n3 trx_id
, ab_info_v2 trx_number
, ab_info_d1 sales_date
, ab_info_d3 invoice_date
, ab_info_v3 cust_name
, ab_info_v17 cust_addr
, ab_info_v7 tax_reg_num
From xxab_zz_vat_trx_gt
Where ab_info_v1 = 'AR'
Order by 3,4) ar_trx
来源:https://stackoverflow.com/questions/61319654/correlated-subquery-working-differently-for-oracle-12c-and-11g