Solved

Oracle data update string with single quotes

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

856 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