2015-10-29 26 views
0

我做我的过渡从T-SQL TO PL/SQL,在我第一次尝试我试图创建一个存储过程(PL/SQL)将数据加载到表中,但我得到一个错误:Oracle存储过程的挑战

PL/SQL: SQL Statement ignored 
ORA-06550: line 29, column 4: 
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: 

代码:

declare 
    v_str VARCHAR2(32767) := '<ns0:ConnCustomerOrgServiceCreateRequest xmlns:ns0="http://tempuri.org" xmlns:ns6="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnItemSvc" xmlns:ns4="http://schemas.microsoft.com/dynamics/2011/02/documents/DocumentPaging" xmlns:ns7="http://schemas.microsoft.com/dynamics/2011/02/documents/EntityKeyPage" xmlns:ns5="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey" xmlns:ns1="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes" xmlns:ns3="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:ns8="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList" xmlns:ns2="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnCustomerOrg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ns2:ConnCustomerOrg> 
     <ns2:CustTable class="entity"> 
      <ns2:AccountNum xsi:nil="true" /> 
      <ns2:CreditMax>0</ns2:CreditMax> 
      <ns2:CustGroup>10</ns2:CustGroup> 
      <ns2:Organization class="entity"> 
       <ns2:NumberOfEmployees xsi:nil="true" /> 
       <ns2:OrganizationName class="entity"> 
        <ns2:Name>PRUEBA</ns2:Name> 
       </ns2:OrganizationName> 
      </ns2:Organization> 
     </ns2:CustTable> 
    </ns2:ConnCustomerOrg> 
</ns0:ConnCustomerOrgServiceCreateRequest> 
'; 
    v_xml XMLTYPE := XMLTYPE(v_str); 
begin 

    select x.AccountNum, x.CreditMax 
    from t 
     ,XMLTABLE('/ConnCustomerOrgServiceCreateRequest/ConnCustomerOrg/CustTable' 
       PASSING t.xml 
       COLUMNS AccountNum NUMBER PATH '/CustTable/AccountNum' 
        ,CreditMax NUMBER PATH '/REC/CreditMax'      
      ) x 

end; 
+2

纯粹的选择内部pl/sql必须SELECT <字段列表> INTO <变量的相应列表> WHERE ...;您正在选择但不将数值放在任何地方。如果您的语句可以返回多行,那么您必须在循环结构中执行此操作,或者将其批量收集到集合中。 –

+0

您没有插入。目前你似乎并不需要PL/SQL,但是由于你正在使用它,你必须选择* into * something - 你需要PL/SQL变量来匹配查询中的结果集列,也就是两个数字变量。 (当然还有缺失的分号)。什么是你从中选择的't'表格?你从CTE例子中复制了这个吗? –

+0

@AlexPoole&Michael Broughton !!!!从吨 ,XMLTABLE( '/ ConnCustomerOrgServiceCreateRequest/ConnCustomerOrg /的CustTable' PASSING t.xml COLUMNS AccountNum NUMBER PATH BEGIN 以T为(选择XMLTYPE(v_str)从双XML) 选择x.AccountNum,x.CreditMax '/ CustTable/AccountNum' ,CreditMax NUMBER PATH'/ CustTable/CreditMax' )x; 结束; – AFF

回答

2

当你在PL/SQL中使用SELECT语句必须有一个INTO子句。 INTO子句允许您将值存储在声明的变量/ s中,以便您可以随时在块内部访问它们。试试这个:

declare 
    v_str VARCHAR2(32767) := '<ns0:ConnCustomerOrgServiceCreateRequest xmlns:ns0="http://tempuri.org" xmlns:ns6="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnItemSvc" xmlns:ns4="http://schemas.microsoft.com/dynamics/2011/02/documents/DocumentPaging" xmlns:ns7="http://schemas.microsoft.com/dynamics/2011/02/documents/EntityKeyPage" xmlns:ns5="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey" xmlns:ns1="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes" xmlns:ns3="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:ns8="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList" xmlns:ns2="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnCustomerOrg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ns2:ConnCustomerOrg> 
     <ns2:CustTable class="entity"> 
      <ns2:AccountNum xsi:nil="true" /> 
      <ns2:CreditMax>0</ns2:CreditMax> 
      <ns2:CustGroup>10</ns2:CustGroup> 
      <ns2:Organization class="entity"> 
       <ns2:NumberOfEmployees xsi:nil="true" /> 
       <ns2:OrganizationName class="entity"> 
        <ns2:Name>PRUEBA</ns2:Name> 
       </ns2:OrganizationName> 
      </ns2:Organization> 
     </ns2:CustTable> 
    </ns2:ConnCustomerOrg> 
</ns0:ConnCustomerOrgServiceCreateRequest> 
'; 


    v_xml XMLTYPE := XMLTYPE(v_str); 
    v_accountnum VARCHAR2(2000); 
    v_creditmax VARCHAR2(2000);--i just assumed their datatypes since i cannot use %TYPE in here because i dont know what table accountnum and creditmax came from 

BEGIN 

SELECT x.AccountNum, x.CreditMax 
INTO v_accountnum, v_creditmax 
FROM t 
    ,XMLTABLE('/ConnCustomerOrgServiceCreateRequest/ConnCustomerOrg/CustTable' 
       PASSING t.xml 
       COLUMNS AccountNum NUMBER PATH '/CustTable/AccountNum' 
        ,CreditMax NUMBER PATH '/REC/CreditMax' 

      ) x; 

END; 

希望这会有所帮助。

1

你是你的SELECT语句后失踪分号;。每份声明必须以;终止。

declare 
    v_str VARCHAR2(32767) := '<ns0:ConnCustomerOrgServiceCreateRequest xmlns:ns0="http://tempuri.org" xmlns:ns6="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnItemSvc" xmlns:ns4="http://schemas.microsoft.com/dynamics/2011/02/documents/DocumentPaging" xmlns:ns7="http://schemas.microsoft.com/dynamics/2011/02/documents/EntityKeyPage" xmlns:ns5="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey" xmlns:ns1="http://schemas.microsoft.com/dynamics/2008/01/sharedtypes" xmlns:ns3="http://schemas.microsoft.com/dynamics/2006/02/documents/QueryCriteria" xmlns:ns8="http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKeyList" xmlns:ns2="http://schemas.microsoft.com/dynamics/2008/01/documents/ConnCustomerOrg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ns2:ConnCustomerOrg> 
     <ns2:CustTable class="entity"> 
      <ns2:AccountNum xsi:nil="true" /> 
      <ns2:CreditMax>0</ns2:CreditMax> 
      <ns2:CustGroup>10</ns2:CustGroup> 
      <ns2:Organization class="entity"> 
       <ns2:NumberOfEmployees xsi:nil="true" /> 
       <ns2:OrganizationName class="entity"> 
        <ns2:Name>PRUEBA</ns2:Name> 
       </ns2:OrganizationName> 
      </ns2:Organization> 
     </ns2:CustTable> 
    </ns2:ConnCustomerOrg> 
</ns0:ConnCustomerOrgServiceCreateRequest> 
'; 
    v_xml XMLTYPE := XMLTYPE(v_str); 
begin 
select x.AccountNum, x.CreditMax 
from t 
    ,XMLTABLE('/ConnCustomerOrgServiceCreateRequest/ConnCustomerOrg/CustTable' 
       PASSING t.xml 
       COLUMNS AccountNum NUMBER PATH '/CustTable/AccountNum' 
        ,CreditMax NUMBER PATH '/REC/CreditMax' 

      ) x; 

end; 
+0

谢谢!.....我仍然有问题,但那是我的问题的一部分:) – AFF