Solved

Oracle data update string with single quotes

Posted on 2011-09-09
7
581 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 73

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 76

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORACLE SQL DEVELOPER Query ? 5 58
how to tune this sql query 61 101
Last record chosen in Oracle Query 3 34
Oracle 12c patching 1 32
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
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
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now