【发布时间】:2017-09-21 21:22:45
【问题描述】:
我正在尝试将几种 XML 格式加载到一个通用表结构中,但其中一个包含以下 XML 数据时遇到问题:
<payslip >
<address >
<addressee >XXXXX YYYYY</addressee>
<line >167 High Road</line>
<line >Walthamstow</line>
<line >London</line>
<line >E17 5DD [201567 ]</line>
<ifundelivered >3738 XYZ Limited Herring Court 27 - 29 Frobisher Street Dulwich London WC2B 3SS</ifundelivered></address>
<employer >
<name >3738 XYZ Limited</name>
<taxdistrict >406</taxdistrict>
<taxref >LA99999</taxref></employer>
<employee >
<payroll >3799-</payroll>
<userid >3799-201567</userid>
<number >201567</number>
<name >XXXXX YYYYY</name>
<deptnumber >0001</deptnumber>
<deptname >2000</deptname>
<taxcode >1150L</taxcode>
<NINO >QQ104330Q</NINO>
<NItable >A</NItable>
<email >xxxxx.yyyyy@qqqqqq.co.uk</email></employee>
<period >
<paydate >2017-08-11</paydate>
<taxperiod type = "week" >20</taxperiod></period>
<elements >
<element amount = "1572.62" position = "gross" title = "Salary"/>
<element amount = "-470.00" position = "adjust" title = "P.A.Y.E." ytd = "1399.80"/>
<element amount = "1741.00" position = "gross" title = "Perf Bonus"/>
<element amount = "-312.84" position = "adjust" title = "N.I." ytd = "994.34"/>
<element amount = "-78.63" position = "gross" rate = "-78.6300" title = "Unpaid Sick" units = "1.0000"/>
<element amount = "-1.00" position = "adjust" title = "RDC" ytd = "3.00"/>
</elements>
<totals >
<gross >3234.99</gross>
<adjustments >-783.84</adjustments>
<nett >2451.15</nett></totals>
<notations >
<thisemployment title = "NIable Pay" ytd = "11426.14"/>
<thisemployment title = "Taxable Pay" ytd = "11426.14"/>
<thisemployment title = "Tax deduct." ytd = "1399.80"/>
<prevemployment title = "Pay" ytd = "0.00"/>
<prevemployment title = "Tax deduct." ytd = "0.00"/>
<employer thisrun = "359.76" title = "Nat. Ins." ytd = "1143.48"/>
<employer thisrun = "0.00" title = "Pension" ytd = "15.73"/>
</notations>
<comments >
<line >2451.15 paid by BACS. **-*7-13 A/c ****3333</line>
</comments>
</payslip>
我无法将变量分配给不同部分中的元素。例如元素“名称”出现在“员工”和“雇主”部分中,我无法区分这些部分以将变量分配给列。
LOAD XML local INFILE 'I:/PAYSLIPS37380004.xml'
INTO TABLE test.temp_payslips
rows identified by '<payslip>'
(@NINO,
@number)
SET Payrollrunid=1,
isLive=1,
print=0,
NINumber=@NINO,
EmployeeNumber=@number;
我尝试在变量前面加上部分(例如@employee.number),但这不起作用。有什么想法吗?
我还需要根据“元素”部分中的数据在子表 (paysliptrans) 中创建记录。我想使用的代码是:
LOAD XML local INFILE 'I:/PAYSLIPS37380004.xml'
INTO TABLE pmdata_test.temp_paysliptrans rows identified by '<elements>'
(@title,
@amount,
@position,
@rate,
@units,
@ytd)
SET PayslipID=(select payslipid from pmdata_test.temp_payslips where EmployeeNumber=@number),
Name=@title,
Type="P",
Total=@amount,
Rate=@rate,
Units=@units,
YTD=@ytd;
但我仍然有同样的问题,因为它不会提取获取 payslipID 数据以填充 paysliptrans.payslipID 字段所需的@number(员工)。
其他信息:
temp_payslips 表
CREATE TABLE `temp_payslips` (
`PayslipID` int(11) NOT NULL AUTO_INCREMENT,
`PayrollRunID` int(11) NOT NULL,
`EmployeeID` varchar(45) DEFAULT NULL,
`EmployeeNumber` varchar(10) NOT NULL DEFAULT '0',
`FirstName` varchar(45) DEFAULT NULL,
`LastName` varchar(45) DEFAULT NULL,
`EmployeeName` varchar(45) DEFAULT NULL,
`AddressName` varchar(45) DEFAULT NULL,
`Address1` varchar(45) DEFAULT NULL,
`Address2` varchar(45) DEFAULT NULL,
`Address3` varchar(45) DEFAULT NULL,
`Address4` varchar(45) DEFAULT NULL,
`Address5` varchar(45) DEFAULT NULL,
`PostCode` varchar(45) DEFAULT NULL,
`Country` varchar(45) DEFAULT NULL,
`CompanyName` varchar(45) DEFAULT NULL,
`Department` varchar(45) DEFAULT NULL,
`CostCentre` varchar(15) DEFAULT NULL,
`CostCentreDesc` varchar(45) DEFAULT NULL,
`LocationName` varchar(35) DEFAULT NULL,
`PayDate` date DEFAULT NULL,
`PeriodNumber` int(11) DEFAULT NULL,
`PayFrequency` varchar(10) DEFAULT NULL,
`PayMethod` varchar(20) DEFAULT NULL,
`PrintPayslip` varchar(1) DEFAULT NULL,
`TaxCode` varchar(7) DEFAULT NULL,
`TaxBasis` varchar(10) DEFAULT NULL,
`NINumber` varchar(9) DEFAULT NULL,
`NICode` varchar(1) DEFAULT NULL,
`GrossPay` decimal(10,2) DEFAULT NULL,
`GrossPayYTD` decimal(10,2) DEFAULT NULL,
`GrossTaxPayYTD` decimal(10,2) DEFAULT NULL,
`TaxPaidYTD` decimal(10,2) DEFAULT NULL,
`Deductions` decimal(10,2) DEFAULT NULL,
`DeductionsYTD` decimal(10,2) DEFAULT NULL,
`NETPay` decimal(10,2) DEFAULT NULL,
`NETPayYTD` decimal(10,2) DEFAULT NULL,
`BankName` varchar(45) DEFAULT NULL,
`BankSortCode` varchar(8) DEFAULT NULL,
`BankAccount` varchar(8) DEFAULT NULL,
`BuildingSocNum` varchar(45) DEFAULT NULL,
`Message` varchar(45) DEFAULT NULL,
`HolidayEntitlement` int(11) DEFAULT NULL,
`HolidayTakenThisPeriod` int(11) DEFAULT NULL,
`HolidayRemaining` int(11) DEFAULT NULL,
`ERSPen` decimal(10,2) DEFAULT NULL,
`OutputPrint` bit(1) DEFAULT NULL,
`OutputEmail` varchar(255) DEFAULT NULL,
`OutputSMS` bit(1) DEFAULT NULL,
`OutputPortal` bit(1) DEFAULT NULL,
`DeliveryType` varchar(45) DEFAULT NULL,
`DeliveryGroup` varchar(45) DEFAULT NULL,
`CompanyCode` varchar(45) DEFAULT NULL,
`EmployerPension` decimal(10,2) DEFAULT NULL,
`EmployerPensionYTD` decimal(10,2) DEFAULT NULL,
`EmployeePension` decimal(10,2) DEFAULT NULL,
`EmployeePensionYTD` decimal(10,2) DEFAULT NULL,
`Misc1Pension` decimal(10,2) DEFAULT NULL,
`Misc1PensionYTD` decimal(10,2) DEFAULT NULL,
`Misc2Pension` decimal(10,2) DEFAULT NULL,
`Misc2PensionYTD` decimal(10,2) DEFAULT NULL,
`TaxYear` year(4) DEFAULT NULL,
`P45GrossforTax` decimal(10,2) DEFAULT NULL,
`P45Tax` decimal(10,2) DEFAULT NULL,
`EmployeeNIYTD` decimal(10,2) DEFAULT NULL,
`EmployerNI` decimal(10,2) DEFAULT NULL,
`EmployerNIYTD` decimal(10,2) DEFAULT NULL,
`GrossforNI` decimal(10,2) DEFAULT NULL,
`GrossforNIYTD` decimal(10,2) DEFAULT NULL,
`SSPYTD` decimal(10,2) DEFAULT NULL,
`SMPYTD` decimal(10,2) DEFAULT NULL,
`SPPYTD` decimal(10,2) DEFAULT NULL,
`SAPYTD` decimal(10,2) DEFAULT NULL,
`ASPPYTD` decimal(10,2) DEFAULT NULL,
`AllSPYTD` decimal(10,2) DEFAULT NULL,
`SortSeq` int(11) DEFAULT NULL,
`tempId` int(11) DEFAULT NULL,
`superceded` tinyint(4) DEFAULT '0',
`isLive` tinyint(4) NOT NULL DEFAULT '1',
`print` tinyint(4) NOT NULL DEFAULT '0',
`UUID` varchar(45) DEFAULT NULL,
PRIMARY KEY (`PayslipID`,`PayrollRunID`,`EmployeeNumber`),
KEY `PayDate` (`PayDate`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
temp_paysliptrans 表
CREATE TABLE `temp_paysliptrans` (
`PayslipTranID` int(11) NOT NULL AUTO_INCREMENT,
`PayslipID` int(11) NOT NULL DEFAULT '0',
`Name` varchar(45) DEFAULT NULL,
`Type` varchar(1) NOT NULL DEFAULT '',
`pstOrder` int(11) DEFAULT NULL,
`Units` decimal(10,2) DEFAULT NULL,
`Rate` decimal(10,4) DEFAULT NULL,
`Total` decimal(10,2) DEFAULT NULL,
`YTD` decimal(10,2) DEFAULT NULL,
`Nontaxable` varchar(1) DEFAULT NULL,
`UserDefInt1` int(11) DEFAULT NULL,
`UserDefDec1` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`PayslipTranID`,`PayslipID`,`Type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
【问题讨论】:
-
还可以共享表的表结构。
temp_payslips和temp_paysliptrans... 也许我明白然后希望您尝试从 xml 导入。第二个 IMPORT 查询很清楚您想要从元素标签加载数据..第一个 IMPORT 查询不是很清楚.. -
我已经为 2 个表添加了 Create SQL。