I have a string that is read from an excel file. String is ¬©K!n?8)©}gH"$.F!r'&(®
I keep getting the following error. When running the insert statement
ERROR [42601] [IBM][CLI Driver][DB2/NT] SQL0007N The character "\" following " K!n?8) }gH""$.F!r'" is not valid. SQLSTATE=42601
How do I do this insert with the \ character in the string? The Character causing the problem might also be the &.
Its a DB2 Database
Thanks
It depends on which interface you are sending the insert statement.
In my experience, it is most probably the typewriter single quote character (') which makes the problem.
INSERT INTO TEMP.CHAR_TEST
VALUES ('¬©K!n?8)©}gH"$.F!r''&(®');
works fine for me, but notice that I have changed ' to '' (insert another single quote after the existing one).
Related
Why this query is not working:
UPDATE country SET timezones="[{"zoneName":'Asia\/Kabul',"gmtOffset":16200,"gmtOffsetName":'UTC+04:30',"abbreviation":'AFT',"tzName":'Afghanistan Time'}] " where name='Afghanistan'
Error I get:
ERROR: syntax error at or near "zoneName"
LINE 1: UPDATE country SET timezones="[{"zoneName":'Asia/Kabul',"gm...
^
SQL state: 42601
Character: 34
the issue with your SQL statement is that the literal string you are trying to set timezones to contains improperly formatted escape characters. if you wanted to avoid that first error you can double up on quotes like timezones="[{""zoneName"": ...
you can go to the link to see more about string formating in SQL. good luck!
You're trying to update the value wrapping the string in quotes. You need to wrap the string in single quotes timezones='[{"zoneName":'Asia...}]'
However, to TitledTeapot's point, you will also have to escape the existing single quotes in your string, so you'd end up with something like this:
'[{"zoneName":''Asia\/Kabul'',"gmtOffset":16200,"gmtOffsetName":''UTC+04:30'',"abbreviation":''AFT'',"tzName":''Afghanistan Time''}]'
I've made a Java code that reads a text document and returns me a list of sql commands (insert into) that I copy and paste on pgAdmin III so it can insert the data read in its database.
As you know, the insert into comand uses simple quotes to wrap string values, as it follows:
insert into table (description) values ('text from the .txt');
The thing is, some descriptions come with simple quotes in its text, and so, it makes pgAdmin understand those as the end of the string:
insert into table (description) values ('this is a description where ' this simple quote messes up the command');
I also have to do the same with Java expressions, like:
if(Currentline.charAt(i) == ''' ){ ... }
So I can fix the entire problem.
I think, probably, there is a simples way to solve that. Does anybody knows how to do it? Basically, how to make the pgAdmin incorporate this character to the string?
What you are looking for is how to escape special characters. Therefore, you have to escape ' with ' which means that you would end with '', being your insert like this:
insert into table (description)
values ('this is a description where '' this simple quote messes up the command');
Edit: since you updated your question with the java code. For java you also need to escape your special character, in this case with \. Your code would be:
if(Currentline.charAt(i) == '\'' ){ ... }
I am getting a syntax error in a PostgreSQL query. I am working on a project developed in YII1, I am getting an error
CDbCommand failed to execute the SQL statement: SQLSTATE[42601]:
Syntax error: 7 ERROR: syntax error at or near "s" LINE 1: ...OT NULL
AND sub_heading like '%Women and Children's Voices%'.
As you can see above, I am using the like operator in single quotes, and in the string there is another single quote (Children's). So PostgreSQL is throwing me an error. Please provide me a solution to escape the string.
You can escape a single quote in a string by using another single quote (i.e., '' instead of '. Note that these are two ' characters, not a single " character):
sub_heading LIKE '%Women and Children''s Voices%'
-- Here -----------------------------^
You should use the format function to construct the SQL statement, using the %L placeholder for the pattern.
I solved this problem by replacing the single quote with double quotes using PHP. Here is the code
There is a variable $var with value Women and Children's Voices. I replace that single quote using the str_replace() function.
$var = str_replace("'", "''", $var);
I'm trying to insert ODI step error message into oracle table.
I captured the error message using <%=odiRef.getPrevStepLog("MESSAGE")%>.
ODI-1226: Step PRC_POA_XML_synchronize fails after 1 attempt(s).
ODI-1232: Procedure PRC_POA_XML_synchronize execution fails.
ODI-1227: Task PRC_POA_XML_synchronize (Procedure) fails on the source XML connection XML_PFIZER_LOAD_POA_DB_DEV.
Caused By: java.sql.SQLException: class java.sql.SQLException
oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'tns3:ContctID'.
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:459)
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:469)
When I try to insert this into a table, I'm getting the following error:
Missing IN or OUT parameter at index:: 1
I tried with substr, replace. Nothing works as in middle of the error message we have a single quotes 'tns3:ContctID'.
Is there any way to insert this into a table?
that's a tough one if you want to use pure java BeanShell and you've given way too little details to get short and straight answer, like
how do you try to insert this (command on source/target, bean shell only, Oracle SQL +jBS, jython, groovy etc...)
The problem here is not only quotes but also newlines.
To replace them is even more difficult as every parsing step <%, <?, <# requires different trick to define those literals
What will work for sure is if you write Jython task for inserting log data (Jython in technology).
There you may use Python ability for multiline string literals
simply:
⋮
err_log = """
<?=odiRef.getPrevStepLog("MESSAGE")?>
"""
⋮
I faced this error few days back . I applied below mentioned solution in ODI ...
Use - q'#<%=odiRef.getPrevStepLog("MESSAGE")%>#'
This will escape inverted comma (') for INSERT statement.
I have used this in my code and it is working fine :)
For example -
select 'testing'abcd' from dual;
this query will give below error
"ORA-01756: quoted string not properly terminated"
select q'#testing'abcd#' from dual;
This query gives no error and we get below response in SQL Developer
testing'abcd
Getting error when trying to RUN:
INSERT INTO dtb_order VALUES (
14,1920,NULL,
'テスト',NULL,'03','6302','0215',NULL,NULL,NULL,'160','0023',NULL,0,13,
'新宿区西新宿','セントラルパークタワー・ラ・トゥール',6,
'1972-09-02 00:00:00',NULL,3150,0,1,500,0,0,0,0,150,3650,3650,8,
'NP後払い',NULL,9000,'2013-09-12 18:42:56',
'2013-09-23 19:42:22',NULL,NULL,10,1,NULL,
'a:2:{s:5:\"title\";a:2:{s:4:\"name\";s:32:\"NP後払いでのお支払情報\";s:5:\"value\";b:1;}s:3:\"msg\";a:2:{s:4:\"name\";s:15:\"ご注意事項\";s:5:\"value\";s:388:\"株式会社ネットxxxションズより、商品とは別に郵送されます。\n主要コンビニ・銀行・郵便局でお支払いできますので、商品の到着を確認してから、\nお支払いをお願いいたします。\nNP後払いの詳しいご案内はこちら⇒ <a href=\'http://np-someurl.jp/about/\' target=\'_blank\'>http://np-someurl.jp/about/</a>\n\";}}',
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
);
Error message:
Error : ERROR: syntax error at or near "http"
LINE 1: ...ます。\nNP後払いの詳しいご案内はこちら⇒ <a href=\'http://np-...
^
Tried http:\/\/np-... no luck.
++++++++
is there other way except $$ (my string with http) $$, because I have almost 200 000 INSERTs and only some of them have http://, I just want to fix "http://" with substitution by vim or something like that, not manually.
You do not show the whole command. My guess is that it is not properly escaped. Use dollar quoting $$ in instead of single quotes so it is not necessary to escape single quotes in the string. Also use escape string E syntax to have the new lines \n
E$$a:2:{s:5:"title";a:2:{s:4:"name";s:32:"NP後払いでのお支払情報";s:5:"value";b:1;}s:3:"msg";a:2:{s:4:"name";s:15:"ご注意事項";s:5:"value";s:388:"株式会社ネットxxxションズより、商品とは別に郵送されます。\n主要コンビニ・銀行・郵便局でお支払いできますので、商品の到着を確認してから、\nお支払いをお願いいたします。\nNP後払いの詳しいご案内はこちら⇒ <a href='http://np-someurl.jp/about/' target='_blank'>http://np-someurl.jp/about/</a>\n";}}$$,
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
Changing \' to " & \" to " did the trick.
VIM
:%s/\\'/"/gc
:%s/\\"/"/gc