Matlab Bulk Insert To SQL Question
显示 更早的评论
Hi,
I have a text file (comma-delimited) and (next-line row delimited) 10 x 116 (116 is the number of columns and were mapped to the corresponding fields/data types in the sql), I am trying to use the Matlab bulk insert, it was ok until I was given a file with NaN instead of Null for numerical data types. How can I handle the NaN values of type float or double from the textfile so that when it is inserted into the database table it is displayed as NULL.
exec(dbconn,['bulk insert ' Table_Name ' from '...
'''temp\FILENAME.txt'' with (fieldterminator = '','', '...
'rowterminator = ''\n'')']);
Thanks.
回答(1 个)
Titus Edelhofer
2014-1-17
0 个投票
Hi,
you need to preprocess the data. So, use fopen/fread to read the full file (or large parts, if the file is huge) into memory as one string. Use strrep to replace the NaN by either nothing (empty) or 'null'. Use fopen/fwrite to write a new file. Read this into sql.
Titus
类别
在 帮助中心 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!