How to select all records,that may contain specific value that is known, without referring to specific column in SQL expression?
For instance, i know,that some unknown column holds value ‘xxx’ and there are many columns and records in table.
Thank you.
So, you want to do a Google-like free text search over your database. This can be done but the performance will be Teh Suck! Google is fast because it has indexes on its indexes, duplicate data stores and generally optimizes everything for precisely this kind of search.
Anyway, here is a proof of concept using dynamic SQL and the Oracle data dictionary. Note that I restrict the columns to the type of data I want to search for i.e. strings.
A more robust implementation might need to handle case, whole words, etc. If you’re on 10g or higher then regular expressions could be useful, but combining regex and dynamic SQL is an, er, interesting prospect.
I repeat that performance is going to be Teh Suck! on a large data set. It is virtually impossible to tune, because we cannot index every column, and certainly not to support LIKE or similar fuzzy matches. An alternative approach would be to use XQuery to generate an XML representation of your data and then use Text to index it. Maintaining such a repository would be overhead, but the effort would be a sound investment if you need this functionality of a regular basis, especially in a production environment.
We can conduct a broader search across all the tables we have privileges on by using
all_tab_colsinstead.Obviously we need to prefix the owning schema in the generated statement.