Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Oracle SQL解析XML内部的JSON_Sql_Xml_Oracle_Xmltable_Oracle Apex 5.1 - Fatal编程技术网

使用Oracle SQL解析XML内部的JSON

使用Oracle SQL解析XML内部的JSON,sql,xml,oracle,xmltable,oracle-apex-5.1,Sql,Xml,Oracle,Xmltable,Oracle Apex 5.1,我有从Oracle atom提要返回的xml,我将它临时存储在名为“atom”的apex_集合中 XML如下所示: <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <id>atomserver:newhire:feed</id> <title type="text">New Hire</title> <l

我有从Oracle atom提要返回的xml,我将它临时存储在名为“atom”的apex_集合中

XML如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>atomserver:newhire:feed</id>
<title type="text">New Hire</title>
<link href="https://ucf1-fap1273-hcm.oracledemos.com/hcmCoreApi/atomservlet/employee/newhire" rel="self" />
<updated>2013-12-16T18:17:56.108Z</updated>
<entry>
<link href="https://ucf1-fap1273-hcm.oracledemos.com/hcmCoreApi/atomservlet/employee/newhire/EMP300000133185858" rel="edit" />
  <id>atomservlet:newhire:EMP300000133185858</id>
  <title type="text">Ford, Laura Hired</title>
  <updated>2016-10-20T12:45:03.000Z</updated>
  <author>
     <name>BETTY.ANDERSON</name>
  </author>
  <summary type="text">Employee Period of Service Created</summary>
  <published>2016-10-20T12:45:03.000Z</published>
  <link href="https://ucf5-fap0357-hcm.oracledemos.com:443/hcmCoreApi/resources/latest/emps?q=PersonId=300000133184715&amp;effectiveDate=2015-01-01" rel="related" />
  <content type="text">{ "Context" : [ { "PrimaryPhoneNumber" : "44 1 781895862", "PersonId" : "300000133184715", "PersonName" : "Ford, Laura", "EffectiveStartDate" : "2015-01-01", "EffectiveDate" : "2015-01-01", "WorkerType" : "EMP", "PeriodType" : "E", "PersonNumber" : "3686", "WorkEmail" : "laura.ford@noreply.com" } ] }</content>
</entry>
</feed>

但是我需要获取内容标签中的信息,它看起来好像是JSON。我知道如何用SQL解析JSON,但如果JSON在XML文档中,我不知道如何解析JSON

Oracle的JSON点表示法,例如content.Context[0]。WorkEmail。它在这里不起作用,因为a您没有在开始时放置表别名,XMLTable甚至没有表别名,但是b更重要的是,您的内容列的类型是VARCHAR24000,而不是JSON,并且它没有is_JSON检查约束。我认为您甚至不能向XMLTable添加约束。所有这些都需要使用点符号

根据您的评论,更简单的选择是使用JSON函数,例如

with t as (select clob001 from apex_collections where collection_name = 'ATOM')
SELECT title, summary, 
      json_value(content, '$.Context[0].WorkEmail') as work_email 
   FROM t,
   XMLTable( XMLNamespaces( 
           'http://www.w3.org/2005/Atom' AS "ns0" 
          ), 'ns0:feed/ns0:entry'            
          PASSING   XMLTYPE.createXML(t.CLOB001)
          COLUMNS title VARCHAR2(4000) path 'ns0:title' ,
                  summary VARCHAR2(240) path 'ns0:summary',
                  content VARCHAR2(4000) path 'ns0:content');

我不明白。此时,内容已作为关系数据从XML中提取出来。那么为什么你不能用你已有的方法来解析呢?尝试时发生了什么?内容标记的内容是JSON。因此,如果我想要标题、摘要和工作电子邮件,我想做如下操作:使用t作为从apex_集合中选择clob001,其中集合名称='ATOM'选择标题、摘要、内容.Context[0]。工作电子邮件从…等。但这会使我遇到ORA-00923:from关键字未在预期的位置找到。非常感谢。我将此标记为正确。我运行的其中一个数据库仍然是11.2,所以我无法访问json_值,但我在帖子中忽略了这一点。但当我们最终升级时,这是一个很好的参考。
with t as (select clob001 from apex_collections where collection_name = 'ATOM')
SELECT title, summary, 
      json_value(content, '$.Context[0].WorkEmail') as work_email 
   FROM t,
   XMLTable( XMLNamespaces( 
           'http://www.w3.org/2005/Atom' AS "ns0" 
          ), 'ns0:feed/ns0:entry'            
          PASSING   XMLTYPE.createXML(t.CLOB001)
          COLUMNS title VARCHAR2(4000) path 'ns0:title' ,
                  summary VARCHAR2(240) path 'ns0:summary',
                  content VARCHAR2(4000) path 'ns0:content');