ORA-00911: invalid character xsql error - sql

I m using sql query in the xsql file but I have ORA-00911: invalid character error. Same query is working directly on the database.
My index.xsql:
<?xml version="1.0" encoding="ISO-8859-2" ?>
<page connection="labor" xmlns:xsql="urn:oracle-xsql">
<xsql:query>
SELECT id, iata_dep, iata_arr FROM route JOIN flight ON route.route_id=flight.route_id
</xsql:query>
</page>
My browser result:
<?xml version="1.0" encoding="ISO-8859-2" ?>
<page connection="labor" xmlns:xsql="urn:oracle-xsql">
<xsql:query>
SELECT id, iata_dep, iata_arr FROM route JOIN flight ON route.route_id=flight.route_id
</xsql:query>
</page>
Where is the character problem?
Thanks,

There are several problems that can cause such behavior :
This error occurs when you try to use a special character in a SQL
statement. If a special character other than $, _, and # is used in
the name of a column or table, the name must be enclosed in double
quotations.
This error may occur if you've pasted your SQL into your editor from
another program. Sometimes there are non-printable characters that may
be present. In this case, you should try retyping your SQL statement
and then re-execute it.
This error occurs when a special character is used in a SQL WHERE
clause and the value is not enclosed in single quotations.

Related

Cannot query my container using the GridDB Shell?

I have a device container with the name 1cbfce15ec4d which houses some my data. I know for a fact there's data in there, but when I try a simple query in the griddb shell, I got the following error:
gs[public]> sql select * from 1cbfce15ec4d;
D20332: An unexpected error occurred while executing a SQL. : msg=[[240001:SQL_COMPILE_SYNTAX_ERROR] Parse SQL failed, reason = Syntax error: 1cbfce15ec4d; on executing query (sql="select * from 1cbfce15ec4d") (db='public') (user='admin') (appName='gs_sh') (clientId='a6d92f48-e558-440-86dd-a05e949fa726:1') (clientNd='{clientId=3, address=127.0.0.1:55744}') (address=127.0.0.1:20001, partitionId=983)]
I am not exactly sure what is going on here -- at first I assumed my data must be corrupt or empty, but that is not the case. It seems to be a case of the shell dying trying to process something about that container name.
Any ideas?
According to the manual :
"If the name of a table or a column contains characters other than ASCII alphanumeric characters and underscore, or if the first character of the name is a number in a SQL statement, enclose the name with double quotation marks."
Try select * from "1cbfce15ec4d"

Postgresql query on xml data that ignores single quotes

I have an xml snippet:
<message to='8ffc29107a21e3639#dev.xyz.com' id='faddf6f2-a973-4b0e-a00a-d6f9b886047a' type='abc'>
<body>body_text</body>
<datetime
xmlns='dev:datetime' time='2022-01-25T11:08:57.974Z'>
</datetime>
<type
xmlns='dev:xtype' type='x_type'>
</type>
<imageurl
xmlns='dev:imageurl' url='https://dev.xyz.com/media/fa5a8b6272cf44f282a02599aa62e0c5.jpg' ratio='1.2091648189209165'>
</imageurl>
</message>
...on which i want to run an postgresql query which returns the url attribute inside the imageurl node.
In order to achieve that, I first tried to query a simple xml string and hit the following error:
SELECT unnest(xpath('//*/text()','<foo lang='en'><bar>test</bar><zar>test1</zar></foo>'));
ERROR: syntax error at or near "en"
LINE 1: SELECT unnest(xpath('//:/text()','<foo lang='en'><bar>test</...
It seems like the sql query is not able to handle single quotation strings. Since my original snippet above has multiple such single quote strings, I am stuck here.
What is the best way to ignore the single quotes in the psql query?
The standard way to escape single quotes inside a SQL string is to double them:
'<foo lang=''en''><bar>test</bar><zar>test1</zar></foo>'
However in such a case, using Postgres' proprietary "dollar quoted strings is more convenient:
SELECT unnest(xpath('//*/text()',
$$<foo lang='en'><bar>test</bar><zar>test1</zar></foo>$$)
);

WIX How to include the equal signs and ampersand in the string table to avoid LGHT0104 error

I have a launch condition error string in String_en-US.wxl:
<WixLocalization Culture="en-us" Codepage="1252" xmlns="http://schemas.microsoft.com/wix/2006/localization">
<String Id="ERR_REQUIRED_APP_ABSENT">This product requires XXX to be on the system. Please download it from "https://knowledge.xxx.com/knowledge/llisapi.dll?func=ll&objId=59284919&objAction=browse&sort=name&viewType=1", install it and try again.</String>
</WixLocalization>
It seems having the ampersand signs (&) and the equal signs (=) cause the light error:
Strings_en-US.wxl(0,0): error LGHT0104: Not a valid localization file; detail: '=' is an unexpected token. The expected token is ';'. Line 36, position 172.
I even tried to escape them using = which is equivalent to the equal sign but it complaint about the ampersand. "How can I avoid the error?
CDATA: A CDATA section is "...a section of element content that is marked for the parser to interpret as only character data, not markup."
In this case, something like this:
<String Id="TEST1"><![CDATA[https://www.hi.com/one&two&three&v=1]]></String>
XML Escape Characters: XML escape characters are normally used for encoding special characters in XML documents. The escape character for & is & & (more) - CDATA is an alternative approach.
Links:
What characters do I need to escape in XML documents?
https://en.wikipedia.org/wiki/CDATA

How to efficiently replace special characters in an XML in Oracle SQL?

I'm parsing an xml in oracle sql.
XMLType(replace(column1,'&','<![CDATA[&]]>')) //column1 is a column name that has xml data
While parsing, I'm temporarily wrapping '&' in CDATA to prevent any xml exception. After getting rid of the exception caused by '&', I'm getting "invalid character 32 (' ') found in a Name or Nmtoken". This is because of '<' character.
E.g: <child> 40 < 50 </child> // This causes the above exception.
So I tried the below and it works.
XMLType(replace(replace(column1,'&','<![CDATA[&]]>'),'< ','<![CDATA[< ]]>'))
In the above, I'm wrapping '< '(less than symbol followed by space) in CDATA. But the above is a bit time consuming. So I'm trying to use regex to reduce the time taken.
Does anyone know how to implement the above action using regex in Oracle sql??
Input : <child> 40 & < 50 </child>
Expected Output : <child> 40 <![CDATA[&]]> <![CDATA[< ]]> 50 </child>
Note: Replacing '& ' with ampersand semicolon sometimes is leading to 'entity reference not well formed' exception. Hence I have opted to wrap in CDATA.
You can do that with a regexp like this:
select regexp_replace(sr.column1,'(&|< )','<![CDATA[\1]]>') from dual;
However, regexp_replace (and all the regexp_* functions) are often slower than using plain replace, because they do more complicated logic. So I'm not sure if it'll be faster or not.
You might already be aware, but your underlying problem here is that you're starting out with invalid XML that you're trying to fix, which is a hard problem! The ideal solution is to not have invalid XML in the first place - if possible, you should escape special characters when originally generating your XML. There are built-in functions which can do that quickly, like DBMS_XMLGEN.CONVERT or HTF.ESCAPE_SC.

sql code not working in oraclesqldeveloper: Invalid Character error

I wrote a code to find few items by a particular number but it keeps saying that is something is an "invalid character"."ORA-00911: invalid character
00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action: Error at Line: 14 Column: 23"
My brain is blown,I am not sure where the problem exists.
Need Help. Thanks.
select
a.app_num,
a.crs_pol_num,
kl.score,
kl.risk_level_desc
from
application a,
kyc_new_risk_level kl
where
a.app_num = kl.app_num
and a.app_num = (select max(to_number(a1.app_num)) from
application a1,
kyc_new_risk_level kl1 where kl1.app_num = a1.app_num and a1.crs_pol_num = a.crs_pol_num)
and a.crs_pol_num in (‘CG0147511’,
‘CG0133662’,
‘CG0138107’,
‘493186’,
‘CG0142230’,
‘CS0138382’,
‘CG0147509’,
‘CG0147545’,
‘921141048001’,
‘CG0347239’,
‘CG0142212’,
‘CG0147518’,
‘CG0134057’,
‘CG0143158’,
‘CG0147536’,
‘CG0244124’,
‘CG0134102’,
‘CG0241709’,
‘CG0147197’,
‘CG0137204’,
‘CG0347496’,
‘CG0147490’,
‘CG0143467’,
‘CG0135689’,
‘CG0146904’,
‘CS0132517’,
‘CG0145455’,
‘CG0147554’,
‘CG0133626’,
‘CG0147560’,
‘CG0135359’,
‘CG0133303’,
‘921165287001’,
‘CG0147546’,
‘CG0114581,
‘CG0122266’,
‘CG0236577’,
‘CG0345349’,
‘CG0132670’,
‘CG0147413’,
‘CG0241646’,
‘CG0143783’,
‘CG0245160’,
‘CG0124066’,
‘CG0124830’,
‘CG0145956’,
‘CG0232953’,
‘CG0144479’,
‘CG0147569’,
‘CG0147555’,
‘CG0244857’,
‘CG0147562’,
‘CG0347578’,
‘CG0346461’,
‘CS0133352’,
‘512097’,
‘CS0127026’,
‘CG0147583’,
‘CG0233314’,
‘CG0247096’,
‘CG0131282’,
‘CG0123462’,
‘CS0124502’,
‘CG0146034’,
‘CG0140236’,
‘CS0126420’,
‘CG0147557’,
‘CG0123182’,
‘CG0233300’,
‘CG0132782’,
‘CG0147501’,
‘CS0141693’,
‘CG0145237’,
‘CG0141763’,
‘CG0147591’,
‘CG0144107’,
‘CG0125208’,
‘CG0132306’);
SQL Developer is showing you the problem before you even run your query
That's not a quote, it's a smart quote. Which is nice for browsers and word processors - but not so much for the database engine.
If you click on that hint, it will replace it with a real single quote.
But with so many to fix, would be much faster, better to use search and replace.
But your cursor on the bad character, and hit Ctrl+R
And then hit 'replace all', then repeat for the closing smart quote.
But in case you missed all that, the error also back from the DB tells you where the issue is