Can create view, but cannot create table / materialized view: Xpath is null
markjwFeb 22 2013 — edited Feb 27 2013Hi all,
We recently moved some XML documents into the database in an XMLType column and want to query the data. I've been writing some queries and turning them into materialized views. I got to one query, and something really strange is happening. My query returns the expected results, but I am getting an error when I try to create a materialized view out of it. Even stranger, I can create a view out of it, and I can manually insert its data into an existing table, but I cannot create a materialized view out of it and I cannot create a table out of it. Here is a brief summary, please let me know if anyone has suggestions.
Issuing the following commands fails in SQLDeveloper
-- Creating a materialized view out of the query fails:
create materialized view element REFRESH COMPLETE ON DEMAND as [query];
Error at Command Line:1 Column:1 SQL Error: ORA-31063: XPath compilation failed: Xpath is null.
-- Creating a table out of the query with the following shortcut fails:
create table element as [query];
Error at Command Line:1 Column:1 SQL Error: ORA-31063: XPath compilation failed: Xpath is null.
Issuing the following commands in SQLDeveloper works fine:
-- Creating a view out of the query works:
create or replace view element as [query];
-- Creating a blank table from the query and then inserting data works:
create table element as select * from [query] where 1 = 2;
insert into element select * from [query];
Here is a simplified version of the query...
I have changed the names around, and cut the query down so maybe it will be a little easier to understand. I did confirm that this query is also having the same symptoms described above. Since I changed the names, executing the query returns no results. However creating a materialized view out of the query still fails with the 'Xpath is null' error.
create materialized view element REFRESH COMPLETE ON DEMAND as
select
m.resource_id,
xml.*
from metadata_sources m,
xmltable(
'for $i in /metadata/app//*[(self::elem1 or self::elem2) and (parent::form or parent::subform)]
let $formName := if($i/parent::subform) then $i/../../@name else $i/../@name
let $subformName := if($i/parent::subform) then $i/../@name else ""
return <data
appId="{$i/ancestor::app[1]/idField}"
formName="{$formName}"
subformName="{$subformName}"
elemName="{$i/@name}"></data>' passing m.xml_content
columns
app_id NUMBER path '@appId',
form_name VARCHAR2(50 char) path '@formName',
subform_name VARCHAR2(50 char) path '@subformName',
elem_name VARCHAR2(50 char) path '@elemName'
) xml;
Edited by: user11949534 on Feb 22, 2013 1:55 PM