- 'select * from table1 where ImageName="' is one part of the string.
- q is another part, which is the variable holding your value.
- '"' is the final part of the string.
Error: Too many input arguments while executing a database query
8 次查看(过去 30 天)
显示 更早的评论
Hi i am trying to execute a Sql query in matlab. The sql uses select command for selecting a particular row using a columname which matches a value that is stored in variable like the following: q=value;%computed value. conn1=database('Dbname','',''); fna=exec(conn1,'select * from table1 where ImageName="',q,'"'); fna=fetch(fna); fda=fna.data;
When i execute this , i get an error : Error using ==> database.exec Too many input arguments.
0 个评论
回答(1 个)
Piyush Kumar
2024-9-27
编辑:Piyush Kumar
2024-9-27
The error you are getting is because of the way you’re trying to construct the SQL query string.
fna=exec(conn1,'select * from table1 where ImageName="',q,'"');
This statement is not correct because it splits the query into multiple parts, which causes the "Too many input arguments" error.
You need to combine these parts into a single string before passing it to the exec function.
q = value; % computed value
conn1 = database('Dbname', '', '');
query = sprintf('select * from table1 where ImageName="%s"', q);
fna = exec(conn1, query);
fna = fetch(fna);
fda = fna.Data;
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!