我为什么得到PLS-00382?

时间:2010-09-08 21:49:40

标签: sql plsql

这是我的对象def:

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"

2 个答案:

答案 0 :(得分: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', 
            'jenny@gmail.com', 
            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,该怎么办?好像你有一个包类型和一个对象类型正在做同样的事情?

答案 1 :(得分:0)

xmltypedefs_spec定义与XML元素对应的记录类型。这些记录类型用于粉碎和构建XML。最初,XML没有使用重复元素,但现在必须。我试图获取xmltypedefs_spec.pidtyp的表,并使用pipelined函数从关联表中返回数据的“行”。我想以这种方式发送数组记录行来构建xml。