1.46. Common functions of SQLite

发布时间 : 2025-10-25 13:32:41 UTC      

Page Views: 10 views

SQLite has many built-in functions for dealing with string or numeric data. Here are some useful SQLite built-in functions, all of which are case-insensitive, which means you can use these functions in lowercase or uppercase or mixed form. For more information, please check the official documentation of SQLite:

Serial number

Function & description

1

SQLite COUNT function

SQLite COUNT The aggregate function is used to calculate the number of rows in a database table.

2

SQLite MAX function

SQLite MAX The aggregate function allows us to select the maximum value of a column.

3

SQLite MIN function

SQLite MIN The aggregate function allows us to select the minimum value of a column.

4

SQLite AVG function

SQLite AVG The aggregate function calculates the average of a column.

5

SQLite SUM function

SQLite SUM Aggregate functions allow you to calculate the sum for a numeric column.

6

SQLite RANDOM function

SQLite RANDOM Function returns a pseudo-random integer between-9223372036854775808 and + 9223372036854775807.

7

SQLite ABS function

SQLite ABS Function returns the absolute value of a numeric parameter.

8

SQLite UPPER function

SQLite UPPER Function to convert a string to uppercase letters.

9

SQLite LOWER function

SQLite LOWER Function to convert a string to lowercase letters.

10

SQLite LENGTH function

SQLite LENGTH Function returns the length of the string.

11

SQLite sqlite_version function

SQLite sqlite_version Function returns the version of the SQLite library.

Before we begin to explain these function examples, assume that the COMPANY table has the following records:

ID NAME AGE ADDRESS SALARY ---------- ---------- ---------- ---------- ---------- 1 Paul 32 California 20000.0 2 Allen 25 Texas 15000.0 3 Teddy 23 Norway 20000.0 4 Mark 25 Rich-Mond 65000.0 5 David 27 Texas 85000.0 6 Kim 22 South-Hall 45000.0 7 James 24 Houston 10000.0 

1.46.1. SQLite COUNT function

SQLite COUNT The aggregate function is used to calculate the number of rows in a database table. Here is an example:

sqlite> SELECT count(*) FROM COMPANY; 

Above. SQLite SQL Statement will produce the following results:

count(*) ---------- 7 

1.46.2. SQLite MAX function

SQLite MAX The aggregate function allows us to select the maximum value of a column. Here is an example:

sqlite> SELECT max(salary) FROM COMPANY; 

Above. SQLite SQL Statement will produce the following results:

max(salary) ----------- 85000.0 

1.46.3. SQLite MIN function

The SQLite MIN aggregate function allows us to select the minimum value of a column. Here is an example:

sqlite> SELECT min(salary) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

min(salary) ----------- 10000.0 

1.46.4. SQLite AVG function

The SQLite AVG aggregate function calculates the average of a column. Here is an example:

sqlite> SELECT avg(salary) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

avg(salary) ---------------- 37142.8571428572 

1.46.5. SQLite SUM function

The SQLite SUM aggregate function allows you to calculate the sum for a numeric column. Here is an example:

sqlite> SELECT sum(salary) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

sum(salary) ----------- 260000.0 

1.46.6. SQLite RANDOM function

The SQLite RANDOM function returns a pseudo-random integer between-9223372036854775808 and + 9223372036854775807. Here is an example:

sqlite> SELECT random() AS Random; 

The above SQLite SQL statement produces the following results:

Random ------------------- 5876796417670984050 

1.46.7. SQLite ABS function

The SQLite ABS function returns the absolute value of a numeric parameter. Here is an example:

sqlite> SELECT abs(5), abs(-15), abs(NULL), abs(0), abs("ABC"); 

The above SQLite SQL statement produces the following results:

abs(5) abs(-15) abs(NULL) abs(0) abs("ABC") ---------- ---------- ---------- ---------- ---------- 5 15 0 0.0 

1.46.8. SQLite UPPER function

The SQLite UPPER function converts a string to uppercase letters. Here is an example:

sqlite> SELECT upper(name) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

upper(name) ----------- PAUL ALLEN TEDDY MARK DAVID KIM JAMES 

1.46.9. SQLite LOWER function

The SQLite LOWER function converts a string to lowercase letters. Here is an example:

sqlite> SELECT lower(name) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

lower(name) ----------- paul allen teddy mark david kim james 

1.46.10. SQLite LENGTH function

The SQLite LENGTH function returns the length of the string. Here is an example:

sqlite> SELECT name, length(name) FROM COMPANY; 

The above SQLite SQL statement produces the following results:

NAME length(name) ---------- ------------ Paul 4 Allen 5 Teddy 5 Mark 4 David 5 Kim 3 James 5 

1.46.11. SQLite sqlite_version function

The SQLite sqlite_version function returns the version of the SQLite library. Here is an example:

sqlite> SELECT sqlite_version() AS 'SQLite Version'; 

The above SQLite SQL statement produces the following results:

SQLite Version -------------- 3.6.20 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。