Re: OCI: How can I insert a string including an amphersand (&) from OCI??

From: Ole Hansen <oha_at_unispeed.com>
Date: Mon, 14 Oct 2002 11:02:51 +0200
Message-ID: <3DAA883B.7030204_at_unispeed.com>


Hi,

I think I really messed up things here. This is an example of the code I use.

char query[200];

sprintf(query, "insert into some_table (a,b) values (25, 'abc&def')");

OCIStmtPrepare(stmthp,errhp,(text*)query,
   (ub4)strlen(query),(ub4)OCI_NTV_SYNTAX,(ub4) OCI_DEFAULT);
OCIStmtExecute(svchp, stmthp, errhp,(ub4)1,

   (ub4)0,(CONST OCISnapshot *)NULL,
   (OCISnapshot *) NULL,OCI_COMMIT_ON_SUCCESS);

Whenever I had a faulty insert I tried to execute the very same statement from sqlplus - and it failed too because the string also included an ampersand and I was prompted for a value.

However the problem seems to be something different which I will look into.

Thanks!

Ole

Rauf Sarwar wrote:

> Ole Hansen <oha_at_city.dk> wrote in message news:<3DA7F1A6.8070000_at_city.dk>...
> 

>>Hi,
>>
>>I have troble escaping an amphersand (&) from within OCI.
>>Neither single quote (') or backslash (\) seems to work.
>>
>>The statement fails if I try to execute it from OCI if the string
>>includes an amphersand but I dont know how to escape an amphersand (&).
>>
>>I really need to store the amphersand with the string.
>>
>>Any ideas?
>>
>>Thanks in advance!
>>Ole Hansen
> 
> 
> 
> Use ASCII value of & i.e. CHR(38). To store abcd&efgh,
> Insert into foo values ('abcd' || CHR(38) || 'efgh');
> 
> /Rauf Sarwar
Received on Mon Oct 14 2002 - 11:02:51 CEST

Original text of this message