concat函数

concat()concat_ws()函数返回一个或多个字符串连接产生的字符串。

concat()函数

concat()函数至少需要两个或以上字符串参数,并将所有参数连接成一个字符串。

  • 如果字符串参数只有一个,则返回该字符串参数本身。

  • 如果任何一个的字符串参数为 NULL,则 concat() 函数返回值为NULL

语法

  1. concat(string1,string2,...)

示例

  1. //连接1,2,3
  2. nebula> RETURN concat("1","2","3") AS r;
  3. +-------+
  4. | r |
  5. +-------+
  6. | "123" |
  7. +-------+
  8. //字符串参数有NULL
  9. nebula> RETURN concat("1","2",NULL) AS r;
  10. +----------+
  11. | r |
  12. +----------+
  13. | __NULL__ |
  14. +----------+
  15. nebula> GO FROM "player100" over follow \
  16. YIELD concat(src(edge), properties($^).age, properties($$).name, properties(edge).degree) AS A;
  17. +------------------------------+
  18. | A |
  19. +------------------------------+
  20. | "player10042Tony Parker95" |
  21. | "player10042Manu Ginobili95" |
  22. +------------------------------+

concat_ws()函数

concat_ws()函数将两个或以上字符串参数与预定义的分隔符(separator)相连接。

  • 如果分隔符为NULL时,concat_ws()函数才返回NULL

  • 如果分隔符不为NULL,字符串参数只有一个,则返回该字符串参数本身。

  • 字符串参数存在NULL值时,忽略NULL值,继续连接下一个参数。

语法

  1. concat_ws(separator,string1,string2,... )

示例

  1. //分隔符为+,连接a,b,c
  2. nebula> RETURN concat_ws("+","a","b","c") AS r;
  3. +---------+
  4. | r |
  5. +---------+
  6. | "a+b+c" |
  7. +---------+
  8. //分隔符为 NULL
  9. neubla> RETURN concat_ws(NULL,"a","b","c") AS r;
  10. +----------+
  11. | r |
  12. +----------+
  13. | __NULL__ |
  14. +----------+
  15. //分隔符为+,字符串参数有NULL
  16. nebula> RETURN concat_ws("+","a",NULL,"b","c") AS r;
  17. +---------+
  18. | r |
  19. +---------+
  20. | "a+b+c" |
  21. +---------+
  22. //分隔符为+。字符串参数只有一个
  23. nebula> RETURN concat_ws("+","a") AS r;
  24. +-----+
  25. | r |
  26. +-----+
  27. | "a" |
  28. +-----+
  29. nebula> GO FROM "player100" over follow \
  30. YIELD concat_ws(" ",src(edge), properties($^).age, properties($$).name, properties(edge).degree) AS A;
  31. +---------------------------------+
  32. | A |
  33. +---------------------------------+
  34. | "player100 42 Tony Parker 95" |
  35. | "player100 42 Manu Ginobili 95" |
  36. +---------------------------------+

最后更新: October 27, 2021