Orientdb 简明教程

OrientDB - Functions

本章解释了 OrientDB 中不同类型函数的完整参考。下表定义了按其功能分类的函数列表。

This chapter explains the complete reference of different types of functions in OrientDB. The following table defines the list of functions, which are categorized by their functionality.

Graph Functions

使用以下查询尝试一些图函数。

Try some graph functions along with the following queries.

执行以下查询以获取所有车辆顶点的所有传出顶点。

Execute the following query to get all the outgoing vertices from all the vehicle vertices.

orientdb {db = demo}>SELECT out() from Vehicle

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

---+----------+---------
 # | @class   | out
---+----------+---------
 0 | Vehicle  | #11:2
 1 | Vehicle  | #13:1
 2 | Vehicle  | #13:4
---+----------+---------

执行以下查询以获取顶点 #11:3 的传入和传出顶点。

Execute the following query to get both incoming and outgoing vertices from the vertex #11:3.

orientdb {db = demo}>SELECT both() FROM #11:3

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

---+----------+--------+-------
 # | @class   | out    | in
---+----------+--------+-------
 0 | Vehicle  | #13:2  | #10:2
 ---+----------+-------+-------

Math Functions

使用以下查询尝试一些数学函数。

Try some math functions using the following queries.

执行以下查询以获取所有员工的薪水总和。

Execute the following query to get the sum of salaries of all employees.

orientdb {db = demo}>SELECT SUM(salary) FROM Employee

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

---+----------+---------
 # | @CLASS   | sum
---+----------+---------
 0 | null     | 150000
---+----------+---------

执行以下查询以获取所有员工的平均薪水。

Execute the following query to get the average salary of all employees.

orientdb {db = demo}>SELECT avg(salary) FROM Employee

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

---+----------+---------
 # | @CLASS   | avg
---+----------+---------
 0 | null     | 25
---+----------+---------

Collections Functions

使用以下查询尝试一些集合函数。

Try some collection functions using the following queries.

执行以下查询以获取教授 9 年级课程的一组教师。

Execute the following query to get a set of teachers, teaching class 9th.

orientdb {db = demo}>SELECT ID, set(teacher.id) AS teacherID from classess where class_id = 9

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

---+----------+--------+--------------------------
 # | @CLASS   | id     | TeacherID
---+----------+--------+--------------------------
 0 | null     | 9     |   1201, 1202, 1205, 1208
---+----------+-------+---------------------------

Misc Functions

使用以下查询尝试一些其他函数。

Try some Misc functions using the following queries.

执行以下查询以学习如何执行 if 表达式。

Execute the following query to learn how to execute if expression.

orientdb {db = demo}> SELECT if(eval("name = 'satish'"), "My name is satish",
"My name is not satish") FROM Employee

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

----+--------+-----------------------
#   |@CLASS  | IF
----+--------+-----------------------
0   |null    |My name is satish
1   |null    |My name is not satish
2   |null    |My name is not satish
3   |null    |My name is not satish
4   |null    |My name is not satish
----+--------+------------------------

执行以下查询以获取系统日期。

Execute the following query to get system date.

orientdb {db = demo}> SELECT SYSDATE() FROM Employee

如果成功执行了以上查询,您会获得以下输出。

If the above query is executed successfully, you will get the following output.

----+--------+-----------------------
#   |@CLASS  | SYSDATE
----+--------+-----------------------
0   |null    |2016-02-10 12:05:06
1   |null    |2016-02-10 12:05:06
2   |null    |2016-02-10 12:05:06
3   |null    |2016-02-10 12:05:06
4   |null    |2016-02-10 12:05:06
----+--------+------------------------

通过彻底使用此函数,你可以轻松地处理 OrientDB 数据。

By using this function thoroughly you can easily manipulate the OrientDB data.