使用資料流程中的資料類型

適用於:SQL Server Azure Data Factory 中的 SSIS Integration Runtime

在 Integration Services 中開發自訂資料流程元件時,您會不斷地處理資料類型、將資料複製到資料流程緩衝區或從其中複製資料,以及轉換值。 在本主題中的資訊可協助您選擇正確的 Integration Services 資料類型,以及正確的處理方法。

將資料插入資料流程

PipelineBuffer 類別提供一系列的 Set 方法,可將資料複製到緩衝區資料行,並提供一系列對應的 Get 方法,可從緩衝區資料行擷取資料。 下表顯示每個 Integration Services 資料類型要使用哪個方法。

資料類型使用的 Set 方法

下表在第一個資料行中列出資料類型,然後列出對應的 SetGet 方法。

資料類型 Set 方法 Get 方法
DT_BOOL SetBoolean GetBoolean
DT_BYTES SetBytes GetBytes
DT_CY SetDecimal GetDecimal
DT_DATE SetDateTime GetDateTime
DT_DBDATE SetDate GetDate
DT_DBTIME SetTime GetTime
DT_DBTIME2 SetTime GetTime
DT_DBTIMESTAMP SetDateTime GetDateTime
DT_DBTIMESTAMP2 SetDateTime GetDateTime
DT_DBTIMESTAMPOFFSET SetDateTimeOffset GetDateTimeOffset
DT_DECIMAL SetDecimal GetDecimal
DT_FILETIME SetDateTime GetDateTime
DT_GUID SetGuid GetGuid
DT_I1 SetSByte GetSByte
DT_I2 SetInt16 GetInt16
DT_I4 SetInt32 GetInt32
DT_I8 SetInt64 GetInt64
DT_IMAGE AddBlobDataAddBlobData GetBlobData
DT_NTEXT AddBlobDataAddBlobData GetBlobData
DT_NULL SetNull 沒有適用於此資料類型的 Get 方法。
DT_NUMERIC SetDecimal GetDecimal
DT_R4 SetSingle GetSingle
DT_R8 SetDouble GetDouble
DT_STR SetString GetString
DT_TEXT AddBlobDataAddBlobData GetBlobData
DT_UI1 SetByte GetByte
DT_UI2 SetUInt16 GetUInt16
DT_UI4 SetUInt32 GetUInt32
DT_UI8 SetUInt64 GetUInt64
DT_WSTR SetString GetString

與 Set 方法搭配使用的資料類型

Set 方法 資料類型
AddBlobDataAddBlobData DT_IMAGEDT_NTEXTDT_TEXT
SetBoolean DT_BOOL
SetByte DT_UI1
SetBytes DT_BYTES
SetDate DT_DBDATE
SetDateTime DT_DATEDT_DBTIMESTAMPDT_DBTIMESTAMP2DT_FILETIME
SetDateTimeOffset DT_DBTIMESTAMPOFFSET
SetDecimal DT_CYDT_DECIMALDT_NUMERIC
SetDouble DT_R8
SetGuid DT_GUID
SetInt16 DT_I2
SetInt32 DT_I4
SetInt64 DT_I8
SetNull DT_NULL
SetSByte DT_I1
SetSingle DT_R4
SetString DT_STRDT_WSTR
SetTime DT_DBTIMEDT_DBTIME2
SetUInt16 DT_UI2
SetUInt32 DT_UI4
SetUInt64 DT_UI8

對應資料流程中的資料類型

當透過轉換將資料從來源移到目的地時,資料流程元件有時必須在 DataType 列舉中所定義 SQL Server Integration Services 類型,以及 System 命名空間中所定義 Microsoft .NET Framework 的受控資料類型之間轉換資料類型。 此外,元件偶爾也必須先將某個 Integration Services 資料類型轉換成其他資料類型,才可將該類型轉換為受控類型。

注意

預設安裝在 C:\Program Files\Microsoft SQL Server\130\DTS\MappingFiles 中的 XML 格式之對應檔案,與本主題所討論的資料類型對應並不相關。 這些檔案會將資料類型從某個資料庫版本或系統,對應到其他資料庫版本或系統 (例如,從 SQL Server 對應至 Oracle),並只可供 [SQL Server 匯入和匯出精靈] 使用。 如需這些對應檔的詳細資訊,請參閱 SQL Server 匯入和匯出精靈

Integration Services 資料類型與 Managed 資料類型之間的對應

BufferTypeToDataRecordTypeDataRecordTypeToBufferType 方法會將 Integration Services 資料類型對應到受控資料類型。

警告

開發人員應該謹慎地使用 PipelineComponent 類別的這些方法,而且可能會想要撰寫自己的資料類型對應方法程式碼,以便能更加符合其自訂元件的獨特需求。 現有方法並未考慮數值的有效位數或小數位數,也未考慮與資料類型本身密切相關的其他屬性。 Microsoft 可能會在後續版本的 Intergration Services 中修改或移除這些方法,或是修改其執行的對應。

下表列出 BufferTypeToDataRecordTypeDataRecordTypeToBufferType 方法如何將各種 Integration Service 資料類型對應至受控資料類型。

Integration Services 資料類型 對應至此 Managed 資料類型
DT_WSTR System.String
DT_BYTES System.Byte 的陣列
DT_DBTIMESTAMP System.DateTime
DT_DBTIMESTAMP2 System.DateTime
DT_DBTIMESTAMPOFFSET System.DateTimeOffset
DT_DBDATE System.DateTime
DT_DBTIME System.TimeSpan
DT_DBTIME2 System.TimeSpan
DT_DATE System.DateTime
DT_FILETIME System.DateTime
DT_NUMERIC System.Decimal
DT_GUID System.Guid
DT_I1 System.SByte
DT_I2 System.Int16
DT_I4 System.Int32
DT_I8 System.Int64
DT_BOOL System.Boolean
DT_R4 System.Single
DT_R8 System.Double
DT_UI1 System.Byte
DT_UI2 System.UInt16
DT_UI4 System.UInt32
DT_UI8 System.UInt64

對應 Integration Services 資料類型以符合 Managed 資料類型

有時資料流程元件必須也先將某個 Integration Services 資料類型轉換到另一個資料類型,才能將該類型轉換為受控類型。 ConvertBufferDataTypeToFitManaged 方法類別會將 Integration Services 資料類型對應至其他可以由 BufferTypeToDataRecordType 方法對應至受控資料類型的 Integration Services 資料類型。

警告

開發人員應該謹慎地使用 PipelineComponent 類別的這些方法,而且可能會想要撰寫自己的資料類型對應方法程式碼,以便能更加符合其自訂元件的獨特需求。 現有方法並未考慮數值的有效位數或小數位數,也未考慮與資料類型本身密切相關的其他屬性。 Microsoft 可能會在後續版本的 Intergration Services 中修改或移除這些方法,或是修改其執行的對應。

下表列出 ConvertBufferDataTypeToFitManaged 方法如何將 Integration Services 資料類型對應至其他 Integration Services 資料類型。

原始的 Integration Services 資料類型 對應至此 Integration Services 資料類型
DT_DECIMAL DT_NUMERIC
DT_CY DT_NUMERIC
DT_DATE DT_DBTIMESTAMP
DT_DBDATE DT_DBTIMESTAMP
DT_FILETIME DT_DBTIMESTAMP
DT_DBTIMESTAMP2 DT_DBTIMESTAMP
DT_DBTIME DT_DBTIME2
DT_BOOL DT_I4
DT_TEXT DT_WSTR
DT_NTEXT DT_WSTR
DT_STR DT_WSTR
DT_IMAGE DT_BYTES

注意

ConvertBufferDataTypeToFitManaged 方法不會傳回 DT_DBTIMESTAMPOFFSET 資料類型的值,而且會發生 UnsupportedBufferDataTypeException。 您必須將 DT_DBTIMESTAMPOFFSET 資料類型轉換為其中一個可以對應至受控資料類型的 Integration Services 日期/時間資料類型。 如需可以對應至受控資料類型的 Integration Services 日期/時間資料類型清單,請參閱上一節<Integration Services 資料類型與 Managed 資料類型之間的對應>中的表格。如需轉換資料類型的詳細資訊,請參閱 Integration Services 資料類型

另請參閱

BufferTypeToDataRecordType
DataRecordTypeToBufferType
ConvertBufferDataTypeToFitManaged
Integration Services 資料類型