Question with like operator

create table mytestc(x varchar2(10));
insert into mytestc values ('18t');
insert into mytestc values ('4t;8t');
commit;
How do I give a select so I can select all the rows where 8t is present
select * from mytestc where x like '%8t%'
gives 18t in result set

Hi,
user650888 wrote:
create table mytestc(x varchar2(10));
insert into mytestc values ('18t');
insert into mytestc values ('4t;8t');
commit;Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful.
Don't forget to post the results you want from that data, an explanation of how you get those results from that data, and the version of Oracle you're using.
How do I give a select so I can select all the rows where 8t is present
select * from mytestc where x like '%8t%'
gives 18t in result setThat's right; '8t' is present in '18t'. That's what you said you wanted. If you would post your desired results and an explanation, then people could help you more.
Did you mean to say that '8t' has to be a complete item in the ;-delimited list, not a subset of some other string, like '18t' or '8td'?
In other words, do you mean that you only want to count '8t' as a match when the character before it is a ';' (or when it is at the beginning of x) qnd the character immediately after it is also ';' (or it comes at the end of x)?
If so:
WHERE     INSTR ( ';' || x || ';'
           , ';8t;'
           )          > 0The exxpression above will be more efficient than the (otherwise) equivalent:
WHERE     ';' || x || ';'     LIKE '%;8t;%'This is called the "mother is in chemotherapy" problem.
Edited by: Frank Kulash on May 24, 2011 4:39 PM

Similar Messages

  • Case Insensitive Search coupled with "LIKE" operator.

    Greetings All, I am running Oracle 11gR1 RAC patchet 25 on Windows X64.
    This db supports and application that requires case insensitive searches.
    Because there are a few entry points into the db I created an "after login" trigger:
    CREATE OR REPLACE TRIGGER MyAppAfterLogon_TRGR
    AFTER LOGON
    ON DATABASE
    DECLARE
    vDDL VARCHAR2(200) := 'alter session set nls_comp=''linguistic''';
    vDDL2 VARCHAR2(200) := 'alter session set nls_sort=''binary_ci''';
    BEGIN
    IF ((USER = 'MyAppUSER') OR(USER = 'MyAppREPORTINGUSER')) THEN
    EXECUTE IMMEDIATE vDDL;
    EXECUTE IMMEDIATE vDDL2;
    END IF;
    END MyAppAfterLogon_TRGR;
    This ensures that everyone connecting to the DB via any mechanism will automatically have case insensitive searches.
    Now, to optimize the know queries I created the standard index to support normal matching queries:
    select * from MyTable where Name = 'STEVE';
    The index looks like:
    CREATE INDEX "CONTACT_IDX3 ON MYTABLE (NLSSORT("NAME",'nls_sort=''BINARY_CI'''))
    This all works fine, no issues.
    The problem is when I write a query that uses the "LIKE" operator:
    select * from MyTable where Name like 'STEV%';
    I get back the record set I expect. However, my index is not used? I can't for the life of me get this query to use an index.
    The table has about 600,000 rows and I have run gather schema stats.
    Does anyone know of any issues with case insensitive searches and the "LIKE" clause?
    Any and all help would be appreciated.
    L

    I think there is issue with your logon trigger :
    "IF ((USER = 'MyAppUSER') OR(USER = 'MyAppREPORTINGUSER')) THEN"
    it should be :
    IF UPPER(USER) = 'MYAPPUSER' OR UPPER(USER) = 'MYAPPREPORTINGUSER' THEN
    because user name stored in Upper case. Check and try.
    HTH
    Girish Sharma

  • Multiple row subquery with like operator

    can any1 give me an example where we can use a multiple row subquery with the like operator.I read it can be used but when i tried it gives the following error
    select * from gagan_emp where ename like (select ename from gagan_emp where deptno=10)
    ERROR at line 1:
    ORA-01427: single-row subquery returns more than one row

    The right part of 'LIKE' is permitted only single value expression
    (including subquery that returns single value),
    is not permitted multiple values.
    -- Examples (but.... not so good)
    select * from gagan_emp e0
    where exists
    (select ename from gagan_emp e1 where deptno=10
    and e0.ename like e1.ename)
    select * from gagan_emp e0
    where exists
    (select ename from gagan_emp e1 where deptno=10
    and e0.ename = e1.ename)
    select * from gagan_emp e0
    where ename = any
    (select ename from gagan_emp e1 where deptno=10)
    select * from gagan_emp
    where ename like
    (select ename from gagan_emp e1 where deptno=10 and rownum=1)
    ;

  • Problem with LIKE operator in select query

    Hi,
    I want to compare one field using LIKE operator. But i m not able to do that.
    DATA: l_doctext type c value ''''.
    CONCATENATE l_doctext s_lbktxt-low '%' l_doctext INTO s_lbktxt-low.
    SELECT bukrs belnr gjahr blart bldat budat xblnr bktxt waers awtyp
                FROM bkpf INTO TABLE g_t_bkpf_labor
                FOR ALL ENTRIES IN g_t_bseg_unique
                WHERE bukrs = g_t_bseg_unique-bukrs
                AND belnr = g_t_bseg_unique-belnr
                AND gjahr = g_t_bseg_unique-gjahr
                AND blart = p_ldtype
                AND bktxt LIKE s_lbktxt-low.
    plz help. Am i dng something wrong.
    Value in s_lbktxt can be like 'TEA.....'

    hi ,
    check this program..
    tables:mara.
    data: begin of it_mara occurs 0,
          matnr like mara-matnr,
          meins like mara-meins ,
          mtart like mara-mtart,
          end of it_mara.
    select-options: s_matnr for mara-matnr.
          select matnr
                 meins
                 mtart
                 from mara
                 into table it_mara
                 where matnr like '%7'.
    sort it_mara by matnr.
    loop at it_mara.
    write:/ it_mara-matnr,
    it_mara-meins,
    it_mara-mtart.
    endloop.
    regards,
    venkat.

  • SQL Query With Like Operator - Performance is very poor - Oracle Apps Table

    Hi,
    I'm querying one of the Oracle Applications Standard Table. The performance is very slow when like operator is used in the query condition. The query uses a indexed column in the where clause.
    The query is..
    select * from hz_parties
    where upper(party_name) like '%TOY%'
    In the above case, It is not using the index and doing full table scan. I have checked the explain plan and the cost is 4496.
    select * from hz_parties
    where upper(party_name) like 'TOY%'
    If I remove the '%' at the begining of the string, the performance is good and it is using the index. In this case, the cost is 5.
    Any ideas to improve the performance of the above query. I have to retrieve the records whose name contains the string. I have tried hints to force the use of index. But it is of no use.
    Thanks,
    Rama

    If new indexes are disallowed, not a lot of good ones, no.
    If you know what keyword(s) are going to be searched for, a materialized view might help, but I assume that you're searching based on user input. In that case, you'd have to essentially build your own Text index using materialized views, which will almost certainly be less efficient and require more maintenance than the built-in functionality.
    There may not be much you could do to affect the query plan in a reasonable way. Depending on the size of the table, how much RAM you're willing to throw at the problem, how your system is administered, and what Oracle Apps requires/ prohibits in terms of database configuration, you might be able to force Oracle to cache this table so that your full table scans are at least more efficient.
    Justin

  • Issue with like operator

    Hi All,
    we are using like operator for search functionality (oracle 10G).
    could any one help me in handling null, when we use like operator.
    Ex:
    select empno,ename,d.deptno
    from emp e, dept d
    where e.deptno = d.deptno
    and e.ename like '%JO%';
    we have a text box in the front end to key in employee name (ename) or part of ename. when user doesnt use this option, he leaves it blank.
    so In the above query, if ename is null then my query fails.
    could anybody help me out in handling this scenario.
    My query should still give me all the employee ids, if the ename is blank.
    using dynamic sql is not advisable.
    Thanks
    Manju

    Something like this ->
    satyaki>select *
      2     from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.26
    satyaki>
    satyaki>
    satyaki>select *
      2  from emp
      3  where upper(ename) like nvl('%'||upper('&str')||'%',upper(ename));
    Enter value for str:
    old   3: where upper(ename) like nvl('%'||upper('&str')||'%',upper(ename))
    new   3: where upper(ename) like nvl('%'||upper('')||'%',upper(ename))
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    13 rows selected.
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>/
    Enter value for str: sa
    old   3: where upper(ename) like nvl('%'||upper('&str')||'%',upper(ename))
    new   3: where upper(ename) like nvl('%'||upper('sa')||'%',upper(ename))
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
    Elapsed: 00:00:00.08Regards.
    Satyaki De.

  • Question with installing operating system to my new hard drive

    I just ordered a new hard drive for my macbook.  I've had no problems finding how to take out the old one and install the new one into my computer, but I can't seem to find information on how to install osx onto the my computer again.  Is it as simple as putting in the osx disks or are there others steps that need to be taken for the macbook to recognize my new hard drive?

    Drive Preparation and OS X Installation
    1. Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Security button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    7. Quit DU after formatting has completed. Install OS X.
    8. Restore your files from your backup or put your old drive into an external enclosure so you can restore from your old drive.

  • Working with LIKE operator

    hi,
    i have a small confusion in escape clause.
    create table products (product_name varchar2(100));
    begin
    insert into products (product_name) values('A%_WQ123');
    insert into products (product_name) values('A%BWQ123');
    insert into products (product_name) values('AB_WQ123');
    commit;
    end;
    select * from products where product_name like '%\%_WQ12%' escape '\';
    output:
    product_name
    A%_WQ123
    A%BWQ123
    can you please tell how this is working,  in the above statment the ESCAPE will escape only % or both %and_
    thanks,

    Are you after this?
    select * from products where product_name like '%\%\_WQ12%' escape '\';
    Cheers,
    Manik.

  • Like operator issue with on Number column

    Hi,
    Query with like operator for Example: " where RATE LIKE ('%2%')"
    the result of the query returns rows which contains "2" as part of field value along with few rows which are updated recently, but do not contain 2 in that row.
    In the table data type of COLUMN is Number, no precision.
    Pls let me know if any one knows about this.
    --satya.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Can you please post the result of the query you are using?
    Regards

  • Why the 'LIKE' operator takes so much time to run?

    I have a table T with 3 columns and 3 indexes:
    CREATE TABLE T
    id VARCHAR2(38) NOT NULL,
    fid VARCHAR2(38) NOT NULL,
    val NVARCHAR2(2000) NOT NULL
    ALTER TABLE T ADD (CONSTRAINT pk_t PRIMARY KEY (id,fid));
    CREATE INDEX t_fid ON T(fid);
    CREATE INDEX t_val ON T(val);
    Then I have the following two queries which differ in only one place - the 1st one uses the '=' operator whereas the 2nd uses 'LIKE'. Both queries have the identical execution plan and return one identical row. However, the 1st query takes almost 0 second to execute, and the 2nd one takes more than 12 seconds, on a pretty beefy machine. I had played with the target text, like placing '%' here and/or there, and observed the similar timing every time.
    So I am wondering what I should change to make the 'LIKE' operator run as fast as the '=' operator. I know CONTEXT/CATALOG index is a viable approach, but I am just trying to find out if there is a simpler alternative, such as a better use of the index t_val.
    1) Query with '=' operator
    SELECT id
    FROM T
    WHERE fid = '{999AE6E4-1ED9-459B-9BB0-45C913668C8C}'
    AND val = '3504038055275883124';
    2) Query with 'LIKE' operator
    SELECT id
    FROM T
    WHERE fid = '{999AE6E4-1ED9-459B-9BB0-45C913668C8C}'
    AND val LIKE '3504038055275883124';
    Execution Plan
    0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=99)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'T' (Cost=1 Card=1 Bytes=99)
    2 1 INDEX (RANGE SCAN) OF 'T_VAL' (NON-UNIQUE) (Cost=4 Card=12)

    I will for sure try to change the order of the PK and see whether there will be any impact to the performance.
    In our application, val is much closer to a unique value than fid. In the example query, the execution plan showed that the index on val was indeed used in the execution of the query. That's why the 1st query took almost no time to return (our table T has more than 6 million rows).
    I was hoping the 'LIKE' operator would utilize the t_val index effectively and provide similar performance to the '=' operator. But apparently that's not the case, or needs some tricks.

  • Case insensitive selects with 'like'

    I use a 10g database (10.2.0.2 same behaviour with 10.2.0.1). What we want is case insensitive selects with 'like' operator in the where clause. NLS_COMP is set to 'LINGUISTIC' and NLS_SORT is set to 'BINARY_CI.
    In a table we have two columns one of type 'varchar2' one of type 'nvarchar2'. The databases national character set is set to UTF8. Case insensitive sorting works with both columns. Select statements with '.... where varchar2col like '%r%' returns also values with upper case 'R' values (that is what I expect).
    The select statements with '.... where nvarchar2col like '%r%' however does not return the row with upper case 'R' values.
    I used SQL*Plus: Release 10.2.0.3.0 and other clients and the behaviour is the same so
    I think it is not client related.
    Is that a known issue or is there any other parameter to set for UTF8 nvarchar columns?
    Any hint is very much appreciated! Here are the nls settings in database, instance and session:
    DPARAMETER      DVALUE IVALUE SVALUE
    NLS_CHARACTERSET WE8ISO8859P1
    NLS_COMP      BINARY LINGUISTIC LINGUISTIC
    NLS_LANGUAGE      AMERICAN AMERICAN AMERICAN
    NLS_NCHAR_CHARACTERSET UTF8
    NLS_RDBMS_VERSION 10.2.0.1.0
    NLS_SORT BINARY BINARY_CI BINARY_CI
    NLS_TERRITORY      AMERICA AMERICA AMERICA

    OK. Found out what the problem is. It is obviously the client.
    While using the instant client and setting the parameters (NLS_SORT=BINARY_CI and NLS_COMP=LINGUISTIC) as environment variables does not work correctly, at least not for nvarchar2 fields. The nls_session_parameters show the correct values, but selects with 'like' operators in the where clause do not return case insensitive. Issuing the 'alter session' commands and again setting the nls parameters solves the problem.
    Using the full client installation also works, in case the parameters are set in the registry on windows systems. With the full client it it not necessary to issue the 'alter session' commands again.
    So obviously the problem is instant client and nvarchar2 field related. That's too bad....

  • Like operator with PowerQuery

    Hi Everyone
    Please help me to construct a PowerQuery With help of LIKE operator SQL Query
    Below is my sample Query
    select * from
    abc where
    LastModifiedDate
    like
    '2012-02-06%'
    Thanks In Advance..

    Hi
    Not sure if you are trying to:
    use Like in a PQ, in which case Chris Webb's blog is very helpful  Implementing A Basic LIKE/Wildcard Search Function In Power Query or
    are you trying to pass a parameter through to a SQL Query in which case I just posted a suggestion to a similar question here How
    to pass date dynamically to SqlQuery in PowerQuery
    Hope this helps

  • How to move Firefox4 Tabs to the Bottom like opera the userChome.css #content tabbox { -moz-box-direction: reverse; } does't work ,and tabmix extension is s incompatible with Firefox 4.

    ''Duplicate post, continue here - [https://support.mozilla.com/en-US/questions/780590]''
    I want move Firefox tabs to the bottom like opera
    but the code of userChome.css
    #content > tabbox { -moz-box-direction: reverse; }
    does'nt work,
    and tabmix can do this,but current version of tabmix is incompatible with Firefox 4.

    You can get the development version of Tab Mix Plus which works with Firefox 4 from http://tmp.garyr.net/forum/viewtopic.php?t=10888
    The author of Tab Mix Plus has stated that he is almost ready to release a new version of Tab Mix Plus.

  • How to use LIKE operator with PreparedStatement

    Hi, I need to execute a query with the LIKE operator, but using a PreparedStatement. Can I do this, and if so what must my SQL look like with the wildcard characters '%' or '_'?
    normal PS example: conn.prepareStatement("select * from mytable where name like ?");
    If I try: conn.prepareStatement("select * from mytable where name like ?%");
    I get: ORA-00911: invalid character
    If I try: conn.prepareStatement("select * from mytable where name like '?%'");
    I get: ORA-01006: bind variable does not exist
    I must use a PreparedStatement, as my variable may contain illegal characters (like '), and using PreparedStatement.setString(1, var) will automatically escape it for me.
    I could also use a normal Statement, but I need to escape my var ... is there a utility that will safely escape a String for an Oracle VARCHAR2??
    Thanks in advance,
    Stu Miller

    Hmm, it seems you are right...
    when my variable contains a '%' symbol, the PreparedStatement will NOT escape it, and thus it is treated like a wildcard. Therefore, I can just do
    pstmt.setString(1, var+"%");
    But, that may return more results than I'm asking for, as when 'var' contains a '%' symbol it is taken as a wildcard too.
    I need each character in my variable to be taken literally, and only add a wildcard at the end. Basically, I need a STARTSWITH operator ;-)
    It seems to me that escaping the sensitive characters in a String (which will differ depending on which operator is used), should be possible. I could write this, but I was hoping Oracle had already done it for me in some utility class.

  • LIKE Operator with Clobs

    Hi, Having Problems using the LIKE Operator with the Clob Datatype. Does any one know if its possible.
    Thanks
    Emer

    It's not possible.
    try use DBMS_LOB.INSTR instead...

Maybe you are looking for

  • How to update CU1 & CU2 to SCCM 2012 R2

    I Install SCCM 2012 R2 then I install CU1 immediately. After about 2 months, I install CU2 in Primary Site. Now I found some bug, but it should be fixed by CU, then I found this is because I didn't push CU to client. So I have some questions about Up

  • Which platform I should use ?

    which java platform I should use to creat message display and settings in mobile phone ? and how can I add language code in java to show different laguage(other than English) on mobile screen ?

  • How to delete image in Mail

    I just noticed that there's a photo from Photo Booth in the top right hand corner of all the new messages I've been sending from Mail. It's likely been there for quite a while and I must have just gotten used to it didn't notice until now that it's a

  • How do I write a VI for an AG-UC2 controller?

     I  need to be able to move a AG-LS25 piezo motor in both directions via labview.  If anyone has any examples of this and would be willing to give me some advice I would really appreciate it.  I have very little experience with labview and would appr

  • Oracle 9i clob segment possible corruption

    Hello all, We are experiencing some select issues from a table containing a CLOB segment. Since I don't know too much about CLOBs and we are suspecting a possible corruption. What would be the next step besides a DBV on the datafile housing hat table