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)
;

Similar Messages

  • How can i use multiple row subquery in update statement

    Hai All
    I using group function in my update statement.. and i need to update more rows so i need to use multiple row
    subquery pls tell me how to use multiple row subquery in update statement
    For example
    while i am using this like this i got an error
    update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
    barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
    Pls tell me how to use with example
    Thanks & regards
    Srikkanth.M

    Hai Man
    Thanks for ur response Let me clear what i need
    First step Fetch the records as text file and stores into table T1
    and the next step is i have seperated the text using substring and stores in different columns of a table
    There are two shifts 0815 to 1645 and 1200 and 2000
    Here I rep IN and O rep OUT
    Empno date time inout
    001 01-01-10 0815 I
    002 01-01-10 0815 I
    003 01-01-10 0818 I
    001 01-01-10 1100 0
    001 01-01-10 1130 I
    002 01-01-10 1145 0
    002 01-01-10 1215 I
    004 01-01-10 1200 I
    005 01-01-10 1215 I
    004 01-01-10 1315 O
    004 01-01-10 1345 I
    001 01-01-10 1645 0
    002 01-01-10 1715 0
    003 01-01-10 1718 0
    004 01-01-10 2010 0
    005 01-01-10 2015 0
    This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
    T2 contains like this
    Empno Intime Intrin Introut Outtime Date
    001 0815 1100 1130 1645 01-01-10
    002 0815 1145 1215 1715 01-01-10
    003 0818 1718 01-01-10
    004 1200 1315 1345 2010 01-01-10
    005 1215 2015 01-01-10
    This what i am trying to do man but i have little bit problems Pls give some solution with good example
    And my coding is
    declare
         emp_code varchar2(25);
    in_time varchar2(25);
    out_time varchar2(25);
    Cursor P1 is
    Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    From temp_att
    group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
    ORDER BY enpno,pdate,ptime;
    begin
         for r2 in p1 loop
    declare
    bar_code varchar2(25);
    begin
    select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
    For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
    if r2.inout ='O' then
    update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
    end if;
    end loop;     
    exception
         when no_data_found then
         if r2.inout ='I' then
                   insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
         end if;
    end;
    end loop;
    commit;     
         end;
    Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
    and how can i use it in the update statement
    Thanks In Advance
    Srikkanth.M

  • Help: multiple-row subquery

    Hi,
    My question hinges off the same type of DB as the question asked on here a little while back (https://forums.oracle.com/thread/1982906).
    The specific question is: Determine which author or authors wrote the books most frequently purchased by customers of JustLee Books
    I am trying to build a multiple-row subquery (I'm not sure if this would be the best way to approach). I supplied the table at the bottom of this post.
    Per my code below, as you can see, this is not working for me. I'm trying to pull the total count of each book (via isbn inside table authorid), then I'll look-up the author code and ultimately the author's name (table orderitems then bookauthor) . I'm working from the inside out, and cannot get past using the first subquery.
    Could someone please be able to help point me in the right direction?
    Thanks for your help!
    SQL> SELECT isbn, authorid 
      2  FROM bookauthor
      3  WHERE isbn IN (SELECT COUNT(isbn)
      4                                FROM orderitems
      5                                GROUP BY isbn)
      6  ORDER BY isbn, authorid;
    no rows selected
    TABLES:
    SQL> select * from orderitems;
        ORDER#      ITEM# ISBN         QUANTITY   PAIDEACH                                                                           
          1000          1 3437212490          1      19.95                                                                           
          1001          1 9247381001          1      31.95                                                                           
          1001          2 2491748320          1      85.45                                                                           
          1002          1 8843172113          2      55.95                                                                           
          1003          1 8843172113          1      55.95                                                                           
          1003          2 1059831198          1      30.95                                                                           
          1003          3 3437212490          1      19.95                                                                           
          1004          1 2491748320          2      85.45                                                                           
          1005          1 2147428890          1      39.95                                                                           
          1006          1 9959789321          1       54.5                                                                           
          1007          1 3957136468          3      72.15                                                                           
          1007          2 9959789321          1       54.5                                                                           
          1007          3 8117949391          1       8.95                                                                           
          1007          4 8843172113          1      55.95                                                                           
          1008          1 3437212490          2      19.95                                                                           
          1009          1 3437212490          1      19.95                                                                           
          1009          2 0401140733          1         22                                                                           
          1010          1 8843172113          1      55.95                                                                           
          1011          1 2491748320          1      85.45                                                                           
          1012          1 8117949391          1       8.95                                                                           
          1012          2 1915762492          2         25                                                                           
          1012          3 2491748320          1      85.45                                                                           
          1012          4 0401140733          1         22                                                                           
          1013          1 8843172113          1      55.95                                                                           
          1014          1 0401140733          2         22                                                                           
          1015          1 3437212490          1      19.95                                                                           
          1016          1 2491748320          1      85.45                                                                           
          1017          1 8117949391          2       8.95                                                                           
          1018          1 3437212490          1      19.95                                                                           
          1018          2 8843172113          1      55.95                                                                           
          1019          1 0401140733          1         22                                                                           
          1020          1 3437212490          1      19.95
    SQL> select * from bookauthor;
    ISBN       AUTH
    0132149871 S100
    0299282519 S100
    0401140733 J100
    1059831198 P100
    1059831198 S100
    1915762492 W100
    1915762492 W105
    2147428890 W105
    2491748320 B100
    2491748320 F100
    2491748320 R100
    3437212490 B100
    3957136468 A100
    4981341710 K100
    8117949391 R100
    8843172113 A100
    8843172113 A105
    8843172113 P105
    9247381001 W100
    9959789321 J100
    20 rows selected.
    SQL> select * from author;
    AUTH LNAME      FNAME
    S100 SMITH      SAM
    J100 JONES      JANICE
    A100 AUSTIN     JAMES
    M100 MARTINEZ   SHEILA
    K100 KZOCHSKY   TAMARA
    P100 PORTER     LISA
    A105 ADAMS      JUAN
    B100 BAKER      JACK
    P105 PETERSON   TINA
    W100 WHITE      WILLIAM
    W105 WHITE      LISA
    R100 ROBINSON   ROBERT
    F100 FIELDS     OSCAR
    W110 WILKINSON  ANTHONY
    14 rows selected.

    a35c130d-ca92-46ca-8177-8a8b5ee02876 wrote:
    Hi,
    My question hinges off the same type of DB as the question asked on here a little while back (https://forums.oracle.com/thread/1982906).
    The specific question is: Determine which author or authors wrote the books most frequently purchased by customers of JustLee Books
    I am trying to build a multiple-row subquery (I'm not sure if this would be the best way to approach). I supplied the table at the bottom of this post.
    Per my code below, as you can see, this is not working for me. I'm trying to pull the total count of each book (via isbn inside table authorid), then I'll look-up the author code and ultimately the author's name (table orderitems then bookauthor) . I'm working from the inside out, and cannot get past using the first subquery.
    Could someone please be able to help point me in the right direction?
    Thanks for your help!
    SQL> SELECT isbn, authorid 
      2  FROM bookauthor
      3  WHERE isbn IN (SELECT COUNT(isbn)
      4                                FROM orderitems
      5                                GROUP BY isbn)
      6  ORDER BY isbn, authorid;
    no rows selected
    TABLES:
    SQL> select * from orderitems;
        ORDER#      ITEM# ISBN         QUANTITY   PAIDEACH                                                                          
          1000          1 3437212490          1      19.95                                                                          
          1001          1 9247381001          1      31.95                                                                          
          1001          2 2491748320          1      85.45                                                                          
          1002          1 8843172113          2      55.95                                                                          
          1003          1 8843172113          1      55.95                                                                          
          1003          2 1059831198          1      30.95                                                                          
          1003          3 3437212490          1      19.95                                                                          
          1004          1 2491748320          2      85.45                                                                          
          1005          1 2147428890          1      39.95                                                                          
          1006          1 9959789321          1       54.5                                                                          
          1007          1 3957136468          3      72.15                                                                          
          1007          2 9959789321          1       54.5                                                                          
          1007          3 8117949391          1       8.95                                                                          
          1007          4 8843172113          1      55.95                                                                          
          1008          1 3437212490          2      19.95                                                                          
          1009          1 3437212490          1      19.95                                                                          
          1009          2 0401140733          1         22                                                                          
          1010          1 8843172113          1      55.95                                                                          
          1011          1 2491748320          1      85.45                                                                          
          1012          1 8117949391          1       8.95                                                                          
          1012          2 1915762492          2         25                                                                          
          1012          3 2491748320          1      85.45                                                                          
          1012          4 0401140733          1         22                                                                          
          1013          1 8843172113          1      55.95                                                                          
          1014          1 0401140733          2         22                                                                          
          1015          1 3437212490          1      19.95                                                                          
          1016          1 2491748320          1      85.45                                                                          
          1017          1 8117949391          2       8.95                                                                          
          1018          1 3437212490          1      19.95                                                                          
          1018          2 8843172113          1      55.95                                                                          
          1019          1 0401140733          1         22                                                                          
          1020          1 3437212490          1      19.95
    SQL> select * from bookauthor;
    ISBN       AUTH
    0132149871 S100
    0299282519 S100
    0401140733 J100
    1059831198 P100
    1059831198 S100
    1915762492 W100
    1915762492 W105
    2147428890 W105
    2491748320 B100
    2491748320 F100
    2491748320 R100
    3437212490 B100
    3957136468 A100
    4981341710 K100
    8117949391 R100
    8843172113 A100
    8843172113 A105
    8843172113 P105
    9247381001 W100
    9959789321 J100
    20 rows selected.
    SQL> select * from author;
    AUTH LNAME      FNAME
    S100 SMITH      SAM
    J100 JONES      JANICE
    A100 AUSTIN     JAMES
    M100 MARTINEZ   SHEILA
    K100 KZOCHSKY   TAMARA
    P100 PORTER     LISA
    A105 ADAMS      JUAN
    B100 BAKER      JACK
    P105 PETERSON   TINA
    W100 WHITE      WILLIAM
    W105 WHITE      LISA
    R100 ROBINSON   ROBERT
    F100 FIELDS     OSCAR
    W110 WILKINSON  ANTHONY
    14 rows selected.
    with
       iisbn as (      select isbn, count(isbn) cnt from orderitems group by isbn )
    SELECT ii.isbn, ba.authorid, ii.cnt
      FROM bookauthor ba, iisbn ii
    where ba.isbn = ii.isbn

  • 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 insert with jsp

    Please i need help on how to enter multiple row into mysql with one insert
    statement and jsp , i have been trying this for weeks without sucess e.g
    <---- THIS AN EXAMPLE OF MY INSERT FORM ---->
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="some sort of jsp page">
    mike : <input type="text" name="staffid" />
    john : <input type="text" name="staffid" />
    peter :<input type="text" name="staffid" />
    james :<input type="text" name="staffid" />
    jerry :<input type="text" name="staffid" />
    mikel: <input type="text" name="staffid" />
    <input name="submit" type="button" />
    </form>
    </body>
    </html>
    <--MY DATABASE LOOKS LIKE --->
    name | staffid |
    | |
    | |
    | |
    I have been looking for a way to enter only the value or all the values that is entered by
    the user.

    ODAFEONIHOWO wrote:
    Please i need help on how to enter multiple row into mysql with one insert
    statement and jsp it's not possible - you'll need to do a batch insert
    i have been trying this for weeks without sucess e.g how much experience do you have with Java?

  • Multiple-Row Subquery

    Newbie needs help again.
    My SQL statement returns multiple rows, but even after reading the manuals I still cannot figure out how to use the IN, ANY or ALL operators to make it multiple-row.
    Version:
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE 10.2.0.1.0 Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    update proj_assigned
    set project_cost = (select job_charge_per_hour * hours_allocated from proj_assigned);
    RESULT:: single-row subquery returns more than one row
    Edited by: 996465 on 2013/03/28 10:47 AM

    thank you.
    The SQL statement must update the project_cost table with the correct value, that is job_charge_per_hour x hours_ allocated.
    the table:
    Column Name Data Type Nullable Default Primary Key
    PROJ_ID VARCHAR2(10) No - 1
    EMP_ID VARCHAR2(10) No - 2
    JOB_CODE VARCHAR2(10) Yes - -
    JOB_CHARGE_PER_HOUR NUMBER(7,2) Yes - -
    HOURS_ALLOCATED NUMBER(5,0) Yes - -
    PROJECT_COST NUMBER(10,2) Yes - -
    The data:
    PROJ_ID------------ EMP_ID-------------- JOB_CODE--------------- JOB_CHARGE_PER_HOUR------------- HOURS_ALLOCATED------------ PROJECT_COST
    ABCSYS -------------FLANAGJ------------ WEBDES ------------------150 -------------------------------------------10------------------------------------ 1500
    ABCSYS------------- NKOSIM------------- WEBDES ------------------150------------------------------------------- 5-------------------------------------- 750
    HRFIN---------------- NAIDOOL----------- HRFIN-----------------------100------------------------------------------ 10------------------------------------- 1000
    HRFIN---------------- sithols---------------- WEBDES------------------ 140------------------------------------------ 10------------------------------------- 1400
    PRIMWEB----------- becker--------------- WEBDES-------------------150------------------------------------------ 100----------------------------------- 15000
    QWENET----------- NAIDOOL-------------HRFIN---------------------- 100------------------------------------------ 10------------------------------------ 1000
    QWENET----------- SEOPAT --------------ITMNG---------------------150--------------------------------------------10------------------------------------ 1500
    QWENET----------- singhs------------------SYSANA------------------ 150------------------------------------------- 10------------------------------------ 1500
    QWENET----------- beckerl----------------SYSANA -------------------10--------------------------------------------- 5-------------------------------------- 50

  • 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.

  • 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

  • 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

  • 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 in multiple-row subqueries

    Hello,
    in a test i saw 2 questions:
    Which operator can be used with a multiple-row subquery?
    A. =
    B. LIKE
    C. BETWEEN
    D. NOT IN
    E. IS
    F. <>
    Answer: D
    and
    Which two statements about subqueries are true? (Choose two.)
    A. A single row subquery can retrieve data from only one table.
    B. A SQL query statement cannot display data from table B that is referred to in its
    subquery, unless table B is included in the main query's FROM clause.
    C. A SQL query statement can display data from table B that is referred to in its subquery,
    without including table B in its own FROM clause.
    D A single row subquery can retrieve data from more than one table.
    E. A single row subquery cannot be used in a condition where the LIKE operator is used for
    comparison.
    F. A multiple-row subquery cannot be used in a condition where the LIKE operator is used for
    comparison.
    Answer: B & D
    But in the last question, why F is not correct? because the 1st question says that only NOT IN can be used in multiple-row subqueries. I'm confused
    Thanks

    only two, but what principle applies if not specified? First two correct?
    however, in explanation i saw something like this (regarding to the 2nd question)
    Incorrect Answers
    A: A single row sub-query can retrieve data from more than one table.
    C: A SQL query statement cannot display data from table B that is referred to in its subquery,
    unless table B is included in the main query's FROM clause.
    E: A single row sub-query can be used in a condition where the LIKE operator is used for
    comparison.
    F: A multiple-row sub-query can be used in a condition where the LIKE operator is used for
    comparison.
    so, at F: can be used or nor? they aren't so clear. only which operators can be used in multiple-row subquery?

  • Issue with Drag/Drop of multiple rows from ListView

    I am working on a sample application with 2 list views i.e. players and team, and implement drop and drop such that players can be dropped from one list view to the other. Everything is working as expected when there is single selection model is enabled on the source list view. However, if I enabled Multiple selection model and drag 2 or more rows from source list view to target list view, seeing the following exception after the drop is completed.
    Exception:
    java.lang.IllegalArgumentException: Only serializable objects or ByteBuffer can be used as data with data format [subListPlayers]
      at com.sun.javafx.tk.quantum.QuantumClipboard.putContent(QuantumClipboard.java:513)
      at javafx.scene.input.Clipboard.setContent(Clipboard.java:230)
    1) What should be the DataFormat used in order to be able to drag and drop multiple rows? Looks like we do not have for Object type, so I have created the following one which does not solve the problem.
       private DataFormat dataFormat = new DataFormat("subListPlayers");
    2) I have made changes to support serialization on the data object which also does not seem to solve the issue. Tried by implementing Serializable interface as well as by implementing Externalize interface.
    Can someone please guide if there is an easy way to implement this behavior?
    Code:
    public class Player
       private String name;
       public Player(String name)
          this.name = name;
       public String getName()
          return name;
       public void setName(String name)
          this.name = name;
       @Override
       public boolean equals(Object o)
          if (this == o) return true;
          if (o == null || getClass() != o.getClass()) return false;
          Player player = (Player) o;
          if (name != null ? !name.equals(player.name) : player.name != null) return false;
          return true;
       @Override
       public int hashCode()
          return name != null ? name.hashCode() : 0;
    public class JavaFXDnDApplication extends Application
       private static final ListView<Player> playersListView = new ListView<Player>();
       private static final ObservableList<Player> playersList = FXCollections.observableArrayList();
       private static final ListView<Player> teamListView = new ListView<Player>();
       private static final GridPane rootPane = new GridPane();
       private DataFormat dataFormat = new DataFormat("subListPlayers");
       public static void main(String[] args)
          launch(args);
       @Override
       public void start(Stage primaryStage)
          primaryStage.setTitle("Drag and Drop Application");
          initializeComponents();
          initializeListeners();
          buildGUI();
          populateData();
          primaryStage.setScene(new Scene(rootPane, 400, 325));
          primaryStage.show();
       private void initializeListeners()
          playersListView.setOnDragDetected(new EventHandler<MouseEvent>()
             @Override
             public void handle(MouseEvent event)
                System.out.println("setOnDragDetected");
                Dragboard dragBoard = playersListView.startDragAndDrop(TransferMode.MOVE);
                ClipboardContent content = new ClipboardContent();
    //            content.putString(playersListView.getSelectionModel().getSelectedItem().getName());
                content.put(dataFormat, playersListView.getSelectionModel().getSelectedItems());
                dragBoard.setContent(content);
          teamListView.setOnDragOver(new EventHandler<DragEvent>()
             @Override
             public void handle(DragEvent dragEvent)
                dragEvent.acceptTransferModes(TransferMode.MOVE);
          teamListView.setOnDragDropped(new EventHandler<DragEvent>()
             @Override
             public void handle(DragEvent dragEvent)
    //            String player = dragEvent.getDragboard().getString();
    //            ObservableList<Player> player = (ObservableList<Player>) dragEvent.getDragboard().getContent(dataFormat);
                String player = dragEvent.getDragboard().getString();
                teamListView.getItems().addAll(new Player(player));
                playersList.remove(new Player(player));
                dragEvent.setDropCompleted(true);
       private void buildGUI()
    //      rootPane.setGridLinesVisible(true);
          rootPane.setPadding(new Insets(10));
          rootPane.setPrefHeight(30);
          rootPane.setPrefWidth(100);
          rootPane.setVgap(20);
          rootPane.setHgap(20);
          rootPane.add(playersListView, 0, 0);
          rootPane.add(teamListView, 1, 0);
       private void populateData()
          playersList.addAll(
                new Player("Adam"), new Player("Alex"), new Player("Alfred"), new Player("Albert"),
                new Player("Brenda"), new Player("Connie"), new Player("Derek"), new Player("Donny"),
                new Player("Lynne"), new Player("Myrtle"), new Player("Rose"), new Player("Rudolph"),
                new Player("Tony"), new Player("Trudy"), new Player("Williams"), new Player("Zach")
          playersListView.setItems(playersList);
       private void initializeComponents()
          playersListView.setPrefSize(250, 290);
          playersListView.setEditable(true);
          playersListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          playersListView.setCellFactory(new Callback<ListView<Player>, ListCell<Player>>()
             @Override
             public ListCell<Player> call(ListView<Player> playerListView)
                return new ListCell<Player>()
                   @Override
                   protected void updateItem(Player player, boolean b)
                      super.updateItem(player, b);
                      if (player != null)
                         setText(player.getName());
          teamListView.setPrefSize(250, 290);
          teamListView.setEditable(true);
          teamListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
          teamListView.setCellFactory(new Callback<ListView<Player>, ListCell<Player>>()
             @Override
             public ListCell<Player> call(ListView<Player> playerListView)
                return new ListCell<Player>()
                   @Override
                   protected void updateItem(Player player, boolean b)
                      super.updateItem(player, b);
                      if (player != null)
                         setText(player.getName());

    Yeah, this is a pain. I filed https://javafx-jira.kenai.com/browse/RT-29082 a while back. Go ahead and vote for it if you are inclined...
    I think the issue in your case is that the observable list provided by MultipleSelectionModel.getSelectedItems() is not Serializable. So even if you make your Player class Serializable, the list itself isn't. The first thing I would try, I think, is to make Player implement Serializable and then pass in an ArrayList instead of the observable list. So you can do
    content.put(dataFormat, new ArrayList<Player>(playersListView.getSelectionModel().getSelectedItems()));
    and
    List<Player> player = (List<Player>) dragEvent.getDragboard().getContent(dataFormat);
    teamListView.getItems().addAll(player);
    If that doesn't work, a workaround is just to store the "dragged list" in a property:
    final ListProperty<Player> draggedPlayers = new SimpleListProperty<Player>();
    // Drag detected handler:
    content.putString("players");
    draggedPlayers.set(playersListView.getSelectionMode().getSelectedItems());
    // Drag dropped handler:
    if (dragboard.hasString() && dragboard.getString().equals("players")) {
         teamListView.getItems().addAll(draggedPlayers.get());
         draggedPlayers.set(null);

  • 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.

Maybe you are looking for