SQLite中的IF语句:更新还是插入?

SQLite中的IF语句:更新还是插入?,第1张

概述我无法使用SQLite运行此查询 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='min 我无法使用sqlite运行此查询
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附近的语法错误”
我该如何解决这个问题

sqlite没有IF语句( see the list of supported queries)

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语句:更新还是插入?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1178652.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存