微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLite的37个核心函数

abs(X)

abs(X)返回 X 的绝对值。

Abs(X) returns NULL if X is NULL.

Abs(X) return 0.0 if X is a string or blob that cannot be converted to a numeric value. If X is the integer -9223372036854775807 then abs(X) throws an integer overflow error since there is no equivalent positive 64-bit two complement value.

changes()

changes()函数返回数据库已更新的记录数INSERT,DELETE,UPDATE 语句。

char(X1,X2,...,XN) 返回X1,XN等UNICODE码对应的字符。
coalesce(X,Y,...)

返回第一个非空参数,全为NULL时返回NULL;参数至少包含两个参数。

glob(X,Y) 用于实现sqlite的 "X GLOB Y"语法。可使用 sqlite3_create_function() 重载该函数从而改变GLOB运算符的功能
ifnull(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 返回第一个非空参数的副本。 若两个参数均为NULL,返回NULL。与coalesce()类似。
instr(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> The instr(X,Y) function finds the first occurrence of string Y within string X and returns the number of prior characters plus 1,or 0 if Y is Nowhere found within X. Or,if X and Y are both BLOBs,then instr(X,Y) returns one more than the number bytes prior to the first occurrence of Y,or 0 if Y does not occur anywhere within X. If both arguments X and Y to instr(X,Y) are non-NULL and are not BLOBs then both are interpreted as strings. If either X or Y are NULL in instr(X,Y) then the result is NULL.
hex(X) The hex() function interprets its argument as a BLOB and returns a string which is the upper-case hexadecimal rendering of the content of that blob.
last_insert_rowid() The last_insert_rowid() function returns theROWIDof the last row insert from the database connection which invoked the function. The last_insert_rowid() sql function is a wrapper around thesqlite3_last_insert_rowid()C/C++ interface function.
length(X) For a string value X,the length(X) function returns the number of characters (not bytes) in X prior to the first NUL character. Since sqlite strings do not normally contain NUL characters,the length(X) function will usually return the total number of characters in the string X. For a blob value X,length(X) returns the number of bytes in the blob. If X is NULL then length(X) is NULL. If X is numeric then length(X) returns the length of a string representation of X.
like(X,Y)
like(X,Z)

用于实现sql语法"X LIKE Y [ESCAPE Z]".若使用可选的ESCAPE子句,则函数被赋予三个参数,否则只有两个。可使用sqlite3_create_function()重载该函数从而改变LIKE运算符的功能注意同时重载like()的两参数和三参数版本,否则在使用/不使用ESCAPE子句时,LIKE运算符的实现可能使用的是不同的代码

likelihood(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> The likelihood(X,Y) function returns argument X unchanged. The value Y in likelihood(X,Y) must be a floating point constant between 0.0 and 1.0,inclusive. The likelihood(X) function is a no-op that the code generator optimizes away so that it consumes no cpu cycles during run-time (that is,during calls tosqlite3_step()). The purpose of the likelihood(X,Y) function is to provide a hint to the query planner that the argument X is a boolean that is true with a probability of approximately Y. Theunlikely(X)function is short-hand for likelihood(X,0.0625).
load_extension(X)
load_extension(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 尝试加载一个sqlite扩展库
lower(X) 转换为小写
ltrim(X)
ltrim(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> The ltrim(X,Y) function returns a string formed by removing any and all characters that appear in Y from the left side of X. If the Y argument is omitted,ltrim(X) removes spaces from the left side of X.
max(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 返回一组中的最大值。
min(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 返回一组中的最小值。
nullif(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 当两参数不同时返回X,否则返回NULL
quote(X) 返回参数的适于插入其它sql语句中的值。字符串会被添加单引号,在内部的引号前会加入逃逸符号。BLOB被编码为十六进制文本。当前的VACUUM使用这一函数实现。在使用触发器实现撤销/重做功能时这一函数也很有用。
random() 返回一个[-9223372036854775808,+9223372036854775807]区间内的随机
randomblob(N) The randomblob(N) function return an N-byte blob containing pseudo-random bytes. If N is less than 1 then a 1-byte random blob is returned. Hint: applications can generate globally unique identifiers using this function together withhex()and/orlower()like this:hex(randomblob(16))

lower(hex(randomblob(16)))
replace(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> The replace(X,Z) function returns a string formed by substituting string Z for every occurrence of string Y in string X. TheBINARYcollating sequence is used for comparisons. If Y is an empty string then return X unchanged. If Z is not initially a string,it is cast to a UTF-8 string prior to processing.
round(X)
round(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> X四舍五入,保留小数点后Y位。若忽略Y参数,则认其为0
rtrim(X)
rtrim(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit">

rtrim(X,Y)返回去除X串右边的Y字符的副本。

rtrim(X) 返回去除X串右边的空格字符的副本。

soundex(X) The soundex(X) function returns a string that is the soundex encoding of the string X. The string "?000" is returned if the argument is NULL or contains no ASCII alphabetic characters. This function is omitted from sqlite by default. It is only available if thesqlITE_SOUNDEXcompile-time option is used when sqlite is built.
sqlite_compileoption_get(N) The sqlite_compileoption_get() sql function is a wrapper around thesqlite3_compileoption_get()C/C++ function. This routine returns the N-th compile-time option used to build sqlite or NULL if N is out of range. See also thecompile_options pragma.
sqlite_compileoption_used(X) The sqlite_compileoption_used() sql function is a wrapper around thesqlite3_compileoption_used()C/C++ function. When the argument X to sqlite_compileoption_used(X) is a string which is the name of a compile-time option,this routine returns true (1) or false (0) depending on whether or not that option was used during the build.
sqlite_source_id() The sqlite_source_id() function returns a string that identifies the specific version of the source code that was used to build the sqlite library. The string returned by sqlite_source_id() begins with the date and time that the source code was checked in and is follows by an SHA1 hash that uniquely identifies the source tree. This function is an sql wrapper around thesqlite3_sourceid()C interface.
sqlite_version() 返回sqlite数据库版本信息
substr(X,Z)
substr(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> 返回输入字符串X中以第Y个字符开始,Z个字符长的子串。X最左端的字符序号为1。若Y为负,则从右至左数起。若sqlite配置支持UTF-8,则字符代表的是UTF-8字符而非字节。
total_changes() The total_changes() function returns the number of row changes caused by INSERT,UPDATE or DELETE statements since the current database connection was opened. This function is a wrapper around thesqlite3_total_changes()C/C++ interface.
trim(X)
trim(X,153); padding:5px 16px 5px 12px; min-height:25px; min-width:25px; height:25px; background-color:inherit"> The trim(X,Y) function returns a string formed by removing any and all characters that appear in Y from both ends of X. If the Y argument is omitted,trim(X) removes spaces from both ends of X.
typeof(X) 返回表达式X的类型。返回值可能为"null","integer","real","text",以及"blob".
unlikely(X) The unlikely(X) function returns the argument X unchanged. The unlikely(X) function is a no-op that the code generator optimizes away so that it consumes no cpu cycles at run-time (that is,0)">sqlite3_step()). The purpose of the unlikely(X) function is to provide a hint to the query planner that the argument X is a boolean value that is usually not true. The unlikely(X) function is equivalent tolikelihood(X,0); text-align:center"> unicode(X) The unicode(X) function returns the numeric unicode code point corresponding to the first character of the string X. If the argument to unicode(X) is not a string then the result is undefined.
upper(X) 转换为大写
zeroblob(N) The zeroblob(N) function returns a BLOB consisting of N bytes of 0x00. sqlite manages these zeroblobs very efficiently. Zeroblobs can be used to reserve space for a BLOB that is later written using incremental BLOB I/O. This sql function is implemented using thesqlite3_result_zeroblob()routine from the C/C++ interface.

原文地址:https://www.jb51.cc/sqlite/199257.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐