oracle表中的Xml批量插入

时间:2015-06-20 09:56:18

标签: sql database oracle11g oracle10g procedures

我是oracle的新手, 我想尝试的是, 我有一个xml,我尝试在oracle数据库表中插入相同的,我已经形成了一个查询,当我尝试插入它。我得到一些错误,如

  

错误报告 -   ORA-06550:第35行,第84栏:   PL / SQL:ORA-00933:SQL命令未正确结束   ORA-06550:第5行,第2栏:   PL / SQL:忽略SQL语句   06550. 00000 - "行%s,列%s:\ n%s"   *原因:通常是PL / SQL编译错误。   *操作:

我无法弄清楚我错过了什么,建议我如何更改查询,

继承我正在努力工作的XML和查询。



- <call>
- <callSummary>
  <indId>100</indId> 
  <notificationNo>notification</notificationNo> 
  <orderNo>orderno</orderNo> 
  </callSummary>
- <callList>
- <callDetails>
  <maintenancetype>1</maintenancetype> 
  <serialNo>1</serialNo> 
  <unitType>unit type</unitType> 
  </callDetails>
- <callDetails>
  <maintenancetype>1</maintenancetype> 
  <serialNo>2</serialNo> 
  <unitType>unit type</unitType> 
  </callDetails>
- <callDetails>
  <maintenancetype>2</maintenancetype> 
  <serialNo>1</serialNo> 
  <unitType>unit type</unitType>
  </callDetails>
- <callDetails>
  <maintenancetype>2</maintenancetype> 
  <serialNo>2</serialNo> 
  <unitType>unit type</unitType> 
  </callDetails>
  </callList>
  </call>
&#13;
&#13;
&#13;

我的查询

&#13;
&#13;
DECLARE  
 call_xml XMLTYPE := xmltype('<call><callSummary><indId>100</indId><notificationNo>notification</notificationNo><orderNo>orderno</orderNo><</callSummary><callList><callDetails><maintenancetype>1</maintenancetype><serialNo>1</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>1</maintenancetype><serialNo>2</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>2</maintenancetype><serialNo>1</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>2</maintenancetype><serialNo>2</serialNo><unitType>unit type</unitType></callDetails></callList></call>');
 
 BEGIN
 INSERT INTO ORDER_DETAILS (
		 IND_ID,NOTIFICATION_NO,ORDER_NO,MAINT_TYPE,SERIAL_NO,UNIT_TYPE)
  SELECT 
  call_xml.value('call/callSummary/indId[1]','CLNT(3)'),
  call_xml.value('call/callSummary/notificationNo[1]','CHAR(12)'),
  call_xml.value('call/callSummary/orderNo[1]','CHAR(12)'),
  call_xml.value('call/callSummary/callList/callDetails/maintenancetype[1]','CHAR(1)'),
  call_xml.value('call/callSummary/callList/callDetails/serialNo[1]','CHAR(1)'),
  call_xml.value('call/callSummary/callList/callDetails/unitType[1]','CHAR(20)') from call_xml.nodes('call');
  
  END;
&#13;
&#13;
&#13;

我希望你提前了解我的问题,Thanx。

1 个答案:

答案 0 :(得分:2)

您想要使用xmlsequence函数。它允许您从XML对象中选择节点列表。如果您想使用pl / sql,请将xmltype替换为您的变量。

      SELECT 
  extractValue(column_value,'callSummary/indId[1]'),
  extractValue(column_value,'callSummary/notificationNo[1]'),
  extractValue(column_value,'callSummary/orderNo[1]'),
  extractValue(column_value,'callSummary/callList/callDetails/maintenancetype[1]'),
  extractValue(column_value,'callSummary/callList/callDetails/serialNo[1]'),
  extractValue(column_value,'callSummary/callList/callDetails/unitType[1]') from table (
       xmlsequence(
         extract(
           xmltype('<call><callSummary><indId>100</indId><notificationNo>notification</notificationNo><orderNo>orderno</orderNo></callSummary><callList><callDetails><maintenancetype>1</maintenancetype><serialNo>1</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>1</maintenancetype><serialNo>2</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>2</maintenancetype><serialNo>1</serialNo><unitType>unit type</unitType></callDetails><callDetails><maintenancetype>2</maintenancetype><serialNo>2</serialNo><unitType>unit type</unitType></callDetails></callList></call>'),'/call/callSummary')));
相关问题