Update equivalent WHERE '1' = '1'

When dynamically creating sentences WHEREfor my sql, I like hard-coding WHERE '1' = '1'in sql, so I don’t need to keep track of whether to add ANDto each next sentence. This is well documented in many places, for example, this question is about using stackoverflow .

Is there an equivalent template for dynamically creating a proposal SETfor statements UPDATE? I prefer not to keep track of whether I need to tarnish the comma or not. If there are no common solutions, this will be an interaction with the oracle database over jdbc.

EDIT For my specific use case, I will need to dynamically change which columns are set. Thus, any solution requiring the query to contain all the columns set does not go. We have a table with 20 + columns, but only 3 or 4 will change at any given time. We conducted several load tests and found that the only way to achieve performance goals is to simply send the data that needs to be updated. Now I'm just trying to write beautiful code for this.

+4
source share
2 answers

- , , :

UPDATE MyTable
SET
    col1 = CASE ? WHEN 1 THEN ? ELSE col1 END
,   col2 = CASE ? WHEN 1 THEN ? ELSE col2 END
,   col3 = CASE ? WHEN 1 THEN ? ELSE col3 END
WHERE
    ... -- condition goes here

, , , . - , , NULL, .

JDBC, , , , , .

+2

, , .

, , :

UPDATE 
  MY_TABLE
SET
  <if test="xx">  COL1='VAL1',</if>
  ID=ID
where 1=1
  COL1 like 'VAL%';

ID=ID noop.

, " ", .

+1

All Articles