简体   繁体   English

我可以信任“%”作为SQL通配符

[英]Can I trust in “%” to be the SQL wildcard

Hi there I'm using JPA to query a database and I should do a column like 'whatever%' query. 您好,我正在使用JPA查询数据库,我应该做一个column like 'whatever%'查询的column like 'whatever%'

My DB is currently Mysql so I could do that without problem, but I was wondering if there was somewhere a method to retrieve the Wildcard character of the database. 我的数据库目前是Mysql,所以我可以毫无问题地做到这一点,但我想知道是否有某个方法来检索数据库的通配符。

There's little chance I change the DB but well ... I'm trying to be as generic as possible. 我改变数据库的可能性很小......但我试图尽可能地通用。

So is "%" the only wildcard (not talking about _ ) used, and will forever be ? 那么“%”是唯一使用的通配符(不是在谈论_ ),而且会永远存在吗?

Thanks for info! 谢谢你的信息!

% is ANSI SQL. %是ANSI SQL。 This value isn't configurable in any of the major databases, and as such there is no need for these databases to provide a method to return the wildcard character. 此值在任何主要数据库中都不可配置,因此这些数据库不需要提供返回通配符的方法。

This should only be a concern if you think you might migrate to a non-ANSI SQL database, such as MS Access, which uses a * as a wildcard character. 如果您认为可以迁移到非ANSI SQL数据库(例如MS Access,它使用*作为通配符),那么这应该只是一个问题。

If is is a possibility, I'd suggest making the wildcard character configurable in your application, and provide a variable containing the wildcard character instead of a hard-coded character. 如果是可能的话,我建议在您的应用程序中配置通配符,并提供包含通配符而不是硬编码字符的变量。

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

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