How to use LIKE Operator with my query requriment

HI all,
I have a requirement as follows
EMPID ENAME JOB SAL
10 RAJ KAMAL MANAGER 25000
20 KAMAL RAJ NAYAK CLERK 4000
30 NARENDAR GUPTA ANALYST 20000
40 ASHUTOSH GUPTA DEVELOPER 10000
50 ASHUTOSH NAYAR PROGRAMMER 15000
i am searching enames such that i need to get the whole name even if i search with just a single LETTER/WORD immaterial of the order they exist in the name for which i need to get the whole name.(INFACT WORD comparision)
ex:
1) select * from emp where ename like '%ka%'
i am getting:
10 RAJ KAMAL MANAGER 25000
20 KAMAL RAJ NAYAK CLERK 4000
This is not what i need i need just word camparision not letters comparision let me tell you...
select * from emp where ename like '%amal%'
Even for this query ill get the same output.. this is not my option to go..
I need just word comparision with starting letter and immaterial of the word position in the name
If it is possible to do with query please let me know..
Thanking you
Narendar Vishwanatham

Full example:
SQL> ed
Wrote file afiedt.buf
  1  with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all
  2             select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all
  3             select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all
  4             select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all
  5             select 50, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual)
  6  -- END OF TEST DATA
  7  select *
  8  from e
  9* where regexp_like(ename,'(^| )KA( |$)')
SQL> /
no rows selected
SQL> ed
Wrote file afiedt.buf
  1  with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all
  2             select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all
  3             select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all
  4             select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all
  5             select 50, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual)
  6  -- END OF TEST DATA
  7  select *
  8  from e
  9* where regexp_like(ename,'(^| )KAMAL( |$)')
SQL> /
     EMPID ENAME           JOB               SAL
        10 RAJ KAMAL       MANAGER         25000
        20 KAMAL RAJ NAYAK CLERK            4000
SQL>

Similar Messages

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

  • How to use LIKE operator in plsql

    Hi
    I wanted to select certain rows using like operator in plsql(Input should be given by the user). I have given my experiment here .I couldn't get any result.
    As per sql syntax while using LIKE operator we should give search criteria within single quote.where as in plsql if we give within single quote its takes as string so no output is comming.what is solution ? How to use like operator in plsql?
    sql syntax
    SQL>SELECT customer_name FROM customer_header
    WHERE customer_name LIKE 'B%' ; customer_name
    Bala murali
    Babu
    Basker
    plsql syntax
    PROCEDURE pro_custheader_like ( v_cname IN varchar2
         ,answer OUT type_refcur_customer) IS
         BEGIN
         OPEN answer FOR
         SELECT customer_name FROM customer_header
              WHERE customer_name LIKE ( ' v_cname ' );
    END pro_custheader_like;
    execution command
    sql>variable answer refcursor;
    sql>set serveroutput on
    sql>exec package_name.pro_custheader_like( 'R',:answer);
    plsql successfully completed
    sql>print :answer
    no row selected
    by
    balamuralikrishnan.s

    plsql syntax
    PROCEDURE pro_custheader_like ( v_cname IN
    varchar2
    ,answer OUT
    type_refcur_customer) IS
    N
         OPEN answer FOR
         SELECT customer_name FROM customer_header
    WHERE customer_name LIKE ( v_cname );
    END pro_custheader_like;
    Try it without any quotes. And, let us know your feedback.
    Regards.
    Satyaki De.
    Message was edited by:
    Satyaki_De

  • How tio use like operator in textitem to get the name

    Oracle forms6i
    Hai All
    I have created an form to create an hierarchy list. I that I had an Text_item how can i use like operator to get the name to select. which trigger i need to use. when i select the name i need to get his employee code and other details
    Thanks In Advance
    Srikkanth.M

    A is the head of Dept 10 and three person are under A namelyHow will you know that B, C and D are under A is there any parent child relationship between Leader and Employee code? If yes, Then you can create the relationship between blocks no need to set where_clause programatically. So, relationship can be like...
    leader_block.emp_code = emp_block.leader_code
    AND leader_blokc.dep_code = emp_block.dep_codeSo, when you will query data in LEADER block it will show employees which are under LEADER which you queried in LEADER block.
    Or if there is no relationship then how will you know that which employee under which leader?
    b 002 10 1
    c 003 10 1
    d 004 10 1
    When i enter the name of head corresponding other members in the department will need to display in the
    Tabular format Or if you want to query the records only for department relation. Then as you said you create two blocks then create create the relationship using dep_code between those blocks.
    like...
    leader.dep_code = emp_block.dep_code-Ammad

  • How to use like operator in loop

    Hi I am trying to use like operation in loop condition. the code is as follows:
    loop at lt_mara into l_mara where l_mara like '%XXX'.
    endloop
    when i have the like operator like above its giving me an error that i cannot use like operator. Is there anyway that i can use like operation in loop at condition,
    Thanks in advance

    using the ranges with CP option we can do that..
    Populate the ranges mentioned below..
    data: r_matnr type range of matnr,
            w_matnr like line of r_matnr.
    w_matnr-low = '%XXX'.
    w_matnr-sign = 'I'.
    w_matnr-option = 'CP'.
    append w_matnr to r_matnr.
    loop at lt_mara into l_mara where matnr in r_matnr.
    endloop
    Regards
    Vijay Babu Dudla

  • How to use like operator in IFTHENELSE (BODS)

    Hi All,
    I want to find the value of  ' % ASSOC%' in the name and replace it to 'Assoc.' using ifthenelse.
    Can any one help me. Is there any similar fuction as LIKE operator. Can we give LIKE in ifthen else condition.
    Thanks in advance

    Hi ,
    if you have data ASSOC1,ASSOC2
    and you want Output like Assoc.1,Assoc.2.
    In this condition it is not possible with ifthenelse function
    it will return output as Assoc.
    Example Source:
    If we use if then else condition. Then it will replace all the Data to Assoc. 
    Or else if you want to replace ASSOC to Assoc. Then you can use Search_Replace also
    it will generate a XML script
    The expected output as follows in the below screen. As per your requirement you can you any one of this.
    Regards,
    Akhileshkiran.

  • How to use filter operator with ROWNUM

    I would like to add filter operator in my mapping with ROWNUM to reduce the ETL loading time during testing to ensure mapping is working, but I don't know how, please help provide me some guideline. Thank you.

    what is your owb version?
    Starting with Oracle Warehouse Builder 10.2.0.3, you can use the pseudocolumns ROWID and ROWNUM in mappings. The ROWNUM pseudocolumn returns a number indicating the order in which a row was selected from a table. The ROWID pseudocolumn returns the rowid (binary address) of a row in a database table.
    You can use the ROWID and ROWNUM pseudocolumns in Table, View, and Materialized View operators in a mapping. These operators contain an additional column called COLUMN USAGE that is used to identify attributes used as ROWID or ROWNUM. For normal attributes, this column defaults to TABLE USAGE. To use an attribute for ROWID or ROWNUM values, set the COLUMN USAGE to ROWID or ROWNUM respectively.
    You can map a ROWID column to any attribute of data type ROWID, UROWID, or VARCHAR2. You can map ROWNUM column to an attribute of data type NUMBER or to any other data type that allows implicit conversion from NUMBER.
    Note that ROWID and ROWNUM pseudocolumns are not displayed in the Data Object Editor since they are not real columns.
    Edited by: Darthvader-647181 on Oct 29, 2008 9:18 AM

  • How to use Airthmetic operator in hibernate Query

    Hi everybody,I am writing a hibernate query that multiply two attributes and takes it sum, but when I use * operator,it gives error "* only allowed inside aggregate function in SELECT " . HQL query is :
    Select
    sum(postab.subtotal),
    sum(postab.tax),
    sum(postab.total),
    count(postab.checknum) ,
    Sum((postab.subtotal)*(loc.royalty)/100)
    From
    com.infonox.hibernate.Location as loc,
    com.infonox.hibernate.Postables as postab
    where loc.restaurantid = postab.restaurantid
    Line which is creating problem is
    Sum((postab.subtotal)*(loc.royalty)/100)
    Is there any other way to take product of two attributs? your help will be greatly appreciated as it is really stumbling block in my project. Thanks in advance

    Sum((postab.subtotal)*(loc.royalty)/100)
    Is there any other way to take product of two
    attributs? your help will be greatly appreciated as
    it is really stumbling block in my project. Thanks in
    advanceSuch a stumbling block should have inspired more activity on your part.
    I'd try rewriting it like this:
    sum(postab.subtotal*loc.royalty/100)[/b]%

  • How to use order by with hierarchical query

    I have a hierarchical query basically it brings back an organization chart. We start with a manager's id, get all that person's employees. If any of the employees is also a manager I want to get that person's employees and return them right after that person. I won't bother with the whole query but relevant part is:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;Where pi_mgr_id is a parameter passed to the procedure and em is the alias for the emp_mgr_relationship table which contains emp_id and mgr_id. This works fine. What I want now is for the employees who work for the same manager to appear in name order. The table which contains the employee names is aliased as pe and the name column is called name1. I added the following:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            order by pe.name1;But that put the entire list in name order. What I want is for employees who work for the same manager to be in name order. Let's the manager whose organization I want is named Frank. What I'd like to get is this
    EMP_NAME    MGR_NAME
    Allen       Frank
    Beth        Frank
    Alex        Beth
    Charles     Beth
    Ed          Beth
    Dean        Frank
    George      Frank
    Benny       George
    David       George
    Sam         George
    Dan         Sam
    Harry       Sam
    John        Sam
    Terry       George
    James       Frank
    Ken         Frank
    Mike        Ken
    Warren      KenHow do I get the list in this order?
    Edited by: kendenny on Jul 28, 2010 7:31 AM

    Make use of ORDER SIBLINGS clause in hierarchial queries to set the order by child columns.
    START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            *order siblings by name1;*

  • How to use LIKE function with a parameter in Oracle REPORT builder??

    how could i use parameter inside a LIKE function in Oracle reports builder?
    it works in SQL plus, but not in report builder!!
    Example:
    select code,desc from item_master where desc
    like '%&give_desc%'; ---works in SQL
    like '%:give_desc%' ---doesn't work in report builder!!

    Hi Renil,
    You will need to use the wildcard character (%) and the concatenation character (||) to join to your user parameter.
    i.e. like '%'||:give_desc||'%'
    Regards,
    John

  • How to use EQUIV operator in a query?

    i want to list products whose names like 'Windows XP' or 'WindowsXP', following is my query:
    select * from product
    where contains(product_name,'Windows XP = WindowsXP',1) > 0
    but this query only return the products whose name contain 'Windows XP'. the result is something likes
    select * from product
    where contains(product_name,'Windows (XP = WindowsXP)',1) > 0
    so i modified it to :
    select * from product
    where contains(product_name,'(Windows XP) = (WindowsXP)',1) > 0
    it's error
    Error report:
    SQL Error: ORA-29902: error in executing ODCIIndexStart() routine
    ORA-20000: Oracle Text error:
    DRG-50900: text query parser error on line 1, column 26
    DRG-50921: EQUIV operand not a word or another EQUIV expression
    29902. 00000 - "error in executing ODCIIndexStart() routine"
    *Cause:    The execution of ODCIIndexStart routine caused an error.
    *Action:   Examine the error messages produced by the indextype code and
    take appropriate action.

    Equiv only works for individual terms. Since there is a space between Windows and XP, they are two terms. You can use synonyms for phrases containing multiple terms, as shown below.
    SCOTT@orcl_11g> CREATE TABLE product (product_name  VARCHAR2 (30))
      2  /
    Table created.
    SCOTT@orcl_11g> INSERT ALL
      2  INTO product VALUES ('Windows XP')
      3  INTO product VALUES ('WindowsXP')
      4  INTO product VALUES ('Unix')
      5  SELECT * FROM DUAL
      6  /
    3 rows created.
    SCOTT@orcl_11g> BEGIN
      2    CTX_THES.CREATE_THESAURUS ('name_thes');
      3    CTX_THES.CREATE_RELATION ('name_thes', 'Windows XP', 'SYN', 'WindowsXP');
      4  END;
      5  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11g> CREATE INDEX product_name_idx ON product (product_name)
      2  INDEXTYPE IS CTXSYS.CONTEXT
      3  /
    Index created.
    SCOTT@orcl_11g> SELECT * FROM product
      2  WHERE  CONTAINS (product_name, 'SYN (Windows XP, name_thes)') > 0
      3  /
    PRODUCT_NAME
    Windows XP
    WindowsXP
    SCOTT@orcl_11g> SELECT * FROM product
      2  WHERE  CONTAINS (product_name, 'SYN (WindowsXP, name_thes)') > 0
      3  /
    PRODUCT_NAME
    Windows XP
    WindowsXP
    SCOTT@orcl_11g>

  • How to use hint on with clause query

    Hi all,
    I have a query and it consits full of tabs with WITH clause. Top level I am just selecting all the tabs (queries with WITH clause) by saying select * from tab1,tab2,.....so on .
    Now my question is If I want to use hint on my SQL can I use the same by using tab1,tab2...
    tab1, tab2 are not actually tables ....each tab represents one SQL with WITH clause.
    Please let me know if there is any confusion on my post.

    What's stopping you from trying it yourself?
    Post your results here to help others.

  • Using like operator with attributes in select command

    Hi,
    I have a table with the attributes as DID, PNO,AGE, DEPARTMENT, DATEOFADM, CHARGES, ADDRESS, DOD
    I want to display the records with the months in DOD and DATEOFADM same. How can I do so? I also want to do the same with the dates in the 2 attributes.
    Thanks
    Edited by: 1004111 on May 23, 2013 1:51 AM

    Hi,
    Please read SQL and PL/SQL FAQ
    When you put some <b>code or output</b> please enclose it between two lines starting with {noformat}<b></b>{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    You should post create table and insert statement for your requirement.
    You can check if 2 dates have the same month in either way:-- this is comparing year and month
    SELECT *
    FROM yourtable
    WHERE TRUNC(dod,'MM')=TRUNC(dateofadm,'MM');
    -- or in case you want to compare only months no matter the year
    SELECT *
    FROM yourtable
    WHERE EXTRACT(MONTH FROM dod) = EXTRACT(MONTH FROM dateofadm);
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to pass variable into lov sql query using like operator

    hi.
    i want to use a lov where i want to pass a variable using like operator.
    my query is
    select empno,name from table where empno like ':ed%';
    my empno is A001 TO A199 AND B001 TO B199 so i want show either A% or B% empno
    how can i do this ?
    reagrds

    kindly press Shift+F1 at a time you face this error to see the exact Oracle error message.
    and provide us with that detail
    and its better if you start new topic for that error... because that will be new error,,,
    -- Aamir Arif
    Edited by: Aamiz on Apr 7, 2010 12:27 PM

  • Error in SQL Query The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query

    hi Experts,
    while running SQL Query i am getting an error as
    The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. for the query
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    T2.LineText
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,T2.LineText
    how to resolve the issue

    Dear Meghanath,
    Please use the following query, Hope your purpose will serve.
    select  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price ,
    CAST(T2.LineText as nvarchar (MAX))[LineText]
    from OQUT T0  INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry LEFT OUTER JOIN
    QUT10 T2 ON T1.DocEntry = T2.DocEntry --where T1.DocEntry='590'
    group by  T1. Dscription,T1.docEntry,T1.Quantity,T1.Price
    ,CAST(T2.LineText as nvarchar (MAX))
    Regards,
    Amit

Maybe you are looking for

  • Running two displays from one DVI port...time to put my ADC down

    Hi Guys, I have a G5 dual with a GeForce FX 5200 which has 1 each of DVI+ADC ports. Until recently the 17" Apple display has been my only monitor. As I have a recording/mix studio I need to move the G5 base unit far away from any recording as it make

  • Use UIX demo 2.1.7 in my application

    Hello, I have download uix-demo-2.1.7.zip and run Shopping Cart Demo. It work very well. I would like to also have a preference page in my application, as in the demonstration. I recovered the two files Preferences.java and Preferences.uix. I modifie

  • WLST domain configuration readTemplate problem

    Hi, I am getting java.lang.NoClassDefFoundError when I try to invoke readTemplate operation while installing WLS90 domain on solaris environment. I sourced $WL_HOME/server/bin/setWLSEnv.sh before I invoked WLST shell. Can anyone shed some light on th

  • Oracle Globalization - GetSessionInfo

    I am using ODP.Net OracleGlobalization class to get the SessionInfo and then to override the sessionInfo settings. I am able to override these settings properly on an English OS with the NLS_Lang set to American_America.AL32UTF8. After overridding th

  • Random changes when changing setting for individual slide in a slideshow

    I've used iPhoto for years and produced many slideshows. However, now when I try to use Ken Burns Effect for an individual slide, I click on the "start" area, adjust my slide, click on "end," and then iPhoto jumps to a totally different slide in the