big_in | R Documentation |
In Oracle, IN statements are limited to 1000 elements. When dynamically extracting data based on values a dataframe, it's pretty easy to exceed this limit. This function converts huge vectors into a format that Oracle can handle, returning many more than 1000 results.
big_in(vec = NULL, vec.field = NULL, isStrings = FALSE)
vec |
The default value is |
vec.field |
The default value is |
isStrings |
The default value is |
This returns a (potentially really long) valid IN string that can be included in a SQL query as a WHERE condition. It must be
prefaced by "WHERE", or "AND" depending on whether other conditions are present. If vec
has no valid values, the function will return
"1=1"
which will allow SQL statements to run.
The logic for this was stolen from our friends at StackOverflow.com. Specifically, Sergey11g's response to https://stackoverflow.com/questions/400255/how-to-put-more-than-1000-values-into-an-oracle-in-clause
Mike McMahon, Mike.McMahon@dfo-mpo.gc.ca
Other util:
Mode()
,
SQL_in()
,
st_err()
## Not run:
bigVector <- c(1:2000)
raw <- big_in(vec=c(1:2000), vec.field = "field2", isStrings = F)
raw
[1] "('_dOh_', field2) IN (('_dOh_',1),('_dOh_',2),...('_dOh_',2000))
qry <- paste0("SELECT field1, field2
from TABLE
where field1 = 'value'
AND ",big_in(vec=c(1:2000), vec.field = "field2", isStrings = F))
qry
[1] "SELECT field1, field2
from TABLE
where field1 = 'value'
AND ('_dOh_', field2) IN (('_dOh_',1),('_dOh_',2),<...>('_dOh_',2000))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.