oracle:舉例
SELECT XMLElement("rowdata",
XMLElement("row",
XMLForest(
code AS "code",
name AS "name",
py_code AS "other"
) ) )
FROM table1 where code='124';
sqlserver:舉例
select * from table1 where code='124' for xml RAW ('row'),elements, root('rowdata')
注: sqlserver中的如果想讓空的字段也顯示出來,需要在elements後 加xsinil
我見到很多人都採用在開發的程序中 用字符串拼接來實現生成xml,我舉的例子要比字符串拼接的代碼量減少很多,而且xml已經很多年應用。