逃避的正确方法是什么?使用 Oracle 12c MATCH_RECOGNIZE 时 JDBC PreparedStatement 中的字符?

What's the correct way to escape the ? character in a JDBC PreparedStatement when using Oracle 12c MATCH_RECOGNIZE?

以下查询在 Oracle 12c 中是正确的:

SELECT *
FROM dual
MATCH_RECOGNIZE (
  MEASURES a.dummy AS dummy
  PATTERN (a?)
  DEFINE a AS (1 = 1)
)

但它在 JDBC 中不起作用,因为 ? 字符用作正则表达式字符,而不是绑定变量。

假设我想将 运行 转义为带有绑定变量的 PreparedStatement,那么通过 JDBC 转义 ? 的正确方法是什么?

注:

这在 the documentation 中明确涵盖:

MATCH_RECOGNIZE Clause

The ? character is used as a token in MATCH_RECOGNIZE clause in Oracle Database 11g and later versions. As the JDBC standard defines the ? character as a parameter marker, the JDBC Driver and the Server SQL Engine cannot distinguish between different uses of the same token.

In earlier versions of JDBC Driver, if you want to interpret the ? character as a MATCH_RECOGNIZE token and not as a parameter marker, then you must use a Statement instead of a PreparedStatement and disable escape processing. However, starting from Oracle Database 12c Release 1 (12.1.0.2), you can use the '{\ ... \}' syntax while using the ? character, so that the JDBC driver does not process it as a parameter marker and allows the SQL engine to process it.