|| apoc.coll.randomItem - APOC 核心文档 - Neo4j 文档

apoc.coll.randomItem

详情

语法

apoc.coll.randomItem(coll)

描述

LIST<ANY> 中返回一个随机项,如果为 LIST<NOTHING>LIST<NULL> 则返回 null。

参数

名称

类型

描述

coll

LIST<ANY>

从中返回随机项的列表。

返回

ANY

使用示例

以下示例演示了如何使用 APOC 和 Cypher 从列表中返回一个随机值

apoc.coll.randomItem
RETURN apoc.coll.randomItem([1,3,5,7,9]) AS output;
使用 Cypher 的 rand()
WITH [1,3,5,7,9] AS list
WITH list, toInteger(rand() * size(list)) AS randomInt
RETURN list[randomInt] AS output
结果
输出

7

© . This site is unofficial and not affiliated with Neo4j, Inc.