Solved

Oracle data update string with single quotes

Posted on 2011-09-09
7
613 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 125 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 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 125 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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 77

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

623 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