简体   繁体   English

Firebird:使用SQL搜索所有字段?

[英]Firebird: Using SQL to search all fields?

I have a SQL query that is going to be used to search fields that are most likely going to change a lot. 我有一个SQL查询,该查询将用于搜索最有可能发生很大变化的字段。 Ie More fields will be added. 即将添加更多字段。 How can I write a sql query using a simple like that will search across al fields without explicitly specifying the fields? 我该如何使用类似SQL这样的简单查询来编写sql查询,而无需明确指定字段即可在al字段中进行搜索?

Something like: 就像是:

select * from MYTABLE where CONCAT(*) like '%mySearchTerm%';

Is there an easy way to do this? 是否有捷径可寻?

I think the only way in Firebird is to use calculated field which concats the fields you want to search: 我认为Firebird的唯一方法是使用计算字段来合并要搜索的字段:

create table T (
  foo varchar(24) not null,
  bar varchar(24) not null,
  ...
  SearchField varchar(1024) generated always as (foo || '##' || bar)
)

select * from T where SearchField like '%mySearchTerm%';

So each time youre altering the table (adding or dropping an field) you also have to change the calculated field, but the query would remain the same. 因此,每次更改表(添加或删除字段)时,您还必须更改计算出的字段,但查询将保持不变。 But this has some impact on perfomance as you're doing concat you really don't need... 但这会对性能产生一些影响,因为您在进行合并时确实不需要……

If you have much records and fields in the table and need high performance, I suggest you to search about Full Text Index ou Full Text Search for Firebird. 如果表中的记录和字段很多,并且需要高性能,建议您搜索全文索引或Firebird全文搜索。 It is not a native feature. 它不是本机功能。 But there are some third party solutions. 但是有一些第三方解决方案。 See this link: http://www.firebirdfaq.org/faq328/ 看到此链接: http : //www.firebirdfaq.org/faq328/

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

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