I'm trying to run the below sql query.
SELECT sr.resultid, xt2.*
FROM RESULTS sr,
XMLTABLE('/extraInfo/resultsViewData'
PASSING XMLType(sr.extrainfo)
COLUMNS
docketNumber VARCHAR2(35) PATH 'docketNumber',
dateFiled VARCHAR2(35) PATH 'dateFiled',
nosDescription VARCHAR2(70) PATH 'nosDescription',
courtname VARCHAR2(100) PATH 'courtname',
chapter VARCHAR2(35) PATH 'chapter'
) xt2
WHERE sr.profileId = '7dd76222';
NOTE: sr.extrainfo has the value
'<extraInfo><resultsViewData><courtname>FL Circuit & County - Santa Rosa</courtname></resultsViewData></extraInfo>'
Even though I use '& amp ;' instead of '&', I still get the below error,
ORA-31011: XML parsing failed
ORA-19213: error occurred in XML processing at lines 1
LPX-00242: invalid use of ampersand ('&') character (use &)
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Sometimes I even get the error,
LPX-00242: invalid use of ampersand ('&') character (use &)
Is there any way to overcome this issue?
Try:
set define off;
Then execute your query;
If you want more info on what set define off; does: When or Why to use a "SET DEFINE OFF" in Oracle Database
I am not able to reproduce your issue at first place.
But still if you are getting the issue then try to use dbms_xmlgen.convert to convert your string as following:
'<extraInfo><resultsViewData><courtname>'
|| dbms_xmlgen.convert('FL Circuit & County - Santa Rosa')
|| '</courtname></resultsViewData></extraInfo>'
db<>fiddle demo
Cheers!!
Related
Select * from mytable where field=
'ce7bd3d4-dbdd-407e-a3c3-ce093a65abc9;cdb597073;7cf6cda5fc'
Getting Below Error while running above query in Hive
FAILED: ParseException line 1:92 character '' not supported here
<EOF> here means End Of File. When you get an "unexpected End Of File" error it means the parser reached the end of the query unexpectedly. This typically happens when the parser is expecting to find a closing character, such as when you have started a string with ' or " but have not closed the string (with the closing ' or ").
When you come across these types of errors it is good to check that your query can be parsed correctly. In addition, the error gives you the location where the parser failed: line 1:92 in this case. You can usually look at this location (character 92 of the query) and work backwards to find the problem character.
Try adding the database name to the "from" statement as below.
Select * from my_db_name.mytable where field= 'ce7bd3d4-dbdd-407e-a3c3-
ce093a65abc9;cdb597073;7cf6cda5fc';
Hive uses the default database when no database was previously specified.
I'm running PostgreSQL 9.4 and are inserting a lot of records into my database. I use the RETURNING clause for further use after an insert.
When I simply run:
... RETURNING my_car, brand, color, contact
everything works, but if I try to use REGEXP_REPLACE it fails:
... RETURNing my_car, brand, color, REGEXP_REPLACE(contact, '^(\+?|00)', '') AS contact
it fails with:
ERROR: invalid regular expression: quantifier operand invalid
If I simply run the query directly in PostgreSQL it does work and return a nice output.
Tried to reproduce and failed:
t=# create table s1(t text);
CREATE TABLE
t=# insert into s1 values ('+4422848566') returning REGEXP_REPLACE(t, '^(\+?|00)', '');
regexp_replace
----------------
4422848566
(1 row)
INSERT 0 1
So elaborated #pozs suggested reason:
set standard_conforming_strings to off;
leads to
WARNING: nonstandard use of escape in a string literal
LINE 1: ...alues ('+4422848566') returning REGEXP_REPLACE(t, '^(\+?|00)...
^
HINT: Use the escape string syntax for escapes, e.g., E'\r\n'.
ERROR: invalid regular expression: quantifier operand invalid
update
As OP author says standard_conforming_strings is on as supposed from 9.1 by default working with psql and is off working with pg-prommise
update from vitaly-t
The issue is simply with the JavaScript literal escaping, not with the
flag.
He elaborates further in his answer
The current value of environment variable standard_conforming_strings is inconsequential here. You can see it if you prefix your query with SET standard_conforming_strings = true;, which will change nothing.
Passing in a regEx string unescaped from the client is the same as using E prefix from the command line: E'^(\+?|00)'.
In JavaScript \ is treated as a special symbol, and you simply always have to provide \\ to indicate the symbol, which is what needed for your regular expressions.
Other than that, pg-promise will escape everything correctly, here's an example:
db.any("INSERT INTO users(name) VALUES('hello') RETURNING REGEXP_REPLACE(name, $1, $2)", ['^(\\+?|00)', 'replaced'])
To understand how the command-line works, prefix the regex string with E:
db.any("INSERT INTO users(name) VALUES('hello') RETURNING REGEXP_REPLACE(name, E$1, $2)", ['^(\\+?|00)', 'replaced'])
And you will get the same error: invalid regular expression: quantifier operand invalid.
I want to check if valid phone number is inserting in table, so my trigger code is here:
select start_index
into mob_index
from gmarg_mobile_operators
where START_INDEX = substr(:new.contact_info,0,3);
if (REGEXP_LIKE (:NEW.CONTACT_INFO,'^(?:'|| mob_index ||')[\-,\:]{0,1}[0-9][0-9][\-,\:]{0,1}[0-9][0-9][\-,\:]{0,1}[0-9][0-9]')) then
found := 1;
end if;
I've checked my regex: "^(?:555)[-,:]{0,1}[0-9][0-9][-,:]{0,1}[0-9][0-9][-,:]{0,1}[0-9][0-9]" on several online tools and it is correct.
When I run my trigger, it compiles successfully, but during inserting a row following error is shown:
insert into GMARG_CONTACTS
(CLINET_ID,CONTACT_INFO,contact_type_id)
values
(0,'555194117','Mobile')
Error report -
SQL Error: ORA-12728: invalid range in regular expression
ORA-06512: at "HR.GMARG_TRIGGER_CONTACT", line 12
ORA-04088: error during execution of trigger 'HR.GMARG_TRIGGER_CONTACT'
12728. 00000 - "invalid range in regular expression"
*Cause: An invalid range was found in the regular expression.
*Action: Ensure a valid range is being used.
So, if my regex is correct, why does oracle shows error?
I tried to find answer, or redifine my regex, but no forward steps...
thank you in advance
Regexp don't use \ to protect - in a bracket expression. You only have to put - as the first character, just after the opening bracket:
IF REGEXP_LIKE('--,,::', '[\-,:]*')
...
=> ORA-12728: invalid range in regular expression
If you're curious, when encountering [\-,:] Oracle understand: "any character in the range from \ to , or the character :". The reason why this raises an exception is \ appears to be after , according to their ASCII value. And Oracle don't accept range having a starting value after the ending one.
On the other hand:
IF REGEXP_LIKE('--,,::', '[-,:]*')
Works as expected.
As a side note, [-,:]{0,1} meaning "zero or one occurrence of - or , or :" could be written [-,:]?.
I am running the SELECT query from the Oracle SQL developer IDE on my RHEL box as below
SELECT count(*)
From xyz
WHERE xmltype(xyz.xmlColumn).existsNode('//name=""') = 1;
Above query works fine if I execute for single record. But when I execute it for the whole table it fails with the error:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of 'C'
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Any pointers on above will help me.
include /text in your xpath. like
select (COLUM_NAME).extract('//parentNode/chileNode/text()').getStringVal() as Colum_Name from TableName where UUID='Value'
Oracle is complaining that "xyz.xmlColumn" is not a valid xml column or type. It expects <element>....</element> format
Your problem is what is stored in your CLOB is not an XML document as it is missing a root node. Since you are scanning the whole document in your extract you could just wrap it in an element to ensure you have 1 and only 1 root, at which point your XMLTYPE cast would work.
SELECT
XMLTYPE(''||clob_field||'').EXTRACT('//se/text()').getStringVal()
FROM tablename
I am getting "ORA-21560: argument 3 is null, invalid, or out of range" error on running query:
SELECT extractvalue(xmltype(blob2clob(shblobdata.blobdata)),
'/booked-order/ads/online-content[name="quantity"]/value')
FROM shblobdata
WHERE id=...;
the full error is:
ORA-21560: argument 3 is null, invalid, or out of range
ORA-06512: at "SYS.DBMS_LOB", line 978
ORA-06512: at "MORAS.BLOB2CLOB", line 14
21560 . 00000 - "argument %s is null, invalid, or out of range"
*Cause: The argument is expecting a non-null, valid value but the
argument value passed in is null, invalid, or out of range.
Examples include when the LOB/FILE positional or size
argument has a value outside the range 1 through (4GB - 1),
or when an invalid open mode is used to open a file, etc.
*Action: Check your program and correct the caller of the routine
to not pass a null, invalid or out-of-range argument value.
I have tried to change "quantity" to ''quantity'' (changing single quote to two apostrophes), but got the same error.
The content of blob is:
<?xml version="1.0" encoding="utf-8"?>
<booked-order>
<ads>
<online-content>
<name>quantity</name>
<value>19872</value>
</online-content>
</ads>
</booked-order>
The problem is in your custom function MORAS.BLOB2CLOB.
Also the error message says clearly ORA-06512: at "MORAS.BLOB2CLOB", line 14
The extract itself is ok, when you keep out BLOB2CLOB and test with
SELECT EXTRACTVALUE (xmltype ( (shblobdata.blobdata)), '/booked-order/ads/online-content[name="quantity"]/value')
FROM (SELECT '<?xml version="1.0" encoding="utf-8"?>
<booked-order>
<ads>
<online-content>
<name>quantity</name>
<value>19872</value>
</online-content>
</ads>
</booked-order>
' blobdata
FROM DUAL) shblobdata
;
it returns 19872
I'd first debug your function blob2clob with
SELECT blob2clob(shblobdata.blobdata)
FROM shblobdata
WHERE id=...;
And if that works ok continue on to the XML parts.
The exception is clearly hurled by BLOB2CLOB(), which is not an Oracle built-in. It's something you've written yourself or lifted from somewhere on the interwebs. So there's not much we can do to help regarding it.
The more general point is, why are you storing XML in a BLOB? The best apporach is to store it in a column defined as Oracle's XMLTYPE datatype. Otherwise store it as a CLOB.