LIKE OPERATOR QUESTION

Hi All,
Quite simply I don't really understand two things.
1) How is the LIKE operator is working to return both columns.
2) When to use the LIKE operator and when to use the relation operator.
Thanks.
(CODE)
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa LIKE bb
--returns both columns
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa = bb
--returns nothing
(/CODE)

Hi,
DaveyB wrote:
Hi All,
Quite simply I don't really understand two things.
1) How is the LIKE operator is working to return both columns.The WHERE clause (whether it contains LIKE or anything else) will only control the number of rows: every row will have the same numberr of columns.
2) When to use the LIKE operator and when to use the relation operator.Use LIKE when you want to use "wildcards" (% or _).
Use other operators (like =) when you don't have wildcards.
(CODE)
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa LIKE bb
--returns both columns
SELECT *
FROM ( SELECT TO_DATE ('01/01/2009 12:01:01', 'DD/MM/YYYY HH24:MI:SS') aa,
TO_DATE ('1-Jan-2009') bb FROM DUAL
WHERE aa = bb
--returns nothing
(/CODE)It's great that you're trying to format your code! I wish everyione did that.
Use square brackets ([ and ]) if you want to use [CODE] and [/CODE] tags.
LIKE operates on strings. Don't use a DATE where a string is required. Do some experiments like the ones you tried just using strings, if you want to see how LIKE behaves.

Similar Messages

  • Very Newbie LIKE operator question

    HI, I am a newbie just starting out with sql. I am trying to find all customers with last name that starts with L. This is what I tried and got no rows selected.
    SELECT *
    FROM Customer
    WHERE LastName LIKE '*L';
    What is the correct syntax?

    in 10g
    SQL> ed
    Wrote file afiedt.buf
      1* select empno,ename from emp where regexp_like(ename,'^A|^a')
    SQL> /
         EMPNO ENAME
          7499 ALLEN
          7876 ADAMSso for you
    select empno,ename from emp where regexp_like(ename,'^L|^l')

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

  • 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

  • Characters allowed inside LIKE operator

    Hi,
    DB: Oracle 10g
    SELECT   count(*)
      FROM   mytable
    WHERE   LOWER(mycolumn) LIKE LOWER('%<th sc="row">Havana</th>%')I am not sure if this pattern will be matched by LIKE operator because it has all sorts of
    characters as you can see -> <, = ", /.
    So, my questions
    1. What characters are allowed inside LIKE?
    2. Any other way of doing the same query?
    3. Index on column "mycolumn" will be invalidated by %. right?
    Please advise.
    Thanks.
    Edited by: abyss on Sep 23, 2010 3:50 PM

    even the like statement will do the same(will not use Index) :)
    to answer your first question, the char you have inthe SQL should be fine., I think it will work for all char except for
    %   and _   You can try with the REGEXP as alternate solution
    Edited by: Prasath on Sep 23, 2010 1:56 PM

  • [VB] Like operator not functioning?

    I'm trying to create the following statement in my VB code, but I'm getting a "Sub or Function not defined" error. My question is, how do you use the Like operator with InDesign scripting? InDesign doesn't seem to recognize the Like operator.
    "myCurrentString" contains a letter.
    If myCurrentString Like "[A-z]" Then
    End If
    I'm also trying to do the following:
    If myCurrentDigit Like "[0-9]" Then
    End If

    I couldn't find "RegExp" in the InDesign script model--could you give a bit more information about what this is? I don't know how to iterate through the contents of an XMLElement as individual character objects, so I'm iterating throught XML.contents, putting each character in a basic string variable. I need a way to put strings into a With statement, or a Like operator. I haven't had success with either technique.
    Here's an example:
    strTime = myCurrentXMLElement.contents
    strTime = Trim(strTime)
    strLength = Len(strTime)
    For counter = 1 to strLength
    strTemp = Mid(strTime, counter, 1)
    [This is where I need to find out if strTemp is a letter or a digit]
    Next

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

  • Can I use a LIKE operator in an IF statement in a column formula

    This is what I have so far.
    CASE WHEN Opportunity."Sales Type" LIKE '*New Acct' THEN 'Sale to NEW Customer' END
    I want to display 'Sale to NEW Customer' if opportunity type contains the terms New Acct.

    Try this:
    CASE WHEN Opportunity."Sales Type" LIKE '%New Acct' THEN 'Sale to NEW Customer' END
    The LIKE operator requires a % wildcard rather than the * wildcard.
    Mike L.

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

  • [Microsoft][SQL Server Native Client 11.0][SQL Server]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.  'Items' (OITM) (OITM)

    Dear Experts,
    i am getting the below error when i was giving * (Star) to view all the items in DB
    [Microsoft][SQL Server Native Client 11.0][SQL Server]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.  'Items' (OITM) (OITM)
    As i was searching individually it is working fine
    can any one help me how to find this..
    Regards,
    Meghanath.S

    Dear Nithi Anandham,
    i am not having any query while finding all the items in item master data i am giving find mode and in item code i was trying to type *(Star) and enter while typing enter the above issue i was facing..
    Regards,
    Meghanath

  • 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

  • Like operator functionality

    We have a simple select query which is using the 'Like' operator on a char(4) column.
    In a oracle windows environment when we have a query such as:
    select col1, col2, col3
    from table1
    where col1 like 'AB'
    it returns everything which is = to 'AB' and doesn't seem to be including the trailing 2 spaces as would be stored becasue the column is char(4)
    In a oracle unix environment when we the same query:
    select col1, col2, col3
    from table1
    where col1 like 'AB'
    it returns nothing...
    It appears as if the version running on a windows environment is truncating the trailing 2 spaces when using the like expression but in a unix environment, it is not. Does anybody have any idea or clue what could be occuring or if there is some database setting which could cause this to occur?

    Quote from Oracle Doc:
    Character Values
    Character values are compared using one of these comparison rules:
    Blank-padded comparison semantics
    Nonpadded comparison semantics
    The following sections explain these comparison semantics.
    Blank-Padded Comparison Semantics If the two values have different lengths, then Oracle first adds blanks to the end of the shorter one so their lengths are equal. Oracle then compares the values character by character up to the first character that differs. The value with the greater character in the first differing position is considered greater. If two values have no differing characters, then they are considered equal. This rule means that two values are equal if they differ only in the number of trailing blanks. Oracle uses blank-padded comparison semantics only when both values in the comparison are either expressions of datatype CHAR, NCHAR, text literals, or values returned by the USER function.
    Nonpadded Comparison Semantics Oracle compares two values character by character up to the first character that differs. The value with the greater character in that position is considered greater. If two values of different length are identical up to the end of the shorter one, then the longer value is considered greater. If two values of equal length have no differing characters, then the values are considered equal. Oracle uses nonpadded comparison semantics whenever one or both values in the comparison have the datatype VARCHAR2 or NVARCHAR2.
    "

  • Using Like Operator in a decode function

    Hi,
    I am trying to find out if I can use the like operator in a decode function
    like:
    select decode(1234,like '%123%','123 is a match') from dual;
    this reults in error ORA-00936: missing expression
    is there any way to make this work?
    thank you

    SQL> ed
    Wrote file afiedt.buf
      1  WITH tbl AS (SELECT '201aaa' dt FROM DUAL UNION ALL
      2               SELECT '123bbb' dt FROM DUAL UNION ALL
      3               SELECT '567ccc' dt FROM DUAL UNION ALL
      4               SELECT 'ab123ddd' dt FROM DUAL
      5               )
      6  SELECT dt,CASE WHEN dt like '%123%' THEN 'Match'
      7         ELSE 'Not Matched'
      8         END With_case
      9        ,DECODE(REGEXP_SUBSTR(dt,'123'),NULL,'Not Match','Match')   With_Regexp
    10        ,DECODE(INSTR(dt,'123'),0,'Not Match','Match') With_Instr
    11        ,DECODE(REPLACE(dt,'123'),dt,'Not Match','Match') With_Replace
    12* FROM tbl
    SQL> /
    DT       WITH_CASE   WITH_REGE WITH_INST WITH_REPL
    201aaa   Not Matched Not Match Not Match Not Match
    123bbb   Match       Match     Match     Match
    567ccc   Not Matched Not Match Not Match Not Match
    ab123ddd Match       Match     Match     MatchEdited by: Saubhik on Jul 26, 2010 5:24 AM
    Edited by: Saubhik on Jul 26, 2010 5:40 AM
    Edited by: Saubhik on Jul 26, 2010 5:40 AM

  • LIKE operator is not working in SQL Query in XML file

    Hi Gurus,
    LIKE operator is not working in SQL query in XML template.
    I am creating a PDF report in ADF using Jdeveloper10g. The XML template is as follows
    <?xml version="1.0" encoding="WINDOWS-1252" ?>
    <dataTemplate name="catalogDataTemplate" description="Magazine
    Catalog" defaultPackage="" Version="1.0">
    <parameters>
    <parameter name="id" dataType="number" />
    <parameter name="ename" dataType="character" />
    </parameters>
    <dataQuery>
    <sqlStatement name="Q1">
    <![CDATA[
       SELECT ename, empno, job, mgr from EMP where deptno=:id and ename LIKE :ename || '%']]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="EmployeeInfo" source="Q1">
    <element name="EmployeeName" value="ename" />
    <element name="EMPNO" value="empno" />
    <element name="JOB" value="job"/>
    <element name="MANAGER" value="mgr" />
    </group>
    </dataStructure>
    </dataTemplate>
    if i pass the parameter value of :ename from UI, it doesn't filter. But if I give ename = :ename it retrieves the data. Can anyone help me why LIKE operator doesn't work here?
    Appreciate your help,
    Shyamal
    email: [email protected]

    Hi
    Well for a start, you are doing some very strange conversions there. For example...
    and to_char(a.msd, 'MM/DD/YYYY') != '11/11/2030'
    and to_char(a.msd, 'MM/DD/YYYY') != '10/10/2030'If a.msd is a date then you should e converting on the other side ie.
    and a.msd != TO_DATE('11/11/2030', 'MM/DD/YYYY')
    and a.msd != TO_DATE('10/10/2030', 'MM/DD/YYYY')Also, you may want to take into consideration nothing being input in :P2_ITEM_NUMBER like this...
    AND INSTR(a.item_number,NVL(:P2_ITEM_NUMBER,a.item_number)) > 0Is item number actually a number or char field? If it's a number, you want to explicitly convert it to a string for using INSTR like this...
    AND INSTR(TO_CHAR(a.item_number),NVL(TO_CHAR(:P2_ITEM_NUMBER),TO_CHAR(a.item_number))) > 0?
    Cheers
    Ben

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

Maybe you are looking for

  • How to print more than one page at a time

    I have not seen any place on the scanner where you can set the number of pages you want to print. I am using a hp diskjet 3050. thank you

  • Can anyone tell me how can I watch any video on Firefox without Adobe Flash Plugin?

    OK I don't know but the latest version of flash player really frustrated me. I don't like Chrome been my entire life Firefox user, but I will have to switch over since I can't stand adobe flash plugin. I uninstalled it and after reboot Firefox automa

  • Layouts in CO24 missing

    Hello! After the Upgrade from R/3 46C to ECC 600 the Layouts of the CO24 are missing. Only the standard layouts "Material View" and "Order View" are available. Could anybody help me, thanks a lot, Barbara

  • Constant Creative Cloud update error

    iMac with 2.93 GHz Intel Core 17 + OS 10.9.1 - I get constant notes that uploads are not possible, while on my macbook everything is okay, it seems - apart from LogTransport2 note I shall "kill" that programm. It's upsetting, really. Premier Pro CC /

  • J2IUN POSTINGS

    HI all, i have done transaction of sale. material is maintain with all necessary inputs of J1ID. i check in J2iun for duty utilization but no value is posted. for the material i check table J_1IEXCDTL. in that i can see only base value but no BED SED