У меня две таблицы 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