- '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
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Piyush Kumar
on 27 Sep 2024
Edited: Piyush Kumar
on 27 Sep 2024
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 Comments
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!