最近做项目,需要提供xml字符串给第三方,之后我试了试这两种数据库 都可以很简单的实现

       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已经很多年应用。

    如有问题,欢迎大家进行沟通 QQ 165393839

相关文章:

  • 2022-01-16
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-06-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
相关资源
相似解决方案