Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SQL Server中Oracle wm_concat的等效命令是什么?_Sql Server_Oracle - Fatal编程技术网

Sql server SQL Server中Oracle wm_concat的等效命令是什么?

Sql server SQL Server中Oracle wm_concat的等效命令是什么?,sql-server,oracle,Sql Server,Oracle,我想在一个字符串中检索列名列表 每个列名都应以逗号分隔 示例: col1, col2, col3 像这样试试 Select Stuff( ( Select ', ' + T2.ColVlaue // Add a comma (,) before each value From MyTable As T2 Where T2.ID= T1.ID For Xml Path(''), type // Select it

我想在一个字符串中检索列名列表

每个列名都应以逗号分隔

示例:

col1, col2, col3
像这样试试

Select Stuff(
        (
        Select ', ' + T2.ColVlaue  // Add a comma (,) before each value
        From MyTable As T2
        Where T2.ID= T1.ID
        For Xml Path(''), type // Select it as XML
        ).value('.', 'nvarchar(max)'), 1, 2, '')  // This is done to remove the first character (,) from the result
From MyTable As T1
Group By T1.Id
或:


在ORACLE中,您可以使用
listag
函数执行此操作:

    SELECT  
LISTAGG(COLUMN_NAME, ', ')
 WITHIN GROUP (ORDER BY COLUMN_NAME) "col names"
    FROM USER_TAB_COLUMNS
      where TABLE_NAME='Table names here';

我迟到了吗?kkk:)

T-SQL没有这样的函数。请注意,这已经被问了很多次了。你能解释一下它是如何工作的吗?Xml路径是关键字?@上一个SELECT查询将结果作为行集返回。通过在查询中指定FOR XML子句,可以选择以XML形式检索SQL查询的正式结果。FOR XML子句可用于顶级查询和子查询。。。路径模式和嵌套的XML查询功能以一种更简单的方式提供了显式模式的灵活性。谢谢,“路径”和“.value”的含义是什么?我在回答中添加了注释。请检查it@DMason:啊,有趣的解决办法。。修改这个问题的案文是值得的。。提议的解决方案到底在做什么?
    SELECT  
LISTAGG(COLUMN_NAME, ', ')
 WITHIN GROUP (ORDER BY COLUMN_NAME) "col names"
    FROM USER_TAB_COLUMNS
      where TABLE_NAME='Table names here';