【发布时间】:2011-12-13 06:48:09
【问题描述】:
我无法使用 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'))
end
else
begin
insert Repetition(Word,Topic,Counts)values('behnam','mine',1)
end
它显示“IF 附近的语法错误” 我该如何解决这个问题
【问题讨论】:
-
只要使用事务(或其他原子保证),程序-
if始终可以在客户端完成。无论如何,这是一个“upsert”,请参阅SQLite - UPSERT not INSERT or REPLACE - 特别是 Eric B 的回答......请注意使用coalesce作为“有限的 if”。 -
SQLite 不支持
IF ELSE END子句,对吧?您是在问是否可以在 SQLite 中实现这一点? SQLite 支持CASE的一些类似 if 的功能,但我认为它不会解决您的问题。 stackoverflow.com/questions/1294619/…
标签: sql if-statement sqlite upsert