필터 지우기
필터 지우기

Handling Quotation when Inserting Table to SQL Database

조회 수: 1 (최근 30일)
Ledger Yu
Ledger Yu 2018년 6월 13일
답변: Ledger Yu 2018년 6월 13일
I have a table that looks like this:
id = [1 2]';
name = {'abc', 'a''bc'}';
data = table(id,name);
disp(data)
Now when I tried to insert this table to a MS SQL database, I got this error:
hdr = {'id','name'};
insert(conn, 'userName.dbName.tableName', hdr, data)
Apparently it's because of the single quotation mark in the second row of the table, as I can see the first row got inserted successfully.
Thoughts?
  댓글 수: 2
Kojiro Saito
Kojiro Saito 2018년 6월 13일
I cannot reproduce this issue in MATLAB R2018a with SQL Server 2016. Which MATLAB and SQL Server versions are you using?
Ledger Yu
Ledger Yu 2018년 6월 13일
Matlab 2013b and SQL Server 2008 R2. Anyway I figured out where the issue lies. Please see my own comment.

댓글을 달려면 로그인하십시오.

채택된 답변

Ledger Yu
Ledger Yu 2018년 6월 13일
The issue appears to be that when Matlab sends data to SQL, it is already an "interpreted" version. So it was a single quotation that SQL receives, not a double one which I passed as an input to "data".
This runs successfully:
id = [1 2]';
name = {'abc', 'a''''bc'}';
data = table(id,name);
insert(conn, 'userName.dbName.tableName', hdr, data)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by