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

Home -> Community -> Usenet -> c.d.o.misc -> Re: how to escape single quotes

Re: how to escape single quotes

From: Ove Malmstrøm <ovema_at_vippetangen.sys.sol.no>
Date: 30 Sep 1999 01:20:39 +0200
Message-ID: <rpkaeq5fgoo.fsf@vippetangen.sys.sol.no>

kev <kevin.porter_at_fast.no> writes:

> Hi,
>
> How do I guard against single quotes in text messing up my SQL
> statements. For example, I have some text like:
>
> 'this is some text. It's got an apostrophe in it'
>
> ie there's inadvertantly 3 single quotes there, which ruin the SQL
> statement. I could URL-encode the text first and URL-decode it
> afterwards (using PHP), but is there a 'proper' way to encode it (in
> Oracle 8)?

There are several ways to do it, but i think quoting it with a single tick is the easiest.

Like:

SQL> desc test

 Name                            Null?    Type
 ------------------------------- -------- ----
 TEST                                     VARCHAR2(20)

SQL> insert into test values ('I''m inserting this');

1 row created.

SQL> select * from test;

TEST



I'm inserting this

--
Ove Received on Wed Sep 29 1999 - 18:20:39 CDT

Original text of this message

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