我需要知道是否可以在UPDATE语句中执行此操作:
UPDATE users SET ('field1','field2','field3') VALUES ('value1','value2','value3');
或类似的语法.我正在使用sqlite.
注意:
Nobody understands me,I just want to know if it is possible to SET separate fields to separate values. That’s all.
有一个(标准sql)语法类似于你提出的,但据我所知,只有Postgres已经实现了它:
UPDATE users SET (field1,field2,field3) = ('value1','value3') WHERE some_condition ;
测试(对于infidels):SQL-Fiddle
这也适用于Postgres:
UPDATE users AS u SET (field1,field3) = (f1,f2,f3) FROM ( VALUES ('value1','value3') ) AS x (f1,f3) WHERE condition ;
这在Postgres和sql-Server中有效:
UPDATE users SET field1 = f1,field2 = f2,field3 = f3 FROM ( VALUES ('value1',f3) WHERE condition ;
和@JackDouglas评论说,这在Oracle中有效:
UPDATE users SET (field1,field3) = ( SELECT 'value1','value3' FROM dual ) WHERE condition ;