ssis 数据转换_SSIS数据类型:高级编辑器的更改与数据转换的转换

ssis 数据转换_SSIS数据类型:高级编辑器的更改与数据转换的转换ssis数据转换Inthisarticle,IwillfirstgiveanoverviewofSSISdatatypesanddatatypesconversionmethodsandthenIwillillustratethedifferencebetweenchangingthecolumnsdatatypesfrom…

大家好,又见面了,我是你们的朋友全栈君。

ssis 数据转换

In this article, I will first give an overview of SSIS data types and data types conversion methods and then I will illustrate the difference between changing the columns data types from the Source Advanced editor and using Data Conversion Transformation.

在本文中,我将首先概述SSIS数据类型和数据类型转换方法,然后说明从Source Advanced编辑器更改列数据类型与使用数据转换转换之间的区别。

This article is the seventh article in the SSIS feature face to face series, which aims to remove confusion and to illustrate some of the differences between similar features provided by SQL Server Integration Services.

本文是SSIS功能面对面系列文章中的第七篇,该文章旨在消除混淆并说明SQL Server Integration Services提供的相似功能之间的某些区别。

SSIS数据类型 (SSIS Data types)

When handling data using Integration Services Data Flow Task, the source data types are converted into SSIS data types. As an example, string data types are converted into DT_STR, DT_WSTR, DT_TEXT, DT_NTEXT data types.

使用Integration Services数据流任务处理数据时,源数据类型将转换为SSIS数据类型。 例如,字符串数据类型将转换为DT_STR,DT_WSTR,DT_TEXT,DT_NTEXT数据类型。

Microsoft provided very detailed information about SSIS data types and related data types on the different data sources. For more information, you can refer to the following links:

Microsoft在不同的数据源上提供了有关SSIS数据类型和相关数据类型的非常详细的信息。 有关更多信息,您可以参考以下链接:

The SSIS data types were founded to provide a unified set of data types that can handle different types from different sources. On the other hand, these data types have some limitations such as the minimum and maximum allowed values for the decimal data type, more detailed can be found at:

建立SSIS数据类型是为了提供一组统一的数据类型,可以处理来自不同来源的不同类型。 另一方面,这些数据类型有一些限制,例如十进制数据类型的最小和最大允许值,有关更多详细信息,请参见:

数据类型转换方法 (Data Types Conversion Methods)

There are two types of data type conversion:

数据类型转换有两种类型:

  1. Implicit conversion

    隐式转换

  2. Explicit conversion

    显式转换

In this section, I will try to make a quick overview of each type.

在本节中,我将尝试快速概述每种类型。

隐式转换 (Implicit Conversion)

Implicit conversions are not visible to the user. Data types are automatically converted from one data type to another. For example, when a string is compared to an int, the string is implicitly converted to int before the comparison proceeds:

隐式转换对用户不可见。 数据类型会自动从一种数据类型转换为另一种数据类型。 例如,当将一个字符串与一个int比较时,在比较进行之前,该字符串会隐式转换为int:

SELECT * FROM Table WHERE [StringColumn] = [NumericColumn]

In SSIS, implicit conversion can be done using different methods, for example:

在SSIS中,可以使用不同的方法来完成隐式转换,例如:

  • Mapping columns with different data types in the Destination component

    在目标组件中映射具有不同数据类型的列

  • Changing the column data type from Advanced Editor

    从高级编辑器更改列数据类型

  • Using a Script Component

    使用脚本组件

For more information about implicit conversion, you can refer to the following posts on Stack overflow website:

有关隐式转换的更多信息,您可以参考Stack Overflow网站上的以下文章:

显式转换 (Explicit conversion)

Explicit conversions are visible to the user. It is performed using CAST or CONVERT functions or other tools. As an example:

显式转换对用户可见。 它是使用CAST或CONVERT功能或其他工具执行的。 举个例子:

SELECT CAST([NumericColumn] AS Varchar(50)) FROM Table

In SSIS, Explicit conversion can be done using different methods, for example:

在SSIS中,可以使用不同的方法来完成显式转换,例如:

  • Using Data Conversion Transformation

    使用数据转换转换

  • Using Derived Column Transformation

    使用派生列转换

  • (DT_WSTR,50)YEAR(GETDATE())

    (DT_WSTR,50)YEAR(GETDATE())

  • Using a Script Component

    使用脚本组件

In this article, I will not describe the Derived Column Transformation, since it was explained in a previous article in this series: SSIS Derived Column with multiple expression Vs multiple transformation

在本文中,由于本系列的上一篇文章已经解释了派生列转换,所以我将不对其进行描述:具有多个表达式的SSIS派生列与多个转换

隐式转换vs显式转换 (Implicit conversion Vs Explicit conversion)

Each pair of SSIS data types has its own case, you can find a pair that can be converted implicitly and another one that needs an explicit conversion.

每对SSIS数据类型都有其自己的情况,您可以找到一对可以隐式转换的数据对,以及另一个需要显式转换的数据。

Microsoft documentation contains a grid that illustrates which data types can be converted implicitly and which can be converted explicitly. This grid can be applied to SSIS data types since we mentioned in the above documentation that contains each SQL data type and its corresponding SSIS data type:

Microsoft文档包含一个网格,该网格说明可以隐式转换哪些数据类型以及可以显式转换哪些数据类型。 由于我们在上述文档中提到了该网格,因此可以将其应用于SSIS数据类型,其中包含每个SQL数据类型及其对应的SSIS数据类型:

This image shows the sql data types and which types can be implicitly or explicitly converted

数据转换转换 (Data Conversion Transformation)

After describing the different types of conversion, we will give an overview of the Data Conversion Transformation and how it is used to perform data conversion.

在描述了不同类型的转换之后,我们将概述数据转换转换及其如何用于执行数据转换。

Data conversion Transformation is a component used within data flow tasks to convert SSIS data types of input columns and generate new output columns:

数据转换转换是数据流任务中使用的组件,用于转换输入列的SSIS数据类型并生成新的输出列:

This image shows the Data Conversion Transformation decsription from the SSIS tollbox

The Data Conversion Transformation editor is not complicated; it is composed of two main parts:

数据转换转换编辑器并不复杂。 它由两个主要部分组成:

  1. Input columns: This part is to select the columns that we want to convert their data types 输入列:这部分是选择我们要转换其数据类型的列
  2. Data conversion configuration: This part is where we specify the output columns SSIS data types, and other related properties such as:数据转换配置:这部分是我们指定输出列SSIS数据类型以及其他相关属性的地方,例如:
    1. Output Alias: Specify the output column name 输出别名:指定输出列名称
    2. Length: Set the output column length for string data type 长度:设置字符串数据类型的输出列长度
    3. Precision: Set the column precision for numeric data type 精度:设置数字数据类型的列精度
    4. Scale: Set the column scale for numeric data type 比例尺:设置数字数据类型的列比例尺
    5. Code Page: Select the code page for columns of type DT_STR 代码页:为DT_STR类型的列选择代码页
This images shows the data conversion transfomation editor

For more information about handling SSIS data types and Data Conversion Transformation, you can refer to the following official documentation:

有关处理SSIS数据类型和数据转换转换的更多信息,您可以参考以下官方文档:

从高级编辑器更改数据类型 (Changing Data type from Advanced Editor)

Another method to convert data types is changing the data types from the source component. To open advanced editor, right-click on the source component and click on Show Advanced Editor option:

转换数据类型的另一种方法是更改​​源组件中的数据类型。 要打开高级编辑器,请右键单击源组件,然后单击“ 显示高级编辑器”选项:

This image shows how to open the source advanced editor to change the SSIS data types of the columns

Note that when using flat file connections, you can change the SSIS data types from the flat file connection manager rather than using source advanced editor.

请注意,使用平面文件连接时,可以从平面文件连接管理器而不是源高级编辑器更改SSIS数据类型。

In the Advanced Editor dialog, go to the Input and Output Properties tab:

在“高级编辑器”对话框中,转到“ 输入和输出属性”选项卡:

This image shows the Input and Output properties tab in the source advanced editor

As shown in the image above, in the Inputs and Outputs tree view, under the Source Output node, you will see two nodes:

如上图所示,在“输入和输出”树视图的“源输出”节点下,您将看到两个节点:

  • External Columns: represent the metadata of external data sources 外部列:代表外部数据源的元数据
  • Output Columns: represent the metadata of the columns used within the data flow task 输出列:表示数据流任务中使用的列的元数据

When you expand any of these nodes, you can select any column and change its SSIS data type as shown in the image below:

展开任何这些节点时,可以选择任何列并更改其SSIS数据类型,如下图所示:

This image shows how to change the SSIS data types of the columns using the advanced editor

讨论与结论 (Discussion and conclusion)

When you change a column data type using a data conversion transformation, or a derived column then you are performing a CAST operation which means an explicit conversion. While when you change the SSIS data types from the advanced editor, you are forcing the SSIS components to read the column as a different data type which means you are performing an implicit conversion.

当您使用数据转换转换或派生列更改列数据类型时,您将执行CAST操作,这意味着显式转换。 从高级编辑器更改SSIS数据类型时,您将强制SSIS组件将列读取为另一种数据类型,这意味着您正在执行隐式转换。

There are many factors that you have to check before deciding which approach you have to use:

在决定必须使用哪种方法之前,必须检查许多因素:

  • The logic you are implementing: Data conversion may be needed only at a specific point of the package execution, which means that you have to use a data conversion transformation. While if the data source column contains values stored in a wrong data type, you can use the advanced editor to change it back (Example: Excel text column that contains Numeric data) 您要实现的逻辑:仅在包执行的特定时间才需要数据转换,这意味着您必须使用数据转换转换。 如果数据源列包含存储在错误数据类型中的值,则可以使用高级编辑器将其改回(例如:包含数字数据的Excel文本列)
  • The source and desired SSIS data types: As shown in the data conversion grid above, not all data types can be converted implicitly 源和所需的SSIS数据类型:如上面的数据转换网格中所示,并非所有数据类型都可以隐式转换
  • Error handling logic: For example, if you are looking to get all values that cannot be converted, using a data conversion transformation may be more adequate since the error thrown are only related to conversion task, while source component may throw a different type of error which require a more generic error handling 错误处理逻辑:例如,如果要获取所有无法转换的值,则使用数据转换转换可能会更合适,因为抛出的错误仅与转换任务有关,而源组件可能会抛出不同类型的错误需要更通用的错误处理

Based on what we mentioned above, you have to choose which type of conversion you should go with based on the SSIS data types you are working with and what is the logic you have to implement within your data flow.

基于上面提到的内容,您必须根据正在使用的SSIS数据类型以及在数据流中要实现的逻辑来选择应该进行哪种转换。

目录 (Table of contents)

SSIS OLE DB Source: SQL Command vs Table or View
SSIS Expression Tasks vs Evaluating variables as expressions
SSIS OLE DB Destination vs SQL Server Destination
Execute SQL Task in SSIS: SqlStatementSource Expressions vs Variable Source Types
Execute SQL Task in SSIS: Output Parameters vs Result Sets
SSIS Derived Columns with Multiple Expressions vs Multiple Transformations
SSIS Data types: Change from the Advanced Editor vs Data Conversion Transformations
SSIS Connection Managers: OLE DB vs ODBC vs ADO.NET
SSIS Flat Files vs Raw Files
SSIS Foreach Loop vs For Loop Container
SSIS: Execute T-SQL Statement Task vs Execute SQL Task
SSIS OLE DB来源:SQL命令与表或视图
SSIS表达式任务与将变量作为表达式求值
SSIS OLE DB目标与SQL Server目标
在SSIS中执行SQL任务:SqlStatementSource表达式与可变源类型
在SSIS中执行SQL任务:输出参数与结果集
具有多个表达式与多个转换的SSIS派生列
SSIS数据类型:高级编辑器的更改与数据转换的转换
SSIS连接管理器:OLE DB与ODBC与ADO.NET
SSIS平面文件与原始文件
SSIS Foreach循环与For循环容器
SSIS:执行T-SQL语句任务与执行SQL任务

翻译自: https://www.sqlshack.com/ssis-data-types-change-from-the-advanced-editor-vs-data-conversion-transformations/

ssis 数据转换

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/162184.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • windows磁盘阵列[通俗易懂]

    windows磁盘阵列[通俗易懂]磁盘阵列磁盘有两个参数:容量,速度。笔记本最高转速5400转每分台式机最高转速7200转每分1.什么是RAIDRAID全称:RemdundantArrayofinexpensivesDisks廉价冗余磁盘阵列,通过对块磁盘组成一种模式,来提高吞吐量和可靠性2.磁盘阵列功能整合闲置磁盘空间提高磁盘读取文件提高容错功能磁盘阵列的…

  • FIR 带通滤波器参数设计流程

    FIR 带通滤波器参数设计流程假设有一段10kHz的语言,现需要对2~3kHz之间的语言信号进行提取,要求1.5kHz及3.5kHz以上的频率需要有40dB的衰减1、求数字频率指标通带下边频:wpl=2∗π∗fpl/fs=0.4πw_{pl}=2*\pi*f_{pl}/f_s=0.4\piwpl​=2∗π∗fpl​/fs​=0.4π通带上边频:wph=2∗π∗fph/fs=0.6πw_{ph}=2*\pi*f_{ph}/f_s=0.6\piwph​=2∗π∗fph​/fs​=0.6π下阻带上变频:wsl=2∗π∗fsl

  • 数仓搭建DWD层

    数仓搭建DWD层尚硅谷电商数仓DWD层

  • restful接口定义_主板上的spi接口接什么

    restful接口定义_主板上的spi接口接什么由于在实际项目中碰到的restful服务,参数都以json为准。这里我获取的接口和传入的参数都是json字符串类型。发布restful服务可参照文章http://www.cnblogs.com/jav

  • python无限锁屏「建议收藏」

    python无限锁屏「建议收藏」无限锁屏fromctypesimport*#可以利用python去调用dll动态库的包可以与c混编importtime#无限锁屏,利用python死循环deflock_windows(): whileTrue: #调用系统底层api,载入依赖库,系统运行时所需要的核心代码 user32=windll.LoadLibrary(‘user32.dll’…

  • shell脚本export变量只限脚本内么_shell脚本调用oracle存储过程

    shell脚本export变量只限脚本内么_shell脚本调用oracle存储过程shell脚本中export命令未生效,原因详解问题:我有一个脚本,脚本中有如下一条语句exportfdu=“dufan”用sh运行脚本后,在当前shell利用命令env查看环境变量,但是却没有fdu变量,难道是因为我的export语句没有生效?解决结果:脚本中的export一定是生效的利用source执行脚本,在当前shell即可查看到fdu环境变量。这个问题涉及了三个知识点:变量(环境变量、自定义变量)父进程与子进程脚本的执行方式什么是变量?变量的分类?1.

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号