SQLite 函数

SQLite CHANGES() 函数返回最近完成的 INSERT、DELETE 或 UPDATE 语句更改、插入或删除的数据库行数,不包括语句在较低级别的触发器中。

语法

CHANGES()

参数

不需要参数。

返回值

返回最近完成的 INSERT、DELETE 或 UPDATE 语句更改、插入或删除的数据库行数

示例:

考虑示例下面创建了一个名为 Employee 的表。创建表后,CHANGES() 函数用于获取最近完成的 INSERT、DELETE 或 UPDATE 语句更改或插入或删除的行数。

sqlite> CREATE TABLE Employee (
  EmpID INTEGER PRIMARY KEY, 
  Name VARCHAR(50));

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         0 |
+-----------+

sqlite> INSERT INTO Employee(Name) Values ('John');

sqlite> INSERT INTO Employee(Name) Values ('Marry');

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> INSERT INTO Employee(Name) Values ('Kim') , ('Jo');

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         2 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+-------+
| EmpID | Name  |
+-------+-------+
| 1     | John  |
| 2     | Marry |
| 3     | Kim   |
| 4     | Jo    |
+-------+-------+

sqlite> UPDATE Employee SET Name = 'Suresh' WHERE EmpID = 4;

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+--------+
| EmpID | Name   |
+-------+--------+
| 1     | John   |
| 2     | Marry  |
| 3     | Kim    |
| 4     | Suresh |
+-------+--------+

sqlite> DELETE FROM Employee WHERE EmpID = 4;

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+-------+
| EmpID | Name  |
+-------+-------+
| 1     | John  |
| 2     | Marry |
| 3     | Kim   |
+-------+-------+