(
@stockType int,
@stockInCode varchar(50),
@createUserName varchar(30),
@createTrueName varchar(30),
@listXml nvarchar(max),
@exceptionMsg nvarchar(4000) output --异常信息,无异常返回的是NULL,有异常返回具体的异常信息
)
AS
DECLARE @xml xml,
@stockInId bigint
BEGIN
BEGIN TRY -- 异常捕获
--必须放在最前面,紧接着事务点
SET @xml = SUBSTRING(@listXml,39,LEN(@listXml)-38);
BEGIN TRAN
INSERT INTO StockIn(stockType,stockInCode,createUserName,createTrueName,isEnd)
VALUES (@stockType,@stockInCode,@createUserName,@createTrueName,'0')
SELECT @stockInId = @@IDENTITY
INSERT INTO StockInDetail (stockInId,goodsId,goodsCode,goodsNum)
SELECT @stockInId, c.doc.value('goodsId[1]','varchar(32)'),
c.doc.value('goodsCode[1]','varchar(50)'),
c.doc.value('num[1]','int')
FROM @xml.nodes('/nodes/node') c(doc);
COMMIT TRAN
END TRY
BEGIN CATCH --异常发生后,相应的事务等处理
--异常信息
set @exceptionMsg = '消息 ' + cast(ERROR_NUMBER() as varchar(50)) + ',级别 '
+ cast(ERROR_SEVERITY() as varchar(50)) + ',状态 '
+ cast(ERROR_STATE() as varchar(50)) + ',过程 ' + 'P_StockInAndStockInDetailAdd'
+ ',第 ' + cast(ERROR_LINE() as varchar(50)) + ' 行'
+ ':' + ERROR_MESSAGE();
ROLLBACK; -- 事务回滚
--异常日志
INSERT INTO Logger(logType, information)
VALUES('ERROR', @exceptionMsg);
END CATCH
END
java端参数转换
String inputXML = XmlConvertUtil.listToXml(productlist);