function with single-string argument, querying sql database
2 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone
Please see below my codes aiming at creating a function which queries data from my database:
function x=getsqldata(var);
Set preferences with setdbprefs.
setdbprefs('DataReturnFormat', 'cellarray');
setdbprefs('NullNumberRead', 'NaN');
setdbprefs('NullStringRead', 'null');
% Set maximum time allowed for establishing a connection.
timeout=logintimeout(10);
%Make connection to database. Note that the password has been omitted.
%Using ODBC driver.
conn = database('odbccalc', 'xx', 'xx');
% Check the database status.
ping(conn);
%Read data from database.
var;
curs = exec(conn, ['SELECT d.ISN , d.Date, d.Px_last FROM tblData d WHERE d.ISN=''',var,'''']);
curs = fetch(curs);
close(curs);
%Assign data to output variable
x = curs.Data;
%Close database connection.
close(conn);
%Clear variables
clear curs conn
While running the function from the command window, I end up with:
getsqldata('CAIXUSD');
Undefined function 'Set' for input arguments of type 'char'.
Thus I wonder if someone could assist. _ In a nutshell, how to make a string variable a valid argument for this function_?
Thanks in advance
ps: the query statements works, I have tested already.
1 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Database Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!