Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.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

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 Listagg delimeter正在打印,如果没有选择值_Sql_Oracle_Oracle12c_Colon_Listagg - Fatal编程技术网

Sql Listagg delimeter正在打印,如果没有选择值

Sql Listagg delimeter正在打印,如果没有选择值,sql,oracle,oracle12c,colon,listagg,Sql,Oracle,Oracle12c,Colon,Listagg,我在select语句中使用了listag() SELECT DISTINCT REPLACE(LISTAGG(a.student1||':'||a.score||'+') WITHIN GROUP ( ORDER BY a.roll_no) OVER (PARTITION BY a.class) 如果我的select语句没有空值,那么我得到 例如:ABC:100 但是如果select是空的,那么我得到 例如:: 如果没有选择行,我希望它为空。好吧,您的替换不完

我在select语句中使用了
listag()

SELECT DISTINCT REPLACE(LISTAGG(a.student1||':'||a.score||'+') 
                WITHIN GROUP ( ORDER BY a.roll_no) OVER (PARTITION BY a.class)
如果我的select语句没有空值,那么我得到 例如:
ABC:100

但是如果select是空的,那么我得到 例如:


如果没有选择行,我希望它为空。

好吧,您的
替换
不完整。另外,
“+”
真的应该被连接吗?那么,什么字符串分隔值呢

   REPLACE (
      LISTAGG (a.student1 || ':' || a.score, '+')    --> removed || for the + sign
         WITHIN GROUP (ORDER BY a.roll_no)
         OVER (PARTITION BY a.class),
      ':', '')                                       --> missing arguments for REPLACE

如果这仍然不是您所要求的,请提供示例测试数据和所需输出。

问题是,无论您连接的值是否为
NULL
,您聚合的表达式都返回非NULL值。我猜你想要像这样的东西

listagg(case when a.student1 is not null
             then a.student1||':'||a.score||'+'
             else null
          end)

如果可以为
student1
设置一个
null
值,但为
score
设置一个非null值,则需要调整
case
语句,以指定在这种情况下希望发生的情况(是否希望使用“:”和“+”?仅使用“+”?)

这是可行的,但如果我删除了| | |则结果中缺少一个字符。例如:如果我的结果应该是ahd:100+acz:77,我得到的是ahd:100+acz:7。最后是一个7