在参数化查询中使用加号连接字符串

Concatenating strings using plus signs in a parameterized query

我想问一下如何在SQL

中实现这样的东西
String updateUserDocs1 = "UPDATE USERDOCS SET VIEW_DOCS = VIEW_DOCS + ' ' + ? WHERE USER_ID = ?";

returns java sql 语法错误。遇到:"WHERE"第1行

该陈述在句法上似乎是正确的。可能是什么问题?

许多 SQL 方言支持 + 运算符的重载以进行字符串连接,但 ANSI SQL 标准字符串连接运算符是 ||.

对于 Derby,代码

sql = "UPDATE USERDOCS SET VIEW_DOCS = VIEW_DOCS + ' ' + ? WHERE USER_ID = ?";
PreparedStatement ps = conn.prepareStatement(sql);

导致以下错误

java.sql.SQLSyntaxErrorException: The '+' operator with a left operand type of 'VARCHAR' and a right operand type of 'CHAR' is not supported.

然而,

sql = "UPDATE USERDOCS SET VIEW_DOCS = VIEW_DOCS || ' ' || ? WHERE USER_ID = ?";
PreparedStatement ps = conn.prepareStatement(sql);

工作正常。