在Talend中获得TMSSqlRow的输出[英] Get output of TMSSqlRow in Talend

本文是小编为大家收集整理的关于在Talend中获得TMSSqlRow的输出的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我想通过tmssqlrow获得影响/删除/更新的行的数量.

这是工作的方式:

在此处输入图像说明

文件使用包含大量SQL语句,例如删除...插入...更新... 每行都是";"

分开的

但是,现在,我想获得每个语句的结果(x行更新,例如在管理工作室中显示结果).

当我转到tmssqlrow的"高级设置"选项卡时,我选择"传播Query's RecordSet",然后选择我创建之前创建的列(对象类型).

在执行时,我有一个错误:

executeQuery方法必须返回结果集.

那么,我如何获得每个语句的结果并在数据库/文件中插入它?

推荐答案

必须将选项"传播查询的记录集"与TPARSERECORDSET结合使用,以便从返回的记录集中提取信息.但是,这是不够的:您必须明确编写查询才能返回已更新/删除的记录数.

这是我所做的:

在此处输入图像描述

我的tjdbcrow(与tmssqlrow相同)查询看起来像这样(请注意,在更新查询之前我必须如何添加'set nocount on',然后'select @@ rowcount'之后)

)

>

在此处输入图像描述

tparseRecordSet检索列结果集的行数(nblines是我的rowcount的别名)

在此处输入图像描述

其他推荐答案

如果需要影响的行数,则更好的选择是使用可以更新,插入或删除行的TMSSSQLOUTPUT组件.执行后,该组件提供了全局变量,以显示由操作影响多少行.

((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE")) 
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_UPDATED"))   
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_INSERTED"))    
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_DELETED"))

本文地址:https://www.itbaoku.cn/post/1719848.html

问题描述

I would like to get the number of row affected / deleted / updated with a TMSSqlRow.

Here is how the job is:

enter image description here

the file use contains a lot of sql statement like DELETE ... INSERT ... UPDATE... each row are separate by ";"

But now, I would like to get result of each statement (x rows updated, like results are display in management studio).

When I go to "advanced settings" tab of tmssqlrow, I select " Propagate QUERY's recordset" and select a column I created before (Object Type).

On execution, I have this error:

The executeQuery method must return a result set.

So, how I can get the result of each statement and insert it (by example) in a database / file?

推荐答案

The option "Propagate QUERY's recordset" must be used in combination with a tParseRecordSet in order to extract info from the returned recordset. However, that is not sufficent: you must explicitly write the query to return the number of records updated/deleted.

Here's what I did:

enter image description here

My tJDBCRow (same as tMSSqlRow) query looks like this (notice how I had to add 'set nocount on' before the update query, and 'select @@rowcount' after)

enter image description here

tParseRecordSet retrieves the number of lines from the column resultset (nbLines is the alias of my rowcount)

enter image description here

其他推荐答案

If you need the number of rows affected, a better option is to use the tMSSqlOutput component which can update,insert or delete rows. After execution, the component provides global variables to show how many rows were affected by the operation.

((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE")) 
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_UPDATED"))   
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_INSERTED"))    
((Integer)globalMap.get("tMSSqlOutput_1_NB_LINE_DELETED"))