ORA-00932:数据类型不一致:预期-获得CHAR00932。00000-在将数据透视与XML结合使用时,“数据类型不一致:预期%s获得了%s”

时间:2019-07-09 06:17:09

标签: xml plsql-package

我有两个表A和B,

表A包含学生卷号DOB。 表B包含学生名册编号和学生注册的课程。

我正在尝试将列名显示为“学生名册”,将所有主题和列名的值显示为“名册号”,如果该学生已注册特定课程,则显示为“ X”。

Final expected output: 

      Roll_number   Tamil   English   Maths   Science   Social

Shyam      01         X       null      null     null      X
Madhuri    02        null      X         X        null     X


And I am putting that value in the Excel sheet by using XML.

When I am trying to use pivot functionality with XML , I am getting the error like 
ORA-00932: inconsistent datatypes: expected - got CHAR
00932. 00000 -  "inconsistent datatypes: expected %s got %s"

Query:

With Q2 as (
SELECT * FROM
(
  SELECT Roll_number, subjects
  FROM A,B where A.roll_number=B.roll_number
)
PIVOT
(
 MIN (DECODE(subjects,null,'X','X'))
 FOR Subjects IN ( 'Tamil' AS Tamil,'English' as English,'Maths' as Maths,'Science' as Science,'Social' as Social))
)
select xmlserialize(document
 xmltransform(
 xmlelement("ROOT"
 ,xmlelement("ROWSET"
 , xmlattributes('Student_Details' as "name")
, xmlelement("COLUMN")
 , xmlelement("ROW"
,xmlelement("CELL", xmlattributes('s67' "header_color"), 'Roll_Number')
,xmlelement("CELL", xmlattributes('s67' "header_color"),'Tamil')
,xmlelement("CELL", xmlattributes('s67' "header_color"),'English')
,xmlelement("CELL", xmlattributes('s67' "header_color"),'Maths')
,xmlelement("CELL", xmlattributes('s67' "header_color"),'Science')
,xmlelement("CELL", xmlattributes('s67' "header_color"),'Social')
 ) 
 , xmlagg(
 xmlelement(
"ROW"
, xmlelement("CELL", xmlattributes('s71' "header_color"), Roll_number) , xmlelement("CELL", xmlattributes('s71' "header_color"), Tamil)
,xmlelement("CELL", xmlattributes('s71' "header_color"),English)
,xmlelement("CELL", xmlattributes('s71' "header_color"),Maths)
,xmlelement("CELL", xmlattributes('s71' "header_color"),Science)
,xmlelement("CELL", xmlattributes('s71' "header_color"),Social)

 )    )  ) )
 , xdburitype('/public/fin/student_details.xml').getXML()
 )
     AS CLOB  )
     FROM Q2

0 个答案:

没有答案