Wildcard queries

I am trying to do a simple query where I select from one table.
I need to select vins and they are 17 digit vins.
so I need to select where vin position 8 is either an:
'Z', 'K', 0, 3, 'W'
well I'm able to do that with a simple like query.
select * from vehicle where
vin like (('_______Z_________')
or .... etc etc....
but here is my struggle.
I need to select those based on the 8th position of the vin and then I need to select based on each of those where the 3rd position is either a number or a letter.
e.g
select * from vehicle
where vin like ('_______Z_________')
and vin like ('__X______________')
where X is the wildcard which restricts it to either a number or a letter.
Is there a wildcard in oracle sql for just numbers or just letters.
I really don't want to write out all 10 digits from 0 to 9 and all letters from A to Z.

In Oracle 10G you can use regular expressions.
http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm#ADFNS1003
Example(I'm not good with regexps but you can have an idea):
SQL> ed
Wrote file afiedt.buf
  1  with t as(
  2  select '1234567890' as vin from dual union all
  3  select '12$4567Z90' from dual union all
  4  select '1234567K90' from dual union all
  5  select '12A4567X90' from dual union all
  6  select '12B4567W90' from dual union all
  7  select '12Y4567090' from dual union all
  8  select 'abcdefghij' from dual union all
  9  select '1234567390' from dual)
10* select *  from t where regexp_like(vin,'^.{7}[ZK03W]')
SQL> /
VIN
12$4567Z90
1234567K90
12B4567W90
12Y4567090
1234567390
5 rows selected.
SQL> ed
Wrote file afiedt.buf
  1  with t as(
  2  select '1234567890' as vin from dual union all
  3  select '12$4567Z90' from dual union all
  4  select '1234567K90' from dual union all
  5  select '12A4567X90' from dual union all
  6  select '12B4567W90' from dual union all
  7  select '12Y4567090' from dual union all
  8  select 'abcdefghij' from dual union all
  9  select '1234567390' from dual)
10  select *  from t where regexp_like(vin,'^.{7}[ZK03W]')
11* and regexp_like(vin,'^.{2}[A-Z|0-9|a-z]')
SQL> /
VIN
1234567K90
12B4567W90
12Y4567090
1234567390
4 rows selected.Message was edited by:
Delfino Nunez looking for a job

Similar Messages

  • Poor performance using Oracle Text

    We are currently using wildcard queries and we have setup substring or prefix index which is recommended in Oracle's documentation in order to improve performance but we have not seen any improvements. Does anyone have any other recommendations?

    We are currently using wildcard queries and we have setup substring or prefix index which is recommended in Oracle's documentation in order to improve performance but we have not seen any improvements. Does anyone have any other recommendations?

  • Prefix Index and Substing Index not working

    Dear all,
    I'm trying to set the following preference to create my index:
    begin
    ctx_ddl.create_preference('substring_pref', 'BASIC_WORDLIST');
    ctx_ddl.set_attribute('substring_pref','PREFIX_INDEX','TRUE');
    ctx_ddl.set_attribute('substring_pref','PREFIX_MIN_LENGTH',3);
    ctx_ddl.set_attribute('substring_pref','PREFIX_MAX_LENGTH',15);
    ctx_ddl.set_attribute('substring_pref','SUBSTRING_INDEX','TRUE');
    end;
    create index artikel_test_idx
    on artikel_test (art_content)
    indextype is ctxsys.context
    parameters ( 'WORDLIST substring_pref' )
    The index is created sucessfully.
    Here is the data I have in my table:
    ART_INHOUD ART_TITEL ART_CONTENT
    1 Titel1 prion alzheimer
    2 Titel2 prion word1 alzheimer
    3 Titel3 prion word2 word3 alzheimer
    4 Titel4 prion
    5 Titel5 alzheimer
    6 Titel6 alzheimer prion
    7 Titel7 alzheimer word1 prion
    8 Titel8 something else
    9 Titel9 prion alzheimer prion alzheimer
    10 Title10 i am theree
    11 Title11 contract initiation work
    12 Title12 oracle university else
    12 rows selected.
    I test the substring feature by searching for "alz". It should returns me all lines that contains "alzheimer". Am I right? But the result show nothing:
    select art_titel, score(1) as score
    from artikel_test
    where contains (art_content, 'alz', 1) > 0
    no rows selected
    If I search for the entire word, it works:
    select art_titel, score(1) as score
    from artikel_test
    where contains (art_content, 'alzheimer', 1) > 0;
    ART_TITEL SCORE
    Titel9 7
    Titel7 4
    Titel6 4
    Titel5 4
    Titel3 4
    Titel2 4
    Titel1 4
    7 rows selected.
    I look at the table DR$ARTIKEL_TEST_IDX$I and all works are in it:
    TOKEN_TEXT
    ALZ
    ALZH
    ALZHE
    ALZHEI
    ALZHEIM
    ALZHEIME
    ALZHEIMER
    ALZHEIMER
    AM
    CON
    CONT
    CONTR
    CONTRA
    CONTRAC
    CONTRACT
    CONTRACT
    Why there is no result when I search for 'alz'?
    Regards,
    Yanick
    Message was edited by:
    yankee75

    The prefix_index and substring_index do not make the substrings searchable as individual words. They just speed up wildcard queries. If you search for "alt" you will only get rows that have the word "alt" in it. If you search for "alt%" you will get all rows that contain words that begin with "alt". Here are some quotes from the Oracle Text Reference, which is part of the Oracle online documentation:
    "substring_index      Specify TRUE for Oracle Text to create a substring index. A substring index improves left-truncated and double-truncated wildcard queries such as %ing or %benz%. Default is FALSE."
    "prefix_index      Specify TRUE to enable prefix indexing. Prefix indexing improves performance for right truncated wildcard searches such as TO%. Defaults to FALSE."

  • Inconsistencies between CR wildcard (* and ?) and SQL std queries (% and _)

    Certain queries built using Crystal Reports do not return a full result set of data as expected, compared to using standard SQL wildcards in an interactive native SQL tool.
    Does anybody know if any of these are bugs in Crystal Reports?
    See example data and queries with their associated results below.
    Example:
    Table name: customer
          Column definitions:
              lname char(20)
              state char(2)
          Relevant rows from our demo database, queried from the native interactive SQL tool are shown below.  For the purposes of illustration, I modified some of the state fields so that there were examples of 'N ', ' N' and 'N' (space in front of the letter N, space after the letter N, and just the letter N with no spaces). I have also added the single quote characters in the query results for those rows to highlight where the spaces exist or do not exist in the data:
    1 > select id,lname,city,state from customer
          where state like '%N%' or lname like '%en %'
    Col.    id      lname                   city                    state
    [ 1]    101     Devlin                  Rutherford              'N ' < was NJ
    [ 2]    102     Reiser                  New York                'N'  < was NY
    [ 3]    104     Mason                   Knoxville               NN
    [ 4]    105     McCarthy                Carmel                  IN
    [ 5]    107     Colburn                 Raleigh                 NC
    [ 6]    108     Goforth                 Chattanooga             ' N' < was TN
    [ 7]    111     Ricci                   Syracuse                NY
    [ 8]    112     McDonough               Brooklyn Park           MN
    [ 9]    113     Kaiser                  Minneapolis             MN
    [ 10]   114     Chopp                   St Paul                 MN
    [ 11]   115     Phillips                St Paul                 MN
    [ 12]   116     Gugliuzza               Mamaroneck              NY
    [ 13]   118     Sanford                 Raleigh                 NC
    [ 14]   120     Stein                   Elmsford                NY
    [ 15]   121     Elkins                  Carmel                  IN
    [ 16]   129     Fahrvergnugen           Baltimore               MD
    [ 17]   131     Sinnot                  Bohemia                 NY
    [ 18]   132     King                    Fort Wayne              IN
    [ 19]   135     Clarke                  New York                NY
    [ 20]   136     Wooten                  Plymouth                MN
    [ 21]   137     Morfek                  Ft. Wayne               IN
    [ 22]   138     Patoff                  Burlington              ON
    [ 23]   141     Pyper                   Fort Wayne              IN
    [ 24]   147     Lela                    Wood Bridge             NJ
    [ 25]   150     Mason                   Don Mills               ON
    [ 26]   152     Jones                   Austin                  NY
    [ 27]   160     Nette                   Port Washington         NY
    [ 28]   163     Peese                   Mississauga             ON
    [ 29]   165     Mournen                 Ft. Wayne               IN
    [ 30]   169     Terlemezian             Matthews                NC
    [ 31]   177     Zubenko                 Raleigh                 NC
    [ 32]   179     Nguyen                  Miramar                 FL
    [ 33]   180     Peros                   Rochester               NY
    [ 34]   181     Teeven                  Washington              DC
    [ 35]   198     Chen                    San Ramon               CA
    [ 36]   199     Mentary                 Rochester               NY
    [ 37]   202     Murphy                  White Plains            NY
    [ 38]   208     Suess                   Albany                  NY
    [ 39]   221     Johnson                 Santa Fe                NM
    [ 40]   331     Johansen                New Orleans             LA
    [ 41]   550     Antolini                Fargo                   ND
    [ 42]   552     OToole                  Nashville               TN
    [ 43]   665     Thompson                Manchester              NY
    43 rows Affected.
    Several queries perform as expected between Crystal Reports and the native SQL query tool.  However, in some cases, the results are different.  Crystal Reports does not return as much data as the native SQL query tool.  I'm not implying which one is correct, I'm merely stating that there is a difference between them.
    In the cases below, the 'Crystal Reports record selection formula' is obtained by navigating the Crystal Reports menu: Report -> Selection Formulas -> Record...
    Single quotes are not specified in the results below - refer above for the actual data in those rows.
    The following cases are inconsistent between the native SQL query tool and Crystal Reports designer:
    Case 1:
    Length of field to be searched: Short (2 chars)
    Wildcard description: letter 'N' + any single character
    Native interactive SQL query and results:
    1 > select id,lname,city,state from customer where state like 'N_'
    Columns:        id      lname   city    state
    [ 1]    101     Devlin                  Rutherford              N
    [ 2]    102     Reiser                  New York                N
    [ 3]    104     Mason                   Knoxville               NN
    [ 4]    107     Colburn                 Raleigh                 NC
    [ 5]    111     Ricci                   Syracuse                NY
    [ 6]    116     Gugliuzza               Mamaroneck              NY
    [ 7]    118     Sanford                 Raleigh                 NC
    [ 8]    120     Stein                   Elmsford                NY
    [ 9]    131     Sinnot                  Bohemia                 NY
    [ 10]   135     Clarke                  New York                NY
    [ 11]   147     Lela                    Wood Bridge             NJ
    [ 12]   152     Jones                   Austin                  NY
    [ 13]   160     Nette                   Port Washington         NY
    [ 14]   169     Terlemezian             Matthews                NC
    [ 15]   177     Zubenko                 Raleigh                 NC
    [ 16]   180     Peros                   Rochester               NY
    [ 17]   199     Mentary                 Rochester               NY
    [ 18]   202     Murphy                  White Plains            NY
    [ 19]   208     Suess                   Albany                  NY
    [ 20]   221     Johnson                 Santa Fe                NM
    [ 21]   550     Antolini                Fargo                   ND
    [ 22]   665     Thompson                Manchester              NY
    22 rows Affected.
    Crystal Reports record selection formula and results:
    {customer.state} like "N?"
                            id  lname                 city                  state
                           104  Mason                 Knoxville             NN
                           107  Colburn               Raleigh               NC
                           111  Ricci                 Syracuse              NY
                           116  Gugliuzza             Mamaroneck            NY
                           118  Sanford               Raleigh               NC
                           120  Stein                 Elmsford              NY
                           131  Sinnot                Bohemia               NY
                           135  Clarke                New York              NY
                           147  Lela                  Wood Bridge           NJ
                           152  Jones                 Austin                NY
                           160  Nette                 Port Washington       NY
                           169  Terlemezian           Matthews              NC
                           177  Zubenko               Raleigh               NC
                           180  Peros                 Rochester             NY
                           199  Mentary               Rochester             NY
                           202  Murphy                White Plains          NY
                           208  Suess                 Albany                NY
                           221  Johnson               Santa Fe              NM
                           550  Antolini              Fargo                 ND
                           665  Thompson              Manchester            NY
    Note that the first two rows are not present here.
    Case 2:
    Length of field to be searched: Short (2 chars)
    Wildcard description: letter 'N' + one space 
    Native interactive SQL query and results:
    1 > select id,lname,city,state from customer where state like 'N '
    Columns:        id      lname   city    state
    [ 1]    101     Devlin                  Rutherford              N
    [ 2]    102     Reiser                  New York                N
    2 rows Affected.
    Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
    {customer.state} like "N "
                            id  lname                 city                  state
    No data is displayed.
    Case 3:
    Length of field to be searched: Long (20 chars)
    Wildcard description: 0 or more + 'en' + space + 0 or more
    Native interactive SQL query and results:
    1 > select id,lname,city,state from customer where lname like '%en %'
    Columns:        id      lname   city    state
    [ 1]    129     Fahrvergnugen           Baltimore               MD
    [ 2]    136     Wooten                  Plymouth                MN
    [ 3]    165     Mournen                 Ft. Wayne               IN
    [ 4]    179     Nguyen                  Miramar                 FL
    [ 5]    181     Teeven                  Washington              DC
    [ 6]    198     Chen                    San Ramon               CA
    [ 7]    331     Johansen                New Orleans             LA
    7 rows Affected.
    Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
    {customer.lname} like "*en *"
                            id  lname                 city                  state
    No data is displayed.
    Case 4:
    Length of field to be searched: Long (20 chars)
    Wildcard description: 0 or more + 'en' + any 7 chars
    Native interactive SQL query and results:
    1 > select id,lname,city,state from customer where lname like '%en_______'
    Columns:        id      lname   city    state
    [ 1]    129     Fahrvergnugen           Baltimore               MD
    1 rows Affected.
    Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
    {customer.lname} like "*en???????"
                            id  lname                 city                  state
    No data is displayed.
    Case 5:
    Length of field to be searched: Long (20 chars)
    Wildcard description: 0 or more + 'en' + seven spaces
    Native interactive SQL query and results:
    1 > select id,lname,city,state from customer where lname like '%en       '
    Columns:        id      lname   city    state
    [ 1]    129     Fahrvergnugen           Baltimore               MD
    1 rows Affected.
    Crystal Reports record selection formula (menu: Report -> Selection Formulas -> Record...) and results:
    {customer.lname} like "*en       "
                            id  lname                 city                  state
    No data is displayed.

    Clint,
    Yes, I think that would probably work fine. 
    The point here is that I think there is a bug in the way Crystal Reports processes wild card strings and passes the sql to the downstream database.  Crystal Reports should translate the wild card strings into the corresponding sql standard syntax, and pass the wild card string to the database, but it does not appear to be doing this.
    At this point, I am only interested in notifying the SAP / Business Objects engineering department of this bug, or in posts that point me to a fix to the bug, rather than a work-around.
    Thanks . . .
    - Jay

  • Using wildcard parameters for MDX and RSQL queries

    Hi,
    Passing parameters to MDX and RSQL queries works,but is there a way we can pass wildcard(%) parameters to MDX and RSQL
    Thanks,
    Hari Devarapalli

    Hari -- Try this Instr function -
    http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.dwe.cubemdx.doc/mdx_instr.html
    Thanks,
    Venkat

  • Wildcard search queries

    Oracle 10g 10.2.0.4
    Linux
    we are having some queries where users are using wildcard for searching data in varchar2 fields. when they use like 'text%" the results are returning fast as it's able to use index. But queries are slow when they use like '%text%' or even like '%text'.
    Kindly suggest.
    check below for explain plan.
    SQL> select * from t_invoice_header where invoice like 'REIM113%';
    Execution Plan
    Plan hash value: 1419012284
    | Id  | Operation                   | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                       |    75 | 26175 |    68   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_INVOICE_HEADER      |    75 | 26175 |    68   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | T_INVOICE_HEADER_IDX2 |    75 |       |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("INVOICE" LIKE 'REIM113%')
           filter("INVOICE" LIKE 'REIM113%')
    SQL>  select * from t_invoice_header where invoice like '%REIM113%';
    Execution Plan
    Plan hash value: 717214792
    | Id  | Operation         | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |                  |  2620K|   872M|   418K  (2)| 01:37:42 |
    |*  1 |  TABLE ACCESS FULL| T_INVOICE_HEADER |  2620K|   872M|   418K  (2)| 01:37:42 |
    Predicate Information (identified by operation id):
       1 - filter("INVOICE" LIKE '%REIM113%')
    SQL>

    Think of how an index would be used. An index on INVOICE will be sorted according to the INVOICE, i.e. alphabetically. If you don't specify the first few characters of the INVOICE value, Oracle can't search the index. And it has no idea how selective the condition will be (if you've specified the first few characters, Oracle can get a reasonable guess on selectivity). So Oracle would either have to do a full scan on the index and then do an unknown series of lookups or it would have to do a table scan. The optimizer expects that the table scan is the more efficient plan-- without more information, I have no reason to expect that the optimizer is incorrect.
    Depending on what the INVOICE column contains, you could potentially create an Oracle Text index and use a CONTAINS operator rather than using LIKE to search for strings within the string. But that assumes that the invoice data can be parsed reasonably in building the Text index.
    Justin

  • Prevent wildcard in queries

    Is it possible to prevent the use of the % wildcard by end users of a Forms application? In addition, the ability to query must be restricted to a fixed length.
    For example, in a form field of a fixed length of 9 characters, how can one require them to supply all 9 characters when querying while also preventing the use of the % wildcharacter?
    Must this be done programmatically?
    If applicable, the environment in question is Forms 10g.
    Thanks,
    Chris

    Hi Francois,
    Thanks for the response. That's pretty much what I thought, and is what I meant by a "programmatic" solution. It looks like this restriction cannot be implement using just the item and block properties, but will require a trigger and a bit of code.
    Thanks!
    Chris

  • No wildcard in boundary match queries?

    In SharePoint 2013, when I try to submit the following FQL query:
    QUERYTEXT = managedproperty:STARTS-WITH("n*")
    I get this error:
    Microsoft.Ceres.SearchCore.Services.Query.QueryServiceId error: Microsoft.Ceres.SearchCore.FastServer.FastServerException: IndexComponent1-f5d8be27-3653-41ea-8f40-f37341a6d9b3-SP8a064cb15f50.I.0.0: WILDCARD not allowed in boundary operation
    Is this a known, and expected behavior?  The same query works fine in FS4SP.  And I know, they are completely different products and a "Best of both" approach was taken when merging SPSearch and FAST Search.  But I keep running
    into undocumented limitations of search in SP2013 and it's getting annoying and looking more like a "some of both" approach was taken.

    Hi tatersnacks,
    According to your description, my understanding is that you want to create a scope to match all items which have a managed property starting with “n” in SharePoint 2013.
    From the MSDN article for SharePoint 2013:
    More information:
    https://msdn.microsoft.com/EN-US/library/office/ff394606(v=office.15).aspx
    so, for your issue, please remove the “*” from the query, like: QUERYTEXT = managedproperty:STARTS-WITH("n").
    And, the query is also for SharePoint 2010, more information about SharePoint 2010 FAST query START-WITH, please refer to the link:
    https://msdn.microsoft.com/EN-US/library/office/ff394462(v=office.14).aspx#fqloperator_starts_with
    Best Regards,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

  • Design problem involving Wildcards and EJB-QL.

    Could someone tell me if this is possible? (my syntax might be a bit off, but bear with me. It's the design I'm interested in, not the exact syntax)
    signature="java.util.Collection findByFullMonty (java.lang.Float price, java.lang.Integer bedrooms... "*snip*
    query="SELECT OBJECT(o) FROM Houses o  WHERE ((o.price =?1) AND (o.bedrooms= ?2) AND ... "*snip*I'd like to be able to use this query with wildcards as default values in a fashion similiar to this:
    Float price = ??  ;//This is where i'm unsure, what is a valid wildcard for a Float?
    Integer bedrooms = ??; // same here for Integer....
    String realtorName = "*"; //i think this is valid wildcard for strings
    *snip*
    //if price supplied set price to input value
    if (myObject.getPrice() != null){
        price = myObject.getPrice();
    //if bedrooms supplied set bedrooms to input value
    if (myObject.getBedrooms()!= null){
        bedrooms = myObject.getBedrooms();
    //always use this finder using wild cards  unless a parameter is supplied
    Collection c = findByFullMonty (price, bedrooms,  realtorName, *snip*); What i'm tyring to achieve is a single query that will work no matter how many of the input paramaters are supplied. Any supplied parameters are used, and those that are not supplied will use wildcard instead. I don't want to make a seperate query for every possible permutaion of supplied input parameters. Can this be done? If so, am I even close or out in left field? Is there a design pattern I should look into for this problem?
    Thanks for any help guys!
    (sorry for the cross-post, i didn't realize this was the approprate place until afterwards)

    Yes, that makes sense, but the EJB-QL statements and finder methods in the home interface have to be defined at deployment time, correct? Once it is deployed, I can't dynamically create the EJB-QL statements and finder methods that are needed. That's the major hurdle I have right now.
    Populating a big 'catch-all' query with wild cards and replacing them with supplied literal values is the only way I could think of to accomplish this dynamically. In my current work around I set a flag for each piece of data supplied. I then decide which (pre-defined) query is needed based on the supplied criteria flags. The problem is, I now have to have 2^n (n = number of possible input parameters) permutaions for the possible queries. For example: say i have: price, bedrooms and bathrooms. I'd need queries for the following cases:
    1 price supplied only
    2 bedrooms supplied only
    3 bathrooms supplied only
    4 price and bedrooms
    5 price and bathrooms
    6 bedrooms and bathrooms
    7 price, bedrooms, bathrooms
    8 nothing supplied (return everything)
    Obviously this is going to break down really fast as the number of input parameters climbs.
    Should I look at using some kind of JDBC code directly to build a query as I go? It seems like I am either approaching this the wrong way or missing something really obvious.

  • Using wildcards in CCM 2.0 search

    Hi experts
    we're using SRM 5.0 (SRM 5.5 Server) with CCM 2.0.
    Is it possible to use wildcards in catalog search?
    Are there any documents about wildcards in CCM ?
    Regards.
    Sven

    Hi
    Yes TREX is mandatory for CCM2.0 (written in the master guide). Please restart the TREX server and retry, if this does not in your case.
    I guess, There are two wildcard characters:
    ? stands for a single character
    stands for a sequence of any combination characters of any length.
    Related links ->
    CCM 2.0 Simple search on CSE does not show any result
    Re: Cross catalog search doesn't work for CCM 2.0
    Re: Search function for Catalogue CCM 1.0 SRM version 4
    CCM view rules - based on wild cards?
    Re: Is TREX required for CCM 2.0 search?
    Hope this answers your queries. Do let me know.
    Regards
    - Atul

  • Use of wildcard * in SELECT statement

    I have read that the use of the wildcard * in a SELECT statement cannot be utilized when using the INSERT INTO or other queries where data column/field alignment is critical. I have noted that the INSERT INTO column/fields must be in the same order
    as the SELECT statement (as there is no alignment to column/field names). Can someone please provide me with the information or article that covered this scenario?

    It is consider a good practice to specify columns name, however , SQL Server is smart enough to insert the data without too , but only if the table does not have an IDENTITY property
    CREATE TABLE #t (c1 int, c2 char(1),c3 real, c4 bit)
    CREATE TABLE #t1 (c1 int, c2 char(1),c3 real, c4 bit)
    ---Same thing with INSERT  like SELECT * you asked
    INSERT INTO #t1 VALUES (1,'A',2.5,0) 
    INSERT INTO #t1 VALUES (2,'B',3.5,1)
    INSERT INTO #t1 VALUES (3,'C',4.5,0)
    INSERT INTO #t SELECT * FROM #t1
    SELECT * FROM #t
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Query of queries problem or bug

    Hello Everyone,
    I have used cfdirectory to get a list of files. As the result
    I receive query with the files.
    Then I want to search it using query of queries. I' ve found
    a problem and I wonder if it is a bug of Coldfusion or perhaps
    wrong usage of QoQ. The thing is that the files that I have are
    using '_' and then are followed by number of week. It seems that
    searching something like this '%_6' returns results *_*6. See
    attached code.
    Thanks for all answers in advance.

    > I think you'll find "_" is a single-char wildcard when
    used with the LIKE
    > operator.
    Found out how to escape it:
    WHERE Name LIKE '%[_]6%'
    I'm glad you brought this up... I didn't know about this
    until I looked @
    your issue. That's my new thing learned for the day: I can go
    to the pub
    now ;-)
    Adam

  • How to use wildcards in the query

    Hi all,
    I have the following code:
    pStmt = conn.prepareStatement("SELECT * FROM library.books where title like ?",java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_UPDATABLE);
    pStmt.setString(1, name);
    rs = pStmt.executeQuery();When I try to apply the following query including wildcard "%", I get an error:
    SELECT *
    FROM `books`
    WHERE `title` LIKE '%?%';Doesn't Java accept "%" in the queries?

    I didn't write whole code not to disturb the focus, but here it is:
       private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {                                     
            ResultSet rs=null;
            String[] pathS= new String[1000];
            PreparedStatement pStmt = null;
            int j=0;
            try{
                Connection conn = HandleCon.getConnInstance();
                pStmt = conn.prepareStatement("DELETE FROM library.tempbook "
                           ,java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_UPDATABLE);
                pStmt.execute();
                if((jTextField12.getText().equals(""))) {
                    JOptionPane.showMessageDialog(null, "YOU SHOULD FILL","Display Message",JOptionPane.ERROR_MESSAGE);
                } else{
                    String name;
                    name=jTextField12.getText();
                    pStmt = conn.prepareStatement("SELECT * FROM library.books where title like
                               %?%",java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_UPDATABLE);
                    pStmt.setString(1, name);
                    rs = pStmt.executeQuery();
                    while (rs.next()) {
                        String a;
                        a=rs.getString(1);
                        String b;
                        b=rs.getString(2);
                        String c;
                        c=rs.getString(3);
                        String d;
                        d=rs.getString(4);
                        String e;
                        e=rs.getString(5);
                        String f;
                        f=rs.getString(6);
                        pathS[j]=f;
                        j++;
                        pStmt = conn.prepareStatement("INSERT INTO library.tempbook
                                     (title,author,publisher,content,tag,paths) " + "VALUES
                                     (?,?,?,?,?,?)",java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_UPDATABLE);
                        pStmt.setString(1, a);
                        pStmt.setString(2, b);
                        pStmt.setString(3, c);
                        pStmt.setString(4, d);
                        pStmt.setString(5, e);
                        pStmt.setString(6, f);
                        pStmt.execute();
                        jList2.setListData(pathS);
            catch (Exception e) {
                System.err.println(e);
        }I get the following error:
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
    You have an error in your SQL syntax; check the manual that corresponds
    to your MySQL server version for the right syntax to use near '%'pap'%' at line 1The mentioned query runs when I use phpMyAdmin.

  • Wildcards in CTXCAT grammar vs. CONTEXT grammar

    I've got a question about using wildcards in the CONTEXT grammar, when working with a catalog (CTXCAT index). For the application in question, the simpler CTXCAT grammar is almost exactly what I need, but there are a few circumstances in which I want to be able to take advantage of the flexibility of the CONTEXT grammar. I am able to do that using a query template, but when the query in question includes wildcards, I sometimes see behavior that I do not understand. Here's a query that works perfectly when expressed in the CTXCAT grammar:
    SELECT count(*)
    FROM ItemKeywordSearch iks
    WHERE CATSEARCH(iks.ItemKeywords, '403(b)*', null) > 0;
    When I try to restate that same query using the CONTEXT grammar like this:
    SELECT count(*)
    FROM ItemKeywordSearch iks
    WHERE CATSEARCH(iks.ItemKeywords, '<query><textquery grammar="CONTEXT">403(b)%</textquery></query>', null) > 0;
    I get a "DRG-51030: wildcard query expansion resulted in too many terms" error. I'm guessing the issue is related to some interaction between the parentheses characters and the wildcard; I don't see the same error if I remove the parentheses from the query.
    Can anyone help me understand the cause of this issue, and suggest a way I can resolve or work around it?
    Thanks,
    Tim

    I don't know what preference attributes you have set. If you want to search for parentheses, then you should set them as printjoins within a lexer so that they are indexed and you will also need to escape them by placing a \ before each one, so that they are not treated as special characters. You can also set the wildcard_maxterms to the maximum value for your verision in a wordlist. The two queries that use the different grammar may be viewing the search string differently. If one ignores the parentheses tries to search for b% or everything that starts with b then that would expand to a lot of terms very quickly and would cause the error. You can query the dr$token column of your dr$...$i domain index table to see how your data has been tokenized during indexing. Please see the demonstration below.
    SCOTT@orcl_11g> CREATE TABLE ItemKeywordSearch
      2    (ItemKeywords  VARCHAR2 (20))
      3  /
    Table created.
    SCOTT@orcl_11g> INSERT ALL
      2  INTO ItemKeywordSearch VALUES ('403(b)')
      3  INTO ItemKeywordSearch VALUES ('403(b)A')
      4  INTO ItemKeywordSearch VALUES ('403(b)B')
      5  INTO ItemKeywordSearch VALUES ('403(b)C')
      6  INTO ItemKeywordSearch VALUES ('other')
      7  SELECT * FROM DUAL
      8  /
    5 rows created.
    SCOTT@orcl_11g> BEGIN
      2    CTX_DDL.CREATE_PREFERENCE ('your_lexer', 'BASIC_LEXER');
      3    CTX_DDL.SET_ATTRIBUTE ('your_lexer', 'PRINTJOINS', '()');
      4    --
      5    CTX_DDL.CREATE_PREFERENCE ('your_wordlist', 'BASIC_WORDLIST');
      6    CTX_DDL.SET_ATTRIBUTE ('your_wordlist', 'WILDCARD_MAXTERMS', '50000');
      7  END;
      8  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11g> CREATE INDEX iks_idx
      2  ON ItemKeywordSearch (ItemKeywords)
      3  INDEXTYPE IS CTXSYS.CTXCAT
      4  PARAMETERS
      5    ('LEXER        your_lexer
      6        WORDLIST  your_wordlist')
      7  /
    Index created.
    SCOTT@orcl_11g> SELECT dr$token FROM dr$iks_idx$i
      2  /
    DR$TOKEN
    403(B)
    403(B)A
    403(B)B
    403(B)C
    OTHER
    SCOTT@orcl_11g> SELECT count(*)
      2  FROM   ItemKeywordSearch iks
      3  WHERE  CATSEARCH
      4             (iks.ItemKeywords,
      5              '403\(b\)*',
      6              null) > 0
      7  /
      COUNT(*)
             4
    SCOTT@orcl_11g> SELECT count(*)
      2  FROM   ItemKeywordSearch iks
      3  WHERE  CATSEARCH
      4             (iks.ItemKeywords,
      5              '<query>
      6              <textquery grammar="CONTEXT">403\(b\)%
      7              </textquery>
      8            </query>',
      9            null) > 0
    10  /
      COUNT(*)
             4
    SCOTT@orcl_11g>

  • Use wildcards in webi report filters?  It seems they're only avail in Query

    Can I use wildcards in webi report filters?  It seems they're only avail in Queries...

    HI,
    Eventhough you have created variable BeX query designer.
    User reponse will work ,
    steps to  achive,
    1.open the universe build on (Bex query with customer variable)
    2.you can find the filter symbol in universe for customer variable that you have created in bexx query
    3. then copy the exact text eg:"select the customer" in universe for that filter
    4.then in webi user reponse of that text. eg :userreponse("select the customer")
    regards,

Maybe you are looking for