Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Escape character for & in strings.

Re: Escape character for & in strings.

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Sun, 27 Jun 1999 17:45:25 GMT
Message-ID: <378262d4.29230471@newshost.us.oracle.com>


A copy of this was sent to "C." <c_ferguson_at_rationalconcepts.com> (if that email address didn't require changing) On Sun, 27 Jun 1999 09:52:09 -0700, you wrote:

>Ok Thomas,
> It's java going through jdbc, and I do see it affecting the insert. It's a minor
>inconvenience. Right now, if the set define off won't work for the connect session,
>I can always break the line apart...not looking forward to that approach, but it
>will work...
>Thanks for your time and responses!
>Cindy
>

I don't understand tho -- the & is *not* a special character whatsoever. SQL submitted via JDBC cannot 'interact' with you as you describe below. I just put together a small example for you to try and let me know what it does for you, for me, it prints out:

$ java TestJDBC
str = ben & jerry

import java.sql.*;

class TestJDBC {

    static String createTable = "create table test (str varchar2(255) )";     static String dropTable = "drop table test";     static String insertInTable = "insert into test values ('ben & jerry')";     static String selectFromTable = "select * from test";

public static void main(String args[]) throws Exception {

    DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

    Connection conn =

      DriverManager.getConnection
        ("jdbc:oracle:thin:@slackdog:1521:oracle8", "scott", "tiger");

    Statement st = conn.createStatement();     try {

        // drop the table, if it exist
        st.executeUpdate(dropTable);

    } catch (SQLException exc) { }

    st.executeUpdate(createTable);
    st.executeUpdate(insertInTable);

    ResultSet rs = st.executeQuery(selectFromTable);     while (rs.next()) {

        System.out.println("str = " + rs.getString("str"));     }
    rs.close();
    st.close();
    conn.close();
    }
}

>Thomas Kyte wrote:
>
>> A copy of this was sent to "C." <c_ferguson_at_rationalconcepts.com>
>> (if that email address didn't require changing)
>> On Sat, 26 Jun 1999 21:31:07 -0700, you wrote:
>>
>> >My most humblest apologies for being ambiguous...Everyone has been so kind as
>> >to offer this solution. What I need to do is see if that will work through
>> >the code. As noted, I'm not trying to do this in a sqlplus session, I'm
>> >connecting from another piece of software...
>> >Thank you very much for your time and response!
>> >Cindy
>> >
>>
>> what tool are you using? any sort of " '&' what value do you want" processing
>> is being done by that tool. SQLPLUS does this (and you set it off with "set
>> define off" or "set scan off").
>>
>> If you tell us the tool, we might be able to tell you the command. If you are
>> writing a C program/odbc/jdbc/etc/etc you will not be affected by this at all.
>>
>> >Kenneth C Stahl wrote:
>> >
>> >> Oh, is that what you want to know. You should have said so from the start.
>> >>
>> >> Simply enter the following command in your script before you execute the
>> >> sql:
>> >>
>> >> set define off
>> >>
>> >> As long as you are not using substitution variables in your sqlplus script
>> >> you'll be ok. If you are, then simply set define to some other innocuous
>> >> character that doesn't have a significane to Oracle.
>> >>
>> >> Ken
>> >>
>> >> "C." wrote:
>> >>
>> >> >
>> >> > insert into icecream VALUES ('Ben & Jerry''s');
>> >> >
>> >> > what happens is:
>> >> > Enter value for jerry:
>> >> >
>> >> > Not what I want to happen. I have code that is trying to do the
>> >> > insert, so
>> >> > I run each string through some checker code looking for the apostrophe
>> >> > and it
>> >> > alters the string to contain two single quotes, but what about the &
>> >> > character.
>> >> >
>> >> > Now, the following insert statement would work:
>> >> > insert into icecream values ('Ben ' || '&' || ' Jerry''s');
>> >> >
>> >> > I could make my code rewrite the string into that format, but give me
>> >> > a
>> >> > break? Isn't there a better solution?
>> >> >
>> >
>>
>> --
>> See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
>> Current article is "Part I of V, Autonomous Transactions" updated June 21'st
>>
>> Thomas Kyte tkyte_at_us.oracle.com
>> Oracle Service Industries Reston, VA USA
>>
>> Opinions are mine and do not necessarily reflect those of Oracle Corporation
>

--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'... Current article is "Part I of V, Autonomous Transactions" updated June 21'st  

Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Sun Jun 27 1999 - 12:45:25 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US