ssis 转换中文字符乱码_SSIS软件包中的字符映射转换

ssis 转换中文字符乱码

This article explores the Character Map Transformation in SSIS package with available configurations.

本文探讨了具有可用配置的SSIS包中的字符映射转换。

介绍 (Introduction)

In the previous article, we explored SQL Server commands to change text case in the following scenarios.

在上一篇文章中,我们探讨了在以下情况下更改文本大小写SQL Server命令。

  1. Lowercase to Uppercase using SQL UPPER function

    使用SQL UPPER函数将小写字母转换为大写字母
  2. Uppercase to Lowercase with SQL LOWER function

    使用SQL LOWER函数从大写到小写
  3. Change the first character of each word in a string to a capital letter. We do not have any available function in SQL Server to do that. We performed this task using a custom function T-SQL code

    将字符串中每个单词的第一个字符更改为大写字母。 在SQL Server中,我们没有任何可用的功能。 我们使用自定义函数T-SQL代码执行了此任务

As you can see here, we have limited functions in SQL Server to convert the character case transformations. It is possible, but you should be a T-SQL programming expert and able to write complex queries.

如您所见,SQL Server中用于转换字符大小写转换的功能有限。 可以,但是您应该是T-SQL编程专家,并且能够编写复杂的查询。

You might have heard a famous proverb – A FRIEND IN NEED IS A FRIEND INDEED.

您可能已经听过一句著名的谚语- “需要的朋友才是真正的朋友”

You might be thinking about the relationship of this proverb with this article. I use this quote for the true friend of DBA and Developers in SQL Server – SSIS Package. Yes, we can easily do character case transformations using SSIS packages. We use Character map transformation in SSIS package to achieve this task.

您可能正在考虑这个谚语与本文的关系。 我将此报价用于SQL Server – SSIS包中DBA和开发人员的真正朋友。 是的,我们可以使用SSIS包轻松进行字符大小写转换。 我们使用SSIS包中的Character map转换来完成此任务。

Let’s explore this transformation in this article in details.

让我们在本文中详细探讨这种转换。

本文的先决条件 (Pre-requisites for this article)

  • SQL Server instance with integration services

    具有集成服务SQL Server实例
  • SQL Server Data tools

    SQL Server数据工具
  • Sample database – AdventureWorks

    示例数据库– AdventureWorks

In the sample database AdventureWorks, we have the following data in the [ProductDescription] table.

在示例数据库AdventureWorks中,我们在[ProductDescription]表中具有以下数据。

SELECT TOP (10) [ProductDescriptionID]
      ,[Description]
        FROM [adventureworks2014].[Production].[ProductDescription]

Sample data

We will use data in description column as a source in this article.

本文将使用描述列中的数据作为源。

SSIS包中的字符映射转换概述 (Overview of Character map transformation in SSIS package)

In SSIS Toolbox, we have the following Character Map transformation.

在SSIS工具箱中,我们进行以下字符映射转换。

Character Map transformation

In the Character Map, it provides the following mapping operations.

在字符映射表中,它提供以下映射操作。

mapping operations

Let’s get a brief overview of each operations in character map transformation.

让我们简要概述一下字符映射转换中的每个操作。

小写 (Lowercase)

It converts all text into lowercase. It is similar to SQL Lower function. Example: car becomes CAR.

它将所有文本转换为小写。 它类似于SQL Lower函数。 示例:汽车变成汽车。

大写 (Uppercase)

It converts all text into uppercase. It is similar to a SQL UPPER function. Example: CAR becomes a car.

它将所有文本转换为大写。 它类似于SQL UPPER函数。 示例:CAR变成一辆汽车。

字节反转 (Byte reversal)

It reverses the order of byte of Unicode.

它颠倒了Unicode字节的顺序。

平假名 (Hiragana)

It converts Katakana characters to Hiragana characters.

它将片假名字符转换为平假名字符。

  • Katakana and Hiragana both are characters in a Japanese syllabary

    片假名和平假名都是日语音节中的字符
  • In the following image, you can see both characters

    在下图中,您可以看到两个字符

Katakana characters to Hiragana characters

片假名 (Katakana)

It converts Hiragana characters to Katakana characters.

它将平假名字符转换为片假名字符。

一半的宽度 (Half-width)

We use this option to convert full-width character to half-width character. In full-width character, you have the same width for each character and similar to Chinese character. It does not depend upon the character set. Half-width characters occupy half-space compared to full-width characters.

我们使用此选项将全角字符转换为半角字符。 在全角字符中,每个字符的宽度相同,与汉字相似。 它不取决于字符集。 与全角字符相比,半角字符占据一半的空间。

  • Full-width example: full width

    全角示例:full width
  • Half-width example: fullwidth

    半角示例:全角

全屏宽度 (Full width)

This option performs reverse work of the half-width. It coverts half-width characters into full-width character.

此选项执行半角的反向工作。 它会将半角字符转换为全角字符。

语言框 (Linguistic casing)

  • Usually, SQL Server uses system language to insert data into tables. Example: date format. If your system uses date format in US format, SQL also uses the same format by default. We can use Linguistic casing to use other local languages.

    通常,SQL Server使用系统语言将数据插入表中。 示例:日期格式。 如果您的系统使用美国格式的日期格式,则默认情况下,SQL也使用相同的格式。 我们可以使用语言大小写来使用其他本地语言。

简体中文 (Simplified Chinese)

We can use this option to convert traditional Chinese characters to Simplified Chinese characters.

我们可以使用此选项将繁体中文字符转换为简体中文字符。

    • Example: My name is Rajendra becomes 我的名字是拉金德拉 in traditional Chinese

      示例:我的名字叫Rajendra成为我的名字是拉金德拉
    • Example: My name is Rajendra becomes 我的名字是拉金德拉 in simplified Chinese

      示例:我的名字叫Rajendra成为简体中文的我的名字是拉金德拉

Note: I used Google translate to show these conversions.

注意:我使用Google翻译显示了这些转换。

繁体中文 (Traditional Chinese)

It converts simplified Chinese characters to Traditional Chinese characters.

它将简体中文字符转换为繁体中文字符。

  • Example: Converts text (My name is Rajendra) 我的名字是拉金德拉 to 我的名字是拉金德拉

    示例:将文本(我的名字是Rajendra)转换为我的名字是拉金德拉

We can use multiple options for a column using Character Map transformation in SSIS package. There are few exclusions as well.

我们可以使用SSIS包中的Character Map转换为列使用多个选项。 也有一些例外情况。

SSIS软件包中字符映射转换中的排除项 (Exclusion in Character Map Transformation in SSIS package)

The simplest example is lowercase and uppercase. Suppose we used lowercase to convert all characters into lowercase. We should not use an uppercase option in this case as it is opposite to the lowercase option. In the following image from Microsoft docs, you can find mutually exclusive operations.

最简单的示例是小写和大写。 假设我们使用小写字母将所有字符转换为小写字母。 在这种情况下,我们不应使用大写选项,因为它与小写选项相反。 在Microsoft docs的下图中,您可以找到互斥的操作。

Exclusion in Character Map Transformation in SSIS package

在SSIS程序包中配置字符映射转换,用于 (Configure Character Map Transformation in an SSIS package for)

Let’s create an ETL to use Character Map transformation in SSIS package.

让我们创建一个ETL以在SSIS包中使用Character Map转换。

Drag a Data flow task in the control flow area and rename it as Character Map Transformation in SSIS.

将数据流任务拖到控制流区域中,并将其重命名为SSIS中的“角色映射转换”。

Data flow task in SSIS package

In the data flow tab, add an OLE DB source and configure a connection to point our source database Adventureworks. Rename this OLE DB source to ProductDescription.

在数据流选项卡中,添加OLE DB源并配置连接以指向我们的源数据库Adventureworks。 将此OLE DB源重命名为ProductDescription。

Change data access mode to SQL command and specify SQL query in this.

将数据访问模式更改为SQL命令,并在其中指定SQL查询。

Sepcify connection and SQL command

Click on Columns and remove the tick on ProductDescriptionID column. We want source column as description.

单击列,然后删除ProductDescriptionID列上的勾号。 我们希望源列作为描述。

Select required column

Join the ProductDescription task to Character Map, as shown below.

将ProductDescription任务加入Character Map,如下所示。

Join the ProductDescription task to Character Map

We need to configure the appropriate options in the Character Map. Double click on it, and it opens the Character map transformation editor. In the transformation editor, it shows you all available columns in the source table. Let’s do the following configurations.

我们需要在字符映射表中配置适当的选项。 双击它,它会打开“角色图转换”编辑器。 在转换编辑器中,它显示源表中所有可用的列。 让我们进行以下配置。

  • Select the column name description in the available input columns table

    在可用的输入列表中选择列名称描述
  • Select destination as New Column. We can replace the existing column as well by selecting option In-place change. It is good to use a new column so that we can compare the original and converted text at one place
  • 选择目标作为新列 。 我们还可以通过选择就地更改选项来替换现有列 最好使用新列,以便我们可以在一个地方比较原始文本和转换后的文本
  • lowercase. We want to convert all text into a lower case character 小写。 我们希望将所有文本转换为小写字符
  • In the output alias, we can specify the name of a new column after case conversion. I specified the new column as Description_new

    在输出别名中,我们可以指定大小写转换后新列的名称。 我将新列指定为Description_new

Select the operation and new column name

You can add an OLE DB destination to get the data into a SQL Server table. For this demo, we want to view the behavior of Character map Transformation in SSIS package. Let’s add a SQL multicast and join it with the character map as shown below.

您可以添加OLE DB目标以将数据获取到SQL Server表中。 对于此演示,我们想查看SSIS包中的Character map Transformation的行为。 让我们添加一个SQL多播并将其与字符映射表连接起来,如下所示。

Add SQL Multicast operator

Right-click on the arrow between Character Map and Multicast and enable data viewer. You can view the data after the character map transformation using this data viewer.

右键单击“字符映射”和“多播”之间的箭头,然后启用数据查看器。 您可以使用此数据查看器在字符映射转换后查看数据。

enable data viewer

You can see the following symbol on the arrow for data viewer.

您可以在数据查看器的箭头上看到以下符号。

data viewer symbol

Execute the SSIS package from the Start button or press F5. In the data viewer, you can see column description (original) and description_new(new) in lowercase. All characters in description_new column are in lowercase.

从“开始”按钮执行SSIS程序包或按F5。 在数据查看器中,您可以以小写形式查看列描述(原始)和description_new(新)。 description_new列中的所有字符均为小写。

Character map transformation output as lowercase

Let’s try a few other operations as well. We cannot do this while the package is executing. First, Stop the SSIS package execution (press Shift + F5) and change the operation as Uppercase as shown in following the image.

我们也尝试其他一些操作。 程序包执行时我们无法执行此操作。 首先,停止执行SSIS包(按Shift + F5),然后将操作更改为大写,如下图所示。

Change operation as Uppercase

Re-execute the package, and it converts Uppercase operation for the input data. In the output, you can see all the characters in uppercase.

重新执行该程序包,然后它将大写操作转换为输入数据。 在输出中,您可以看到所有大写字符。

Character map output as Uppercase

Let’s change the operation to Full Width and observe the output.

让我们将操作更改为“ 全宽”并观察输出。

Change operation as full width

Click Ok and execute the SSIS package. It changes the characters font and spacing, as shown below.

单击“确定”并执行SSIS包。 它将更改字符的字体和间距,如下所示。

Character map output as Full width

Select multiple options as lowercase and uppercase

As highlighted earlier, we cannot use two operations that are not compatible with each other. For example, let’s select both lowercase and uppercase operations together, and you get the following error message.

如前所述,我们不能使用两个互不兼容的操作。 例如,让我们同时选择小写和大写操作,您会收到以下错误消息。

Select multiple options in character transformation

Similarly, we cannot use Uppercase and half-width operation together on the same column. You can refer the table shown in the above section for the mutually exclusive operations.

同样,我们不能在同一列上同时使用大写和半角运算。 您可以参考上一节中显示的表进行互斥操作。

Select multiple options as uppercase and half-width

结论 (Conclusion)

In this article, we explored Character Map Transformation in SSIS package to convert the case of the characters using SSIS. You can easily change the configuration from the available operations and get the desired output.

在本文中,我们探索了SSIS包中的字符映射转换,以使用SSIS转换字符的大小写。 您可以轻松地从可用操作中更改配置并获得所需的输出。

翻译自: https://www.sqlshack.com/character-map-transformation-in-ssis-packages/

ssis 转换中文字符乱码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、“01 参考资料列表”文件夹——该文件夹包含一个名为“参考资料列表.doc”的文档,文档列出了本次考核所涉及到的五部分内容(SQL管理及T-SQLSSIS及SSAS、网络及硬件、Oracle及DB2,其他)的知识点和考查点,以及为了学习这些知识需要阅读的参考资料清单。 2、“02 参考资料内容”文件夹——包含了“参考资料列表.doc”描述的参考资料文档。包括:“01 sql_ox.pdf”、“02 SQL21天自学通.pdf”、“03 SSIS&SSAS 参考资料.doc”、“04 oracle&DB2 参考资料.doc”、“05 网络及硬件 参考资料.doc” 3、“03 入门考试题&答案”文件夹——包括入门考试的考题和答案。此目录下共包含3个文件: a、“01 代理培训考试题.doc”文档,包括本次考试的习题和标准答案(不包括BI上机题的答案和简答题windows防火墙配置的答案) b、“NorthWind.bak”,一个数据库备份文件,用户在进行BI部分的上机测试时,需要利用此数据库备份文件进行数据库的恢复操作。 c、“03 BI考试题答案.rar”压缩文件,是关于BI上机测试部分的标准答案。解压缩后包括四个文件夹: “01 SSIS” 文件夹,为数据加工用例。 “02 SSAS” 文件夹,为多维数据用例。 “03 数据库备份”文件夹,是构建好的SSIS和SSAS 数据库备份文件。 “04 OLAP展现”文件夹,包含“OLAP图.xls”Excel文件,是多维数据在Excel的展现效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值