fetch returns a table full of cells for 'char' values
조회 수: 1 (최근 30일)
이전 댓글 표시
I use fetch to get data from a MS Azure SQL Database into Matlab. My script worked when I last ran it - approximately 10 days ago. In the meanwhile the DB has been updated - the only change were changes in naming of tables and columns.
However, now I get a table where each field that should contain a character arrays, contains a cell. This makes it hard to work with the character arrays.
I tried to set the DB preferences, but it did not change the output.
setdbprefs('DataReturnFormat', 'table');
I also tried to put my simple SQL statement in a file and use runsqlscript instead of fetch - but I still got the char arrays in cells.
conn = database(datasource, username,password);
runsqlscript(conn,mySQLscript.sql)
This is the code I try to run (with some connetion details changed, of course)
conn = database(datasource, username,password);
sqlTest = 'select * from MyTableOfInterest'
conn = database('MyDB','DB_Reader_user','MyPassword','Vendor','MICROSOFT SQL SERVER','Server','myProjectServer.database.windows.net','PortNumber',1433,'AuthType','Server');
dataDB_ids = fetch(conn,sqlTest);
close(conn)
The result looks like this:

I would like to have is the above picture without the curley brackets.
I know I can do that with using for-loops and changing field per field, but there must be a smarter solution. (Especially since I think the the result looked fine last time I ran the script).
Technical details:
MATLAB Version: 9.7.0.1247435 (R2019b) Update 2
Database Toolbox Version 9.2 (R2019b)
Best regards, Sara
댓글 수: 0
답변 (1개)
Harsha Priya Daggubati
2020년 1월 31일
Hi,
Can you check the datatype of the variables present in the table, by making use of the metadata returned by 'fetch'.https://www.mathworks.com/help/database/ug/database.odbc.connection.fetch.html?searchHighlight=fetch&s_tid=doc_srchtitle
You can use setoptions method to specify the type for columns. Refer the link for more details.
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!