sql query find match

3 次查看(过去 30 天)
mark
mark 2015-1-31
hello guys, can you help me? how can i prevent adding same information in the database using sql query?
this is my code
cname= get(c_name,'string');
conn = database('mydatabase_2','','')
curs = exec(conn,'select * from db1');
curs = fetch(curs);
curs.Data
sqlquery = ['select * from db1 '...
'where cname = ' cname ];

采纳的回答

Geoff Hayes
Geoff Hayes 2015-2-1
Mark - I suspect that your query could be more like
sqlquery = ['select count(*) from db1 '...
'where cname = ''' cname '''' ];
Note that since the name is a string, you should wrap it in quotes. For example, if cname were Mark, then the above SQL query would become
sqlquery =
select count(*) from db1 where cname = 'Mark'
Note that we use count to determine the number of records in the database that match on the name Mark. You could then execute this query as
curs = exec(conn,sqlquery);
curs = fetch(curs);
curs.Data
where curs.Data would be an integer value that you would use to determine whether you should add the information to the database (if zero) or not (if non-zero).

更多回答(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