×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

ampersand in DML statement

ampersand in DML statement

ampersand in DML statement

(OP)
Is there a way (other than setting verify off in PL/SQL which is not what we're using to submit the statements) to allow an ampersand (&) character in a DML statement?  I know for example, that to allow a single quote character ('), you can simply double it up ('').  Is there anything similar for ampersands?  Thanks.

RE: ampersand in DML statement

Try this:

SET ESCAPE '\'
INSERT INTO my_table VALUES 'Smith \& Wesson';

RE: ampersand in DML statement

(OP)
I not sure that will work for me.  I need to be able to send everything as a single statement.

RE: ampersand in DML statement

Check to find out what the default escape character is for your system.  Then use that character before the ampersand.  For instance, if you start a sqlplus session and enter the command
SHOW escape
and get a response that indicates your escape character is '~', then try
INSERT INTO my_table VALUES ('Smith ~& Wesson');

RE: ampersand in DML statement

Another possibility is

INSERT INTO my_table VALUES ('Smith '||CHR(38)||' Wesson');

This may work for you, depending on how easy it is to modify your sql.

RE: ampersand in DML statement

(OP)
Carp, when I did a SHOW ESCAPE in PL/SQL it shows that it is OFF.  I also tried karluk's suggestion of the CHR(38) and that didn't work either.  Is there some one of setting the show escape to always be on in the database?

RE: ampersand in DML statement

escape OFF means you do not have an escape character defined.  You can remedy this by either executing the SET ESCAPE command previously shown or entering this command into your glogin.sql script.  I recommend the latter, since it will automatically set this command when you start a session.

RE: ampersand in DML statement

May I ask what kind of problem you had with the chr(38) function?  It works just fine on the few examples I've tested.  The main problem I see is that it is cumbersome, not that it doesn't work at all.  You have to build your string by concatenating three pieces.

RE: ampersand in DML statement

(OP)
Is the glogin.sql script applicable only to pl/sql or would it apply to connection made through other means (ODBC for example)?  Would it apply to all users or just me?  

The problem I had with karluk's suggestion was that the results in the column included the ||Chr(38|| in the value as if was just plain text.  It didn't actually cause a concatenation to occur.

RE: ampersand in DML statement

Ah, I think you missed two vital quotes.  You have to replace your string with three separate pieces.  The pieces before and after the chr(38) have to be enclosed in quotes, but the chr(38) can't have quotes around it:

'Smith '
||
chr(38)
||
' Wesson'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close