Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle data update string with single quotes

Posted on 2011-09-09
7
Medium Priority
?
635 Views
Last Modified: 2012-05-12
I am getting an [ORA-00911:invalid character] error on the following string?  This column's data contains single quotes as part of the value.

UPDATE cmi_sales_filters_tab2 SET FILTER = 'BILLED<>1 AND INVTO_IDENTITY<>''CMOZ'' AND INVTO_IDENTITY<>''CMCB'' AND INVTO_IDENTITY<>''CMTOW'' AND INVTO_IDENTITY<>''CMGAR'' and company = ''05''' WHERE ID = 'PL Exclduing intra co sales'; 

Open in new window


What am I missing?
0
Comment
Question by:tnowacoski
  • 4
  • 2
7 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36511592
the string itself you are updating is fine.

is the error coming when you try to use that string as part of dynamic sql?
0
 
LVL 78

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
ID: 36511608
Does the error message give you an approximate column for he error?

What you posted seems correct.
0
 

Author Comment

by:tnowacoski
ID: 36511677
This is to update a 2 column table: ID (varchar2[50]) and  FILTER (varchar2[255]).  I am trying to update the FILTER column with a string that has single quotes mixed in throughout the string.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:tnowacoski
ID: 36511693
That is all that I have on the error.  This update is being submitted through a PHP/OCI8 web page.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 36511702
There is nothing wrong with your update statement.

See the code below.  The row updates just fine.

>>submitted through a PHP/OCI8 web page

If is likely a PHP error then. Do you need to escape quotes in PHP?  I'm not a PHP person.
drop table tab1 purge;
create table tab1(col1 varchar2(1000));
insert into tab1 values(null);

UPDATE tab1 SET col1 = 'BILLED<>1 AND INVTO_IDENTITY<>''CMOZ'' AND INVTO_IDENTITY<>''CMCB'' AND INVTO_IDENTITY<>''CMTOW'' AND INVTO_IDENTITY<>''CMGAR'' and company = ''05''';

Open in new window

0
 

Author Comment

by:tnowacoski
ID: 36511715
Below is the PHP/OCI8 page that is submitting the update.  I have changed the connection string information to "protect the innocent".

<!DOCTYPE html>
<html lang=en>
<header>
<meta charset=utf-8>
<link rel="stylesheet" type="text/css" href="main.css" />
<title>Sales Filter Record Update</title>
</header>
<body>
<A href="http://localhost/Update2.php">Back</A><BR>
<A href="http://localhost/index.html">Home</A><BR><br>
<?
$objConnect = oci_connect("username","password","database");
$strSQL = "UPDATE cmi_sales_filters_tab2 SET ";
$strSQL .="FILTER = '".str_replace("'", "''", $_POST["txtFilter"])."' ";
$strSQL .="WHERE ID = '".$_GET["ID"]."';";
echo 'Updating record with: <br>';
echo "<small>$strSQL </small><br>";
$objParse = oci_parse($objConnect, $strSQL);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
if($objExecute)
{
oci_commit($objConnect); //*** Commit Transaction ***//
echo "Save completed.";
}
else
{
oci_rollback($objConnect); //*** RollBack Transaction ***//
$e = oci_error($objParse);
echo "Error Save [".$e['message']."]";
}
oci_close($objConnect);
?>

</body>
</html>

Open in new window

0
 

Author Comment

by:tnowacoski
ID: 36511786
The solution was to omit the ";" at the end of the update line.......syntax!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question