Binding with a LIKE query

I am using PHP and ORACLE and am having trouble with binding. I can get a basic bind to work, but I am having trouble with a more complex query like this:
$oracle_search_name = 'some input text';
$query1 = "SELECT source_title FROM records WHERE UPPER(source_title) LIKE UPPER('%$oracle_search_name%')";
It works OK without binding, but how can I replace $oracle_search_name with a bind variable? Simply replacing the $ sign with a colon doesn't seem to work.

Hey cj,
Thanks for the help! That seems to do the trick.
I noticed that you capitalized the bind variable in the OciBindByName() function. Is that required? Here is my example:
OciBindByName($s, ":MY_BIND_VARIABLE", $my_bind_variable, -1); // Capitalized ":MY_BIND_VARIABLE"
Also, another question: Will Oracle automatically understand to bind multiple instances of the bind variable like this?
SELECT tid, col1, col2, col3 FROM test1 WHERE UPPER(col1) LIKE UPPER('%'||:my_bind_variable||'%') OR UPPER(col2) LIKE UPPER('%'||:my_bind_variable||'%')
That seems to work correctly but I am having trouble finding a detailed reference online about binding in Oracle.
Thanks again for the input.

Similar Messages

  • Help with simple LIKE query...

    I have a person table, the person table has a field which has their interests... In a form they choose which interests they have i.e. swimming, tennis through checkboxes. What i don't get IS how do i create a query based on this? (for example one person likes swimming and the other tennis:
    SELECT * from Person WHERE interests LIKE '%Swimming%Tennis%';
    the above gives me 0 results any ideas?

    You can avoid difficult application issues by enabling a more appropriate schema.
    Here is a very basic schema that may or may not work for you, but I hope it will give you some ideas. I did not create any unique indexes in this sample, but both PERSON and INTEREST table would have a unique index created on them. The PERSON_INTEREST table would have a non-unique index created for it. I also included a query that shows how to correctly query against this schema. This is in Oracle syntax, but the DDL should be similar to whatever DBMS you are using, and the SQL should be the same.
    I'll be honest, this might be overkill for what you are attempting, but if you plan on extending your project / assignment in anyway, you would be better off with a more complete schema. I hope it helps. Good luck on your project / assignment.
    CREATE TABLE PERSON          (PERSON_ID NUMBER,   NAME_LAST VARCHAR2(20), NAME_FIRST VARCHAR2(20), EMAIL VARCHAR2(30));
    CREATE TABLE INTEREST        (INTEREST_ID NUMBER, INTEREST_DESC VARCHAR2(20));
    CREATE TABLE PERSON_INTEREST (PERSON_ID NUMBER,   INTEREST_ID NUMBER);
    INSERT INTO PERSON VALUES(1, 'SMITH','JOHN','[email protected]');
    INSERT INTO PERSON VALUES(2, 'JONES','FRED','[email protected]');
    INSERT INTO PERSON VALUES(3, 'ANDERSON','TOM','[email protected]');
    INSERT INTO PERSON VALUES(4, 'JACOBSEN','SAM','[email protected]');
    INSERT INTO PERSON VALUES(5, 'PUCKETT','KIRBY','[email protected]');
    INSERT INTO INTEREST VALUES (1,'TENNIS');
    INSERT INTO INTEREST VALUES (2,'SWIMMING');
    INSERT INTO INTEREST VALUES (3,'BOWLING');
    INSERT INTO INTEREST VALUES (4,'TABLE TENNIS');
    INSERT INTO INTEREST VALUES (5,'FISHING');
    INSERT INTO PERSON_INTEREST VALUES (1,1);
    INSERT INTO PERSON_INTEREST VALUES (1,3);
    INSERT INTO PERSON_INTEREST VALUES (1,5);
    INSERT INTO PERSON_INTEREST VALUES (2,2);
    INSERT INTO PERSON_INTEREST VALUES (2,3);
    INSERT INTO PERSON_INTEREST VALUES (3,1);
    INSERT INTO PERSON_INTEREST VALUES (3,2);
    INSERT INTO PERSON_INTEREST VALUES (4,2);
    INSERT INTO PERSON_INTEREST VALUES (4,3);
    INSERT INTO PERSON_INTEREST VALUES (5,4);
    INSERT INTO PERSON_INTEREST VALUES (5,5);
    // Find all the Interests for a Person
    SELECT
       A.NAME_LAST,
       A.NAME_FIRST,
       B.INTEREST_DESC
    FROM
       PERSON A,
       INTEREST B,
       PERSON_INTEREST C
    WHERE
       A.NAME_LAST = 'SMITH'
       AND A.NAME_FIRST = 'JOHN'
       AND A.PERSON_ID = C.PERSON_ID
       AND B.INTEREST_ID = C.INTEREST_ID  
    ORDER BY 3
    NAME_LAST            NAME_FIRST           INTEREST_DESC
    SMITH                JOHN                 BOWLING
    SMITH                JOHN                 FISHING
    SMITH                JOHN                 TENNIS
    // Find all people who likes to swim and bowl
    SELECT
       A.NAME_LAST,
       A.NAME_FIRST
    FROM
       PERSON A,
       INTEREST B,
       PERSON_INTEREST C
    WHERE
       B.INTEREST_DESC IN ('SWIMMING', 'BOWLING')
       AND B.INTEREST_ID = C.INTEREST_ID  
       AND A.PERSON_ID = C.PERSON_ID
    GROUP BY
       A.NAME_LAST,
       A.NAME_FIRST
    ORDER BY 1,2
    NAME_LAST            NAME_FIRST
    ANDERSON             TOM
    JACOBSEN             SAM
    JONES                FRED
    SMITH                JOHN
      

  • Cm:select performance problem with multiple likes query clause

    I have query like <br>
              <b>listItem like '*abc.xml*' && serviceId like '*xyz.xml*'</b><br>
              Can we have two likes clauses mentioned above in the cm:select. The above is executing successfully but takes too much time to process. <br><br>
              Can we simplify the above mentioned query or any solution. Please help me in this issue.<br><br>
              Thanks & Regards,<br>
              Murthy Nalluri

    A few notes:
    1. You seem to have either a VPD policy active or you're using views that add some more predicates to the query, according to the plan posted (the access on the PK_OPERATOR_GROUP index). Could this make any difference?
    2. The estimates of the optimizer are really very accurate - actually astonishing - compared to the tkprof output, so the optimizer seems to have a very good picture of the cardinalities and therefore the plan should be reasonable.
    3. Did you gather index statistics as well (using COMPUTE STATISTICS when creating the index or "cascade=>true" option) when gathering the statistics? I assume you're on 9i, not 10g according to the plan and tkprof output.
    4. Looking at the amount of data that needs to be processed it is unlikely that this query takes only 3 seconds, the 20 seconds seems to be OK.
    If you are sure that for a similar amount of underlying data the query took only 3 seconds in the past it would be very useful if you - by any chance - have an execution plan at hand of that "3 seconds" execution.
    One thing that I could imagine is that due to the monthly data growth that you've mentioned one or more of the tables have exceeded the "2% of the buffer cache" threshold and therefore are no longer treated as "small tables" in the buffer cache. This could explain that you now have more physical reads than in the past and therefore the query takes longer to execute than before.
    I think that this query could only be executed in 3 seconds if it is somewhere using a predicate that is more selective and could benefit from an indexed access path.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • XSQL Using bind params with sql LIKE clause

    I am unable to use a bind-param with the LIKE clause in a SELECT statement.
    eg call .../temp.xsql?name=N
    XSQL query is this:
    <xsql:query max-rows="-1" bind-params="name">
    SELECT last_name
    FROM emp
    WHERE last_name LIKE '?%'
    </xsql:query>
    I have tried a few combinations so far with no success eg:
    WHERE last_name LIKE '{@name}%'
    WHERE last_name LIKE ?||%
    Any ideas?

    I highly recommend using XSQL's real bind variable feature wherever you can. You can read about it in the XSQL Online Documentation (Search for the "Using Bind Variables" section).
    Using this feature is more performant and more secure than using textual substitution variables.
    Here's what your page looks like using textual substitution:
    <page connection="UTD4" xmlns:xsql="urn:oracle-xsql">
      <xsql:query null-indicator="yes" >
        SELECT * FROM TC_HL7_SEG WHERE SEGMENT_CODE LIKE '{@code}%'
      </xsql:query>
    </page> .
    And here's what it would look like using real bind variables:
    <page connection="UTD4" xmlns:xsql="urn:oracle-xsql">
      <xsql:query null-indicator="yes" bind-params="code">
        SELECT * FROM TC_HL7_SEG WHERE SEGMENT_CODE LIKE ?||'%'
      </xsql:query>
    </page> .
    Using real bind variables allows the database to avoid reparsing the SQL statement everytime, which improves performance.
    Steve Muench
    JDeveloper/BC4J Development Team
    Author, Building Oracle XML Applications

  • How to create sql query for item master with operator LIKE with variables?

    hi all,
    How to create sql query for item master with
    operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
    Jeyakanthan

    Hi Jeyakanthan,
    here is an example (put the like statement into the where field)
    SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
    The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
    Regards Steffen

  • Data not getting bind with cursor

    Hi,
    Database: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit
    OS: Windows Server 2003
    Consider following procedure:
    Proc P1() as
    cursor c(in_par varchar2) is select distinct col1, col2 from Table1 where col3 = in_par;
    begin
    for rec_c in c('X') loop
    end loop;
    exception
    end;
    Problem: In most of the execution, the value 'X' passed in cursor c get bind with col3 in where clause and get the desired result. However, in some cases, the value 'X' does not get bind with col3 in where clause. I don't know the steps to re-produce the issue, but it occurs once in a while.
    On querying v$sql_bind_capture, i get 'NULL' in value_string whenever this problem occurs. Otherwise, I get 'X' in v$sql_bind_capture. No exception is thrown anytime.
    What may cause miss of binding constant literal 'X' to cursor?

    Have not seen this error before - PL/SQL not binding SQL statements containing PL/SQL variables, correctly. What at times happen is no bind at all due to name collision. Using the same name for a PL/SQL variable as a SQL column in the SQL statement and scope being such that with name resolution, the SQL column gets preference. This of course does not seem to be the case here.
    What could be happening is that a null variable is being passed as the bind value.
    You can also have a look at the Metalink/support.oracle.com for any notes or bugs on this behaviour. Knee-jerk reaction from my side that this is too a common issue to be an actual PL/SQL bug... (would have reared its head a long time ago)
    In cases like this I like to make sanity checks - reduce the problem to its bare basics with a test case and see if that works. Then gradually increase its complexity and see when it brakes, if at all.

  • Can I use Array Binding with a ExecuteDataSet or ExecuteReader methods?

    I want to use Array binding with selects. From the examples that I see so far it seems like everyone is showing the ExecuteNonQuery method. I wonder if I can use this functionality with a regular query that returns ref cursoros.
    Andrzej

    what is the error you recieve?

  • Finding a table with a like %name% in a schema

    What is the query I should use to find a table with a like %name% in a schema?
    Thank you for any help

    select * from all_tables
    where owner = 'YOUR_SCHEMA' and lower(table_name) like '%name%'
    /Regards
    Dmytro

  • How can I update the table with a single query for...

    I have a table with columns C1 and C2.
    C1 C2
    A1 null
    A1 null
    A1 null
    A1 null
    A2 null
    A2 null
    A2 null
    A3 null
    A4 null
    A4 null
    I want to update my table with a single query so that I would have data like
    C1 C2
    A1 1
    A1 2
    A1 3
    A1 4
    A2 1
    A2 2
    A2 3
    A3 1
    A4 1
    A4 2
    The updated column C2 has the values like serial no grouped on the column C1.

    SQL> create table mytable
      2  ( c1 varchar2(2)
      3  , c2 number(2)
      4  )
      5  /
    Tabel is aangemaakt.
    SQL> insert into mytable (c1)
      2  select 'A1' from dual union all
      3  select 'A1' from dual union all
      4  select 'A1' from dual union all
      5  select 'A1' from dual union all
      6  select 'A2' from dual union all
      7  select 'A2' from dual union all
      8  select 'A2' from dual union all
      9  select 'A3' from dual union all
    10  select 'A4' from dual union all
    11  select 'A4' from dual
    12  /
    10 rijen zijn aangemaakt.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1
    A1
    A1
    A1
    A2
    A2
    A2
    A3
    A4
    A4
    10 rijen zijn geselecteerd.
    SQL> merge into mytable t1
      2  using (select c1
      3              , row_number() over (partition by c1 order by null) rn
      4              , rowid rid
      5           from mytable
      6        ) t2
      7     on (t1.rowid = t2.rid)
      8   when matched then
      9        update set c2 = rn
    10   when not matched then
    11        insert values (null,null)
    12  /
    10 rijen zijn samengevoegd.
    SQL> select * from mytable
      2  /
    C1                                     C2
    A1                                      1
    A1                                      2
    A1                                      3
    A1                                      4
    A2                                      1
    A2                                      2
    A2                                      3
    A3                                      1
    A4                                      1
    A4                                      2
    10 rijen zijn geselecteerd.Regards,
    Rob.

  • Get Oracle SID in PL/SQL with out a query

    Hi,
    Is there any way where I can get ORACLE SID value in the PL/SQL layer with out actually querying v$database tables.
    I am looking for key word in PL/SQL which stores currect SID name, just like how keyword 'user' stores the current user who has logged in.
    Thanks
    Sree

    Hi,
    Is there any way where I can get ORACLE SID valuein
    the PL/SQL layer with out actually querying
    v$database tables.
    I am looking for key word in PL/SQL which stores
    currect SID name, just like how keyword 'user'stores
    the current user who has logged in.Subtle correction ...
    [url=http://download-east.oracle.com/docs/cd/B19306_01
    /appdev.102/b14261/subprograms.htm#sthref1776]'user'
    is a built-in function provided by Oracle. Why don't you create your own function to perform the
    Select?
    I know I can create a function but, I dont want to read the table everytime it is called. Knowing that Database sid is going to be constant for next couple of years.
    The procedure in which I am going to use database sid is called for almost every transaction in the database. I am trying to avoid IO operation for a constant value. I cant declare a global constant as it is going to be different for each environment Dev, QA, Production etc..and we are looking to deploy same code for all the environments. We are anticipating to have multiple databases for production too.

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • About regex and 'like' query

    Dear all,
    can i doing regex query in SAP B1?
    And how to use 'like' query with table, i mean :
    SELECT * FROM test T0 INNER JOIN test2 T1
    WHERE T0 LIKE '%T1.testfield%'
    thanks for your help

    wait - something came out funny in the previous posting - the system highlighted the name "field" with blue - that is NOT what I typed...
    instead I typed...
    "field" between two brackets ( bracket = [ and the other bracket - I cannot type them in because they come out as a different character)
    what the heck is going on with the forum here???  I am seeing this highlighting in other postings as well...
    Hope THIS one comes out correctly
    Edited by: Zal Parchem on Dec 29, 2007 2:47 PM

  • Access data on multi-logical database with ad hoc query

    Dear all,
    I would like to know if it is possible to access data in multi-logical database with ad hoc query.
    I recall that I read some document stated that you can access data in multi-logical database with PNP as base.
    But I find no document about how to set it up, any comment?
    Regards
    Bill

    Hi Bill...
    PNP can be accessible..............
    PNP  0000-0999, 2000 to 2999 HR Master Data & Time 
    PCH.... I don't think so....
    Experts please do reply on this please...................
    Vijay
    Edited by: Vijay Shankar on Sep 13, 2011 11:32 AM

  • Binding with .length

    Hi -
    My boss and I working looking though the XFA specification and he noticed the ability to use aggregate functions like .length. 
    But when ever I enter (schema path).length into designer it easies it.  Can someone provide some guidence?  I use an XSD external type binding with designer and using an external library to flatten the files (for now).   I'm using the latest version of design.
    thanks, Doug

    Hi,
    I'm not sure what you are trying to do.  Are you wanting to show the number of occurrences of a repeating item, if so you will probably need to use a calculation script.
    Can you give a reference to the XFA Spec that refers to the length property?
    Regards
    Bruce

  • Binding with ApplicationID

    Hi all,
    Is it possible to bind an ApplicationID with a LDAP server (Active Directory).
    Well the situation is something like this before actually binding with the userDN and password, the AD is actually first bound with the AppID (which is picked from the properties file).
    Also to which parameter shud i put this AppId with, in the Properties(environment)...like for example for the password we have:
    props.put(Context.SECURITY_CREDENTIALS,pwd);
    Please advice,
    Thanx in advance,
    Regards
    Hari

    Thanx it is solved.
    Regards
    Hari

Maybe you are looking for

  • Can't open iphoto after complete reboot.

    Hi! My computer stoped working a while back and I had the harddrive replaced, now I can't open iphoto after importing it from time mashine. I still have the same OS X (10.6.8) on a Mac Book pro from 2009. I can't buy the new one, or update it, becaus

  • How can I change my App Store from mex to us

    My iPad store is Mexico and I want to put it in the us.

  • Debugging Java classes based on IProgramBaseEx

    I developed my own class implementing the IProgramBaseEx interface. MyOwnClass is being loaded and its run method is executed. The code throws some runtime errors maybe due to some logical programming errrors: I can schedule a program object that has

  • Java.lang.ClassNotFoundException:myclass org.apache.catalina.loader

    I've been building some HTTP servlets and to ease up on the typing I've created a ServletUtilities file and class for repetitve tasks. I then added this file to my core package. However once I made a call to my ServletUtilites class from the other cl

  • Filemaker Pro 6 trial version will not install on iBook

    iBook G4 running OS 10.4 will not install the Filemaker Pro 6 trial version. I am attempting to use it to update files from version 3. I downloaded the trial version from their site, and attempted to open it (it is a .sit file) and it says it cannot