SQLite 中是否可以进行 try/catch 类型更新?
UPDATE Table SET Value = 5 WHERE DateTime = '03:42:34';
但有时该 DateTime
并不存在。我想知道是否有任何方法可以让它动态尝试,那么
UPDATE Table SET Value = 5 WHERE DateTime = '03:42:35';
这可能是不可能的,特别是因为 'DateTime` 是一个字符串,但想知道是否有某种方法可以做到这一点。
我曾想过采用 DateTime
的前 7 个字符并进行匹配,但这可能不够精确。
UPDATE Table SET Value = 5 WHERE DateTime = '03:42:34';
Sometimes that DateTime
will not exist, though. I'm wondering if there's any way that I can have it dynamically attempt then
UPDATE Table SET Value = 5 WHERE DateTime = '03:42:35';
This is probably not possible, especially since 'DateTime` is a string, but wondered if there might be some way of doing it.
I had thought of taking the first 7 characters of the DateTime
and having that match, but that's probably not quite precise enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CASE 表达式听起来可以做你想做的事。
http://www.sqlite.org/lang_expr.html
The CASE expression sounds like it could do what you want.
http://www.sqlite.org/lang_expr.html
这是你想要的吗?
Is this what you want?
我以一种简单的方式工作,我觉得自己很愚蠢,因为没有考虑到最初的情况:
UPDATE Table SET Value = 5 WHERE DateTime BETWEEN datetime('2020-03-21 03:42:35', '-1 secondary')和 datetime('2020-03-21 03:42:35', '+1 秒')
I got this working in a straightforward way I feel silly for not thinking of originally:
UPDATE Table SET Value = 5 WHERE DateTime BETWEEN datetime('2020-03-21 03:42:35', '-1 second') and datetime('2020-03-21 03:42:35', '+1 second')