简体   繁体   English

SQL 非括号字符的语法

[英]SQL syntax for characters not in brackets

I'm accessing a Microsoft Access database using ODBC.我正在使用 ODBC 访问 Microsoft Access 数据库。

According to the w3schools SQL tutorial , the ANSI-92 wildcard for "any character not in brackets" should be ^ .根据w3schools SQL 教程,“任何不在括号中的字符”的 ANSI-92 通配符应该是^ However, their own example uses the ANSI-89 wildcard !但是,他们自己的示例使用 ANSI-89 通配符! . .

The MSDN documentation is also confusing. MSDN 文档也令人困惑。 The ANSI-92 section shows ^ character, but the example next to it actually uses ! ANSI-92部分显示^字符,但它旁边的示例实际上使用! . . That looks like an error and I've filled out feedback to notify Microsoft.这看起来像是一个错误,我已填写反馈以通知 Microsoft。

What is the correct "any character not in brackets" syntax?什么是正确的“任何不在括号中的字符”语法? And will this apply across multiple databases and access technologies (DAO, ODBC, OleDB, MySQL, etc)?这是否适用于多个数据库和访问技术(DAO、ODBC、OleDB、MySQL 等)?

There is no way to do this across databases.无法跨数据库执行此操作。 SQL supports the LIKE syntax that has exactly two wildcards: SQL 支持恰好有两个通配符的LIKE语法:

  • % matches zero or more characters. %匹配零个或多个字符。
  • _ matches exactly one character. _只匹配一个字符。

One could throw in the \ character to escape wildcards as well.也可以输入\字符来转义通配符。

In addition, SQL Server supports character classes as explained in the tutorial (which seems to be accurate).此外,SQL Server 支持字符类,如教程中所述(这似乎是准确的)。 The only other database that comes to mind that does this is Sybase (which has the same code base).唯一想到的其他数据库是 Sybase(它具有相同的代码库)。 MS Access just has a bastardized version with special characters. MS Access 只有一个带有特殊字符的混蛋版本。 It never supported SQL standards in this respect.在这方面,它从未支持 SQL 标准。

Most other databases implement full regular expression support (YAY,).大多数其他数据库都实现了完整的正则表达式支持 (YAY,)。 but their syntax varies by database, So.但它们的语法因数据库而异,所以。 there is not a database-independent way to do what you want.没有一种独立于数据库的方式来做你想做的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM