如何引用在更新语句中使用的sqlite db列 [英] How do I reference sqlite db column to use in update statement

查看:73
本文介绍了如何引用在更新语句中使用的sqlite db列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆