简体   繁体   English

如何获取db2查询output如下形式?

[英]How to get db2 query output in the following form?

I have a DB2 LUW database, I need the query output in the following form.我有一个 DB2 LUW 数据库,我需要以下形式的查询 output。 Each row in from the query output should be in a single line as follows.查询 output 中的每一行都应该在一行中,如下所示。 Thanks in advance for youe help.提前感谢您的帮助。

Example:-例子:-

Table - employee表 - 员工

columns:- First_name,Last_name,Department列: - 名字,姓氏,部门

Output:- Output:-

<First_name>Adam</First_name><Last_name>Santner</Last_name></dept>hr</dept>
<First_name>John</First_name><Last_name>Milne</Last_name><dept>hr</dept>
<First_name>Mike</First_name><Last_name>Tyson</Last_name><dept>hr</dept>

and so on等等

Try the following.试试下面的。
You may uncomment the commented out lines to run this statement as is and get the result as you specified.您可以取消注释已注释掉的行以按原样运行此语句并获得您指定的结果。
Refer to the XMLROW scalar function description.请参阅XMLROW 标量 function描述。

/*
WITH EMPLOYEE (First_name, Last_name, dept) AS 
(
VALUES
  ('Adam', 'Santner', 'hr')
, ('John', 'Milne',   'hr')
, ('Mike', 'Tyson',   'hr')
)
*/
SELECT SUBSTRING (S, 6, CHARACTER_LENGTH (S) - 11) AS S 
FROM 
(
SELECT XMLSERIALIZE (XMLROW (First_name AS "First_name", Last_name AS "Last_name", dept AS "dept") AS VARCHAR (1000)) AS S
FROM EMPLOYEE
) T 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM