0

Having an Oracle database with a table STUDENT, which has a field STUDEN_NAME, is there a way to retrieve it enclosed in XML tags?

select STUDENT_NAME from STUDENT;

res.getString("STUDENT_NAME"); // I want: <StudenName>PAUL</StudentName>

Thanks

0

3 Answers 3

3
select xmlelement("StudentName", STUDENT_NAME) from STUDENT;

A Google search for

oracle result set as xml

Turned up the Oracle XML DB Developer's Guide, specifically chapter 18, entitled Generating XML Data from the Database - from where I got the syntax shown above.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, forgot to add in your java code use: res.getString(1).
no real need. He can just alias the query column and still use the name.
rs.getString("STUDEN_NAME"); and rs.getString(1); returns null (but the table contains names) ¿?
1

If you mean that you want to make the actual change in the query then the following will give you what you are looking for:

SELECT XMLELEMENT("StudentName",student_name) student_name FROM student;

Comments

0

The solution for me comes using getClobVal;

select XMLELEMENT("StudentName", STUDENT_NAME).getClobVal() STUDENT_NAME from STUDENT

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.