sql – “ORA-22812:在尝试访问系统表时无法引用嵌套表列的存储表”

我的Oracle 12c数据库中有一个

XML Schema创建:

BEGIN
-- Register the schema
DBMS_XMLSCHEMA.registerSchema('http://www.example.com/fvInteger_12.xsd','<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="FeatureVector">
<xs:complexType>
<xs:sequence>
<xs:element name="feature" type="xs:integer" minOccurs="12" maxOccurs="12"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>',TRUE,FALSE);
END;
/

创建表:

CREATE TABLE fv_xml_12_1000 (
   id    NUMBER,fv  XMLTYPE)
   XMLTYPE fv STORE AS OBJECT RELATIONAL
      XMLSCHEMA "http://www.example.com/fvInteger_12.xsd"
      ELEMENT "FeatureVector";

表DDL:

SELECT 
DBMS_MetaDATA.GET_DDL( 'TABLE','FV_XML_12_1000') 
FROM DUAL;

上面的查询结果:

CREATE TABLE "HIGIIA"."FV_XML_12_1000"
   (    "ID" NUMBER,"FV" "SYS"."XMLTYPE"
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 mineXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"
 VARRAY "FV"."XMLDATA"."feature" STORE AS TABLE "SYS_NTZqNkxcSIThTgU5pCWr3HmA=="

 (( PRIMARY KEY ("nesTED_TABLE_ID","SYS_NC_ARRAY_INDEX$")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COmpuTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 mineXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS"  ENABLE)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 mineXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ) RETURN AS LOCATOR
  XMLTYPE COLUMN "FV" XMLSCHEMA "http://www.example.com/fvInteger_12.xsd" ELEMEN
T "FeatureVector" ID 4129

我想访问这个表,这是在HIGIIA模式中(确实在higiia的user_tables中). :

SYS_NTZqNkxcSIThTgU5pCWr3HmA==

但是,我无法执行命令:

desc SYS_NTZqNkxcSIThTgU5pCWr3HmA==

因为我收到错误

SP2-0565: Identificador invalido.

查询

select * from "SYS_NTZqNkxcSIThTgU5pCWr3HmA=="

返回错误

ORA-22812: cannot reference nested table column’s storage table

我该怎么做才能访问该表(表SYS_NTZqNkxcSIThTgU5pCWr3HmA ==)?

提前致谢!

解决方法

您将XML文档存储为“对象关系”,这导致Oracle为存储创建内部表,您通常不需要直接访问该表.

但是,您可以通过取消该表来;请注意,您必须包含一个表别名,并使用它来使点表示法正确解析;并且必须引用“功能”,因为它区分大小写:

select f.id,t.column_value
from fv_xml_12_1000 f
cross join table(f.fv.xmldata."feature") t;

您无法看到整个fv或其隐式XMLDATA,只能看到varray中保存的特征值.

如果我创建三个虚拟行:

insert into fv_xml_12_1000 values (1,xmltype.createxml ('<?xml version="1.0"?>
<FeatureVector xmlns:ns="http://www.example.com/fvInteger_12.xsd">
 <feature>123</feature>
</FeatureVector>'));

insert into fv_xml_12_1000 values (2,xmltype.createxml ('<?xml version="1.0"?>
<FeatureVector xmlns:ns="http://www.example.com/fvInteger_12.xsd">
 <feature>234</feature>
</FeatureVector>'));

insert into fv_xml_12_1000 values (3,xmltype.createxml ('<?xml version="1.0"?>
<FeatureVector xmlns:ns="http://www.example.com/fvInteger_12.xsd">
 <feature>456</feature>
 <feature>567</feature>
</FeatureVector>'));

那个查询给了我:

ID Result Sequence
---------- ---------------
         1             123
         2             234
         3             456
         3             567

您也可以使用普通的XML DB机制访问XML文档;将存储的数据看作XML文档只需:

select fv from fv_xml_12_1000;

添加过滤器以选择单个ID的XML文档.

如果要从XML文档中提取元素,可以使用XQuery或XMLTable;这相当于上一个查询

select x.*
from fv_xml_12_1000 f
cross join xmltable('/' passing f.fv columns x xmltype path '.') x;

…但是你可以添加一个更有用的XPath表达式和/或columns子句来获得你想要的数据,例如:

select f.id,x.feature
from fv_xml_12_1000 f
cross join xmltable(
  '/FeatureVector/feature'
  passing f.fv
  columns feature number path '.')
x;

它为您提供主表ID值和所有相关的功能号,每个ID /功能一行.使用与以前相同的三个虚拟行,该查询为我提供:

ID    FEATURE
---------- ----------
         1        123
         2        234
         3        456
         3        567

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...