循环选择结果并在操作中使用它们 [英] loop through select results and use them in an operation

查看:71
本文介绍了循环选择结果并在操作中使用它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我想遍历一次select的结果并将它们收集到一个唯一的字符串中,以实现整个结果,查询将获取单列的一组行

从表名tbl中选择tbl.column_name,其中(条件)

我想获取此查询的所有结果,并使用一些字符将它们分开后将它们放入字符串nvarchar2(4000)中.


在此先感谢...

hello everybody ...

i want to loop through the results of a select and gather them into a unique string implements the whole result , the query fetches a set of rows of a single column

select tbl.column_name from table_name tbl where (condition)

I want to get all the results of this query and put them into a string nvarchar2(4000) after separating them using some characters


thanks in advance...

推荐答案

如果您正在使用Oracle 11G,则可以使用listagg.
例如:
If you''re using Oracle 11G you can use listagg.
For example:
select
   deptno,
   listagg (ename, ',') 
WITHIN GROUP 
(ORDER BY ename) enames
FROM 
   emp
GROUP BY 
   deptno

将为您提供所有部门的每个部门的逗号分隔列表.

如果您有较早的版本,还有其他方法,但是除了列出它们之外,我将为您提供链接 [ ^ ] intead.

will give you all employenames as a comma separated list per department.

There are other methods if you have earlier versions, but instead of listing them I''ll give you a link[^] intead.


从tbl的条件中选择column1 +'',''++ column2 +'',''+ column3
select column1+'',''+column2+'',''+column3 from tbl where condition


这篇关于循环选择结果并在操作中使用它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆