Ask the Expert

Inserting value that includes single quotes

How can I INSERT a row in table from a frontend application developed in VB.net and from SQL*Plus, where one of field values includes single quotes (' ')? My query is
INSERT INTO abc VALUES
(
1,
'Write 'C' Program to add two Number'
);
Fields in relation:
a number;
b varchar(30);
Problem: While inserting the string in Column b, Oracle Echoes the following message:
'write 'C' program',
        *
ERROR at line 4:
ORA-00917: missing comma
How can I insert such a value?

    Requires Free Membership to View

Inserting the single quote can be done in two ways.

1) Using extra quotes to insert "C with single quotes around it"

2) To use the function to get the character from its corresponding ASCII value, for single quotes it is 39.

I will provide both examples for you.

1)  INSERT INTO abc VALUES
  ( 1, 'Write "C" Program to add two Number');

2) INSERT INTO abc VALUES
    (1, 'Write ' || CHR(39) || 'C' || CHR(39) || ' Program to add two Number');


This was first published in July 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: