I am not able to extract big int from MS sql database using the oledb driver from matlab

조회 수: 3 (최근 30일)
I am not able to extract big int datatype from MS sql database using the oledb driver from matlab. The return type of big int datatype of ms sql is returned as string and not as an integer after the execution of the query.
I do not want to type cast the returned value or use the str2num func .
Request anyone to please help in this regard.

채택된 답변

Ankita Nargundkar
Ankita Nargundkar 2016년 10월 21일
To get the BIGINT data as INT64 into MATLAB you can retrieve the number as string and then use the attached MEX-file below to convert to INT64.
To retrieve the data as text you could consider changing the actual data format in your database or you could simply include a CAST in your query:
>> setdbprefs('DataReturnFormat','cellarray');
>> conn = database('myDatabase','myUser','myPassword');
>> res = exec(conn,'SELECT CAST(col1 AS VARCHAR) FROM myTable');
>> res = fetch(res);
>> data = res.data;
>> longlong = atoi64(data(:,1))
longlong =
12345678901234567
98765432104567895
Compile it using:
>> mex atoi64.c
Before using it.
  댓글 수: 1
denzil fernandes
denzil fernandes 2016년 11월 3일
Hello Ankita,
Here we are doing a datatype conversion after extracting the data from driver. Is it not possible to extract the data in int64 format itself without doing a data type conversion after extraction. Does matlab support int64 format using the oledb driver
Thanks & Regards, Denzil

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

추가 답변 (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