필터 지우기
필터 지우기

function with single-string argument, querying sql database

조회 수: 2 (최근 30일)
Isma
Isma 2015년 8월 31일
댓글: Walter Roberson 2015년 8월 31일
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.

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