如何引用在更新语句中使用的sqlite db列 [英] How do I reference sqlite db column to use in update statement
问题描述
我正在尝试更新android sqlite数据库中的datetime列,以使用国际日期格式(yyyy-mm-dd)而不是当前格式(mm/dd/yyyy
).我想使用sqlite date()函数重新设置列的当前值.我以为它会像下面这样简单:
I am trying to update a datetime column in an android sqlite db to use international date format (yyyy-mm-dd) instead of the current format (mm/dd/yyyy
). I want to use the sqlite date() function to reformat the current value of the column. I thought it would be as simple as the following:
update tblename set thedate = date(thedate)
但以上操作无效.
我该如何编写sql语句来完成此任务?
How would i write the sql statement to accomplish this?
谢谢 帕特里克
推荐答案
DATE()无法理解您的旧日期格式.
DATE() doesn't understand your old date format.
以下应能工作:
UPDATE tblname SET thedate = substr(thedate, 7, 4) || '-' || substr(thedate, 1, 2) || '-' || substr(thedate, 4, 2);
这篇关于如何引用在更新语句中使用的sqlite db列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!