2010-09-08 152 views
1

這裏是我的對象DEF:爲什麼我會得到PLS - 00382?

CREATE OR REPLACE TYPE FALCON.contacts AS OBJECT (phone   VARCHAR2(50) 
    ,phoneusage  VARCHAR2(25) 
    ,phonetype  VARCHAR2(25) 
    ,email   VARCHAR2(150) 
    ,phoneext  VARCHAR2(25) 
    ,anytext   VARCHAR2(250)) 

下面是表DEF:

CREATE OR REPLACE TYPE FALCON.contacttbl AS TABLE OF contacts 

這裏是我的管道函數

FUNCTION get_pcontacts(p_conttbl IN xmltypedefs_spec.conttbl) 
RETURN falcon.contacttbl 
PIPELINED 
IS 
    l_contact falcon.contacts; 
BEGIN 
    FOR n IN 1 .. p_conttbl.count 
    LOOP 
     PIPE ROW(**falcon.contacts**(p_conttbl(n).phone, p_conttbl(n).phoneusage,    p_conttbl(n).phonetype, p_conttbl(n).email, p_conttbl(n).phoneext, p_conttbl(n).anytext)); 
    END LOOP; 
    RETURN; 
END get_pcontacts; 

我得到的錯誤,當我調用表功能:

FUNCTION get_pidxml(p_pidrec xmltypedefs_spec.pidtyp) 
RETURN CLOB 
IS 
    l_tmprec     CLOB; 
    l_pxml     xmltype; 
    l_bxml     xmltype; 
    l_pcontacts    xmltypedefs_spec.conttbl := p_pidrec.personalcont; 
    l_bcontacts    xmltypedefs_spec.conttbl := p_pidrec.businesscont; 

BEGIN 

--  l_pxml := get_contacts(p_pidrec, 'p'); 
--  l_bxml := get_contacts(p_pidrec, 'b'); 

SELECT xmlelement("pid" 
        ,xmlforest(p_pidrec.setid AS "setID" 
           ,p_pidrec.patidexternal AS "patientIDExternal" 
           ,p_pidrec.patientid AS "patientID" 
           ,p_pidrec.patintasgnauth AS "patientIDInterAssignAuthority" 
           ,p_pidrec.patinttypecd AS "patientIDInternalIDTypeCode" 
           ,p_pidrec.patidalternate1 AS "patientIDAlernate1" 
           ,p_pidrec.patlastname AS "patientLastName" 
           ,p_pidrec.patfirstname AS "patientFirstName" 
           ,p_pidrec.patmiddleinit AS "patientMiddleInitial" 
           ,p_pidrec.patsuffix AS "patientSuffix" 
           ,p_pidrec.patprefix AS "patientPrefix" 
           ,p_pidrec.degree AS "degree" 
           ,p_pidrec.familyname AS "familyName" 
           ,p_pidrec.givenname AS "givenName" 
           ,p_pidrec.mothermaidname AS "mothersMaidenName" 
           ,p_pidrec.dob AS "dateOfBirth" 
           ,p_pidrec.adminsex AS "administrativeSex" 
           ,p_pidrec.patientalias AS "patientAlias" 
           ,p_pidrec.race AS "race" 
           ,p_pidrec.racetext AS "raceText" 
           ,p_pidrec.pataddr1 AS "patientAddress1" 
           ,p_pidrec.pataddr2 AS "patientAddress2" 
           ,p_pidrec.patcity AS "patientCity" 
           ,p_pidrec.patstate AS "patientState" 
           ,p_pidrec.patzip AS "patientZip" 
           ,p_pidrec.countrycode AS "countryCode" 
           ,p_pidrec.addresstype AS "addressType" 
           ,p_pidrec.othgeodesig AS "otherGeographicDesignation" 
           ,p_pidrec.county AS "county" 

           ,(SELECT xmlagg(xmlelement("contactInfo", 
              xmlforest(phone AS "phoneNumber", 
                 phoneusage AS "telecomUseCode", 
                 phonetype AS "telecomequiptype", 
                 email AS "email", 
                 phoneext AS "phonenumberextension", 
                 anytext AS "anytext"))) 
           FROM TABLE(**get_pcontacts(l_pcontacts**))) AS "personalContact" 
+0

你有一個複雜的實現。如果將get_pcontacts()函數獨立調用,而沒有使用所有XML函數,get_pcontacts()函數是否可以正常工作? – APC 2010-09-09 09:30:58

回答

0

http://pls-00382.ora-code.com/

PLS-00382:表達式類型錯誤

的因爲我不知道xmltypedefs_spec.conttbl是如何定義的呢,我刪除從管道函數的輸入參數,只是有它產生假數據飛:

CREATE OR REPLACE FUNCTION get_contacts 
    RETURN contacttbl PIPELINED 
IS 
    -- converts some structure to pipe of contacts 
BEGIN 
    FOR n IN 1 .. 5 LOOP 
     PIPE ROW( 
     contact( 
      '877-867-5309', 
      'Work', 
      'Cell', 
      '[email protected]', 
      n, 
      'WTF?' 
     ) 
    ); 
    END LOOP; 
    RETURN; 
END get_contacts; 

的查詢現在執行沒有錯誤:

SELECT 
    xmlagg(
     xmlelement("contactInfo", 
      xmlforest(
       phone AS "phoneNumber", 
       phoneusage AS "telecomUseCode", 
       phonetype AS "telecomequiptype", 
       email AS "email", 
       phoneext AS "phonenumberextension", 
       anytext AS "anytext" 
      ) 
     ) 
    ) 
FROM 
    TABLE(get_contacts()) 

這告訴我可能xmltypedefs_spec.conttbl有問題,也許在SQL語句中使用集合類型?不確定。如果將xmltypedefs_spec.pidtyp更改爲使用falcon.contacttbl而不是xmltypedefs_spec.conttbl,會怎麼樣?似乎你有一個包類型和一個對象類型正在做同樣的事情?

0

xmltypedefs_spec定義對應於XML元素的記錄類型。這些記錄類型用於碎化和構建XML。最初,XML不使用重複元素,但現在必須。我試圖獲取一個xmltypedefs_spec.pidtyp表,並使用流水線函數從關聯表中返回'行'的數據。正是以這種方式,我想發送數組記錄的行來構建xml。