ODBC 中的转义序列Escape Sequences in ODBC

许多语言功能(例如外部联接和标量函数调用)通常由 Dbms 实现。A number of language features, such as outer joins and scalar function calls, are commonly implemented by DBMSs. 不过,这些功能的语法通常是特定于 DBMS 的,即使标准语法由各种标准主体定义也是如此。However, the syntaxes for these features tend to be DBMS-specific, even when standard syntaxes are defined by the various standards bodies. 因此,ODBC 定义了包含以下语言功能标准语法的转义序列:Because of this, ODBC defines escape sequences that contain standard syntaxes for the following language features:

  • 日期、时间、时间戳和日期时间间隔文本Date, time, timestamp, and datetime interval literals

  • 标量函数,例如数字、字符串和数据类型转换函数Scalar functions such as numeric, string, and data type conversion functions

  • LIKE 谓词转义符LIKE predicate escape character

  • 外部联接Outer joins

  • 过程调用Procedure calls

ODBC 使用的转义序列如下所示:The escape sequence used by ODBC is as follows:

  
(extension)  
  

备注Remarks

驱动程序会识别和分析转义序列,驱动程序将使用特定于 DBMS 的语法替换转义序列。The escape sequence is recognized and parsed by drivers, which replace the escape sequences with DBMS-specific grammar. 有关转义序列语法的详细信息,请参阅附录 C: SQL 语法中的ODBC 转义序列For more information about escape sequence syntax, see ODBC Escape Sequences in Appendix C: SQL Grammar.

备注

在 ODBC 2 中。x,这是转义序列的标准语法: --(*供应商( 供应_商名称_)、产品(产品名称扩展 ** *)--**In ODBC 2.x, this was the standard syntax of the escape sequence: --(*vendor(vendor-name), product(product-name)extension *)--

除了此语法以外,还定义了简写语法,格式为: {extension}In addition to this syntax, a shorthand syntax was defined of the form: {extension}

ODBC 3 中的。x,转义序列的长格式已被弃用,并且简写形式仅用于。In ODBC 3.x, the long form of the escape sequence has been deprecated, and the shorthand form is used exclusively.

由于转义序列由驱动程序映射到 DBMS 特定的语法,因此应用程序可以使用转义序列或 DBMS 特定的语法。Because the escape sequences are mapped by the driver to DBMS-specific syntaxes, an application can use either the escape sequence or DBMS-specific syntax. 但是,使用特定于 DBMS 的语法的应用程序将无法互操作。However, applications that use the DBMS-specific syntax will not be interoperable. 使用转义序列时,应用程序应确保已关闭 SQL_ATTR_NOSCAN 语句特性,默认情况下它是如此。When using the escape sequence, applications should make sure that the SQL_ATTR_NOSCAN statement attribute is turned off, which it is by default. 否则,转义序列将直接发送到数据源,这通常会导致语法错误。Otherwise, the escape sequence will be sent directly to the data source, where it will generally cause a syntax error.

驱动程序仅支持可映射到基础语言功能的转义序列。Drivers support only those escape sequences that they can map to underlying language features. 例如,如果数据源不支持外部联接,则这两个驱动程序都不会。For example, if the data source does not support outer joins, neither will the driver. 若要确定支持的转义序列,应用程序将调用SQLGetTypeInfoSQLGetInfoTo determine which escape sequences are supported, an application calls SQLGetTypeInfo and SQLGetInfo. 有关详细信息,请参阅下一节、日期、时间和时间戳文本For more information, see the next section, Date, Time, and Timestamp Literals.

本部分包含下列主题。This section contains the following topics.