问题:如果fIEld1_spanish不为空,如何仅使用fIEld1_spanish更新fIEld1?如果fIEld2_spanish不为空,我想用fIEld2_spanish更新fIEld2.
谢谢!
解决方法 http://sqlfiddle.com/#!5/58554/1update item_tableset fIEld1 = coalesce(fIEld1_spanish,fIEld1),fIEld2 = coalesce(fIEld2_spanish,fIEld2)
coalesce()函数将返回传递给它的第一个参数,该参数不为null.所以在这种情况下,由于fIEld2_spanish为null,它将fIEld2设置为fIEld2(基本上什么都不做).
要支持空字符串和NulL值,请尝试以下 *** 作:
http://sqlfiddle.com/#!5/b344f/3
update item_tableset fIEld1 = case when coalesce(fIEld1_spanish,'') = '' then fIEld1 else fIEld1_spanish end,fIEld2 = case when coalesce(fIEld2_spanish,'') = '' then fIEld2 else fIEld2_spanish end总结
以上是内存溢出为你收集整理的database – SQLite仅在值不为空时更新列全部内容,希望文章能够帮你解决database – SQLite仅在值不为空时更新列所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)