bcp error: Text column data incomplete and Invalid character value for cast specification
bcp error: Text column data incomplete and Invalid character value for cast specification
我有一些 CSV 文件,我想将其加载到数据库中 table,如下所示
DB TABLE
CREATE TABLE [EVT_STREAM].[Event](
[SystemName] [varchar](25) NOT NULL,
[Router] [varchar](128) NULL,
[Event] [nvarchar](max) NULL,
[ReceivedAt] [datetime] NOT NULL,
[InsertedAt] [datetime] NOT NULL
)ON [PRIMARY]
CSV文件内容如下
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 260, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 66, 'event_string': 'STERILE_ADAPTER_PARTIAL_BEGIN', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 0, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 9042, 'event_string': 'SA_SW2_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 260, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 66, 'event_string': 'STERILE_ADAPTER_PARTIAL_BEGIN', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 0, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 9040, 'event_string': 'SA_SW1_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:02|2021-06-25-18:05:02
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 100, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 63, 'event_string': 'STERILE_ADAPTER_ON', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:03|2021-06-25-18:05:03
TEST_1|server|{'message_type': 0, 'rsdb': {'array_index': 0, 'data_id': 162, 'data_id_string': 'SUDB_PSC', 'key': 3067, 'key_index': 3, 'key_string': 'SUDB_KEY_PSC_USM_STERILE_ADAPTER_ON', 'new_value': 1, 'old_value': 0, 'rsdb_id': 268521760}}|2021-06-25-18:05:04|2021-06-25-18:05:04
TEST_1|server|{'message_type': 32, 'snapshot_kk': {'snapshot_data': [53563, 53563], 'snapshot_kk_entry': [{'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}, {'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}], 'snapshot_kk_hdr': {'gmt_timestamp': 1563473826, 'manip_bitfield': 543, 'mid': 0, 'psc_model_type': 0, 'snapshot_session': 9, 'ss_timestamp': 53563, 'ssc1_model_type': 1, 'ssc2_model_type': 0, 'table_idx': 0, 'trigger': 1, 'trigger_mid': 3, 'trigger_str': 'SNAPSHOT_TRIGGER_STERILE_ADAPTER_ON'}}}|2021-06-25-18:05:04|2021-06-25-18:05:04
TEST_1|server|{'message_type': 32, 'snapshot_kk': {'snapshot_data': [53563, 53563], 'snapshot_kk_entry': [{'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}, {'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}], 'snapshot_kk_hdr': {'gmt_timestamp': 1563473826, 'manip_bitfield': 543, 'mid': 0, 'psc_model_type': 0, 'snapshot_session': 9, 'ss_timestamp': 53563, 'ssc1_model_type': 1, 'ssc2_model_type': 0, 'table_idx': 1, 'trigger': 1, 'trigger_mid': 3, 'trigger_str': 'SNAPSHOT_TRIGGER_STERILE_ADAPTER_ON'}}}|2021-06-25-18:05:05|2021-06-25-18:05:05
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 916833, 'a1': 916839, 'a2': 808385, 'a3': 16, 'event': 9040, 'event_string': 'SA_SW1_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:06|2021-06-25-18:05:06
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 100, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 63, 'event_string': 'STERILE_ADAPTER_ON', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:06|2021-06-25-18:05:06
BCP命令如下错误
bcp EVT_STREAM.Event in fcboqgiuny.csv -S sw2sql01.dv.local,1517 -U appdbowner -P appdbowner1 -t "|" -c
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Text column data incomplete
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
BCP copy in failed
谁能帮我看看我错过了什么?
问题出在您的日期时间字段中,即 csv 文件中的最后两个字段。
您应该删除日期和时间之间的破折号,并在其位置插入一个 space。
例如在你的第一行中改变这个
2021-06-25-18:05:01|2021-06-25-18:05:01
至此
2021-06-25 18:05:01|2021-06-25 18:05:01
我有一些 CSV 文件,我想将其加载到数据库中 table,如下所示
DB TABLE
CREATE TABLE [EVT_STREAM].[Event](
[SystemName] [varchar](25) NOT NULL,
[Router] [varchar](128) NULL,
[Event] [nvarchar](max) NULL,
[ReceivedAt] [datetime] NOT NULL,
[InsertedAt] [datetime] NOT NULL
)ON [PRIMARY]
CSV文件内容如下
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 260, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 66, 'event_string': 'STERILE_ADAPTER_PARTIAL_BEGIN', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 0, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 9042, 'event_string': 'SA_SW2_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 260, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 66, 'event_string': 'STERILE_ADAPTER_PARTIAL_BEGIN', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:01|2021-06-25-18:05:01
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 0, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 9040, 'event_string': 'SA_SW1_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:02|2021-06-25-18:05:02
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 100, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 63, 'event_string': 'STERILE_ADAPTER_ON', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:03|2021-06-25-18:05:03
TEST_1|server|{'message_type': 0, 'rsdb': {'array_index': 0, 'data_id': 162, 'data_id_string': 'SUDB_PSC', 'key': 3067, 'key_index': 3, 'key_string': 'SUDB_KEY_PSC_USM_STERILE_ADAPTER_ON', 'new_value': 1, 'old_value': 0, 'rsdb_id': 268521760}}|2021-06-25-18:05:04|2021-06-25-18:05:04
TEST_1|server|{'message_type': 32, 'snapshot_kk': {'snapshot_data': [53563, 53563], 'snapshot_kk_entry': [{'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}, {'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}], 'snapshot_kk_hdr': {'gmt_timestamp': 1563473826, 'manip_bitfield': 543, 'mid': 0, 'psc_model_type': 0, 'snapshot_session': 9, 'ss_timestamp': 53563, 'ssc1_model_type': 1, 'ssc2_model_type': 0, 'table_idx': 0, 'trigger': 1, 'trigger_mid': 3, 'trigger_str': 'SNAPSHOT_TRIGGER_STERILE_ADAPTER_ON'}}}|2021-06-25-18:05:04|2021-06-25-18:05:04
TEST_1|server|{'message_type': 32, 'snapshot_kk': {'snapshot_data': [53563, 53563], 'snapshot_kk_entry': [{'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}, {'is_float': 0, 'kk_id': 12, 'kk_id_str': 'SYS_CYCLE_COUNT_GBL', 'num_dofs': 1}], 'snapshot_kk_hdr': {'gmt_timestamp': 1563473826, 'manip_bitfield': 543, 'mid': 0, 'psc_model_type': 0, 'snapshot_session': 9, 'ss_timestamp': 53563, 'ssc1_model_type': 1, 'ssc2_model_type': 0, 'table_idx': 1, 'trigger': 1, 'trigger_mid': 3, 'trigger_str': 'SNAPSHOT_TRIGGER_STERILE_ADAPTER_ON'}}}|2021-06-25-18:05:05|2021-06-25-18:05:05
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 916833, 'a1': 916839, 'a2': 808385, 'a3': 16, 'event': 9040, 'event_string': 'SA_SW1_PRESENT', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:06|2021-06-25-18:05:06
TEST_1|server|{'message_type': 2, 'super_evt_non_error': {'a0': 100, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 63, 'event_string': 'STERILE_ADAPTER_ON', 'history_buffer_id': 3, 'history_buffer_string': 'HISTORY_BUFFER_UI_EVT', 'mid': 3, 'mid_string': 'AIM4'}}|2021-06-25-18:05:06|2021-06-25-18:05:06
BCP命令如下错误
bcp EVT_STREAM.Event in fcboqgiuny.csv -S sw2sql01.dv.local,1517 -U appdbowner -P appdbowner1 -t "|" -c
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Text column data incomplete
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][ODBC Driver 17 for SQL Server]Invalid character value for cast specification
BCP copy in failed
谁能帮我看看我错过了什么?
问题出在您的日期时间字段中,即 csv 文件中的最后两个字段。
您应该删除日期和时间之间的破折号,并在其位置插入一个 space。
例如在你的第一行中改变这个
2021-06-25-18:05:01|2021-06-25-18:05:01
至此
2021-06-25 18:05:01|2021-06-25 18:05:01