if 0<(select COUNT(*) from Repetition where (Word='behnam' and topic='mine'))begin update Repetition set Counts=1+ (select Counts from Repetition where (Word='behnam' and topic='mine'))endelsebegin insert Repetition(Word,topic,Counts)values('behnam','mine',1)end
它说“IF附近的语法错误”
我该如何解决这个问题
Insetad,查看ERIC B关于另一个thread的建议.你实际上是在做一个UPSERT(如果记录存在则更新,如果不存在则INSERT). Eric B.有一个很好的例子,说明如何在sqlite语法中使用sqlite中的“INSERT OR REPLACE”功能.基本上,你做的事情如下:
INSERT OR REPLACE INTO Repetition (Word,Counts) VALUES ( 'behnam',coalesce((select Counts + 1 from Repetition where Word = 'behnam',AND topic = 'mine),1) )总结
以上是内存溢出为你收集整理的SQLite中的IF语句:更新还是插入?全部内容,希望文章能够帮你解决SQLite中的IF语句:更新还是插入?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)