SQLite的37個核心函數

來源:互聯網
上載者:User

標籤:

轉載:http://www.feiesoft.com/00012/

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,X2,...,XN等UNICODE碼對應的字元。
coalesce(X,Y,...)

返回第一個不允許為 NULL 的參數,全為NULL時返回NULL;參數至少包含兩個參數。

glob(X,Y) 用於實現SQLite的 "X GLOB Y"文法。可使用 sqlite3_create_function() 重載該函數從而改變GLOB運算子的功能。
ifnull(X,Y) 返回第一個不允許為 NULL 的參數的副本。 若兩個參數均為NULL,返回NULL。與coalesce()類似。
instr(X,Y) 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 the ROWID  of 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,Y,Z)

用於實現SQL文法"X LIKE Y [ESCAPE Z]".若使用可選的ESCAPE子句,則函數被賦予三個參數,否則只有兩個。可使用sqlite3_create_function() 重載該函數從而改變LIKE運算子的功能。 注意同時重載like()的兩參數和三參數版本,否則在使用/不使用 ESCAPE子句時,LIKE運算子的實現可能使用的是不同的代碼。

likelihood(X,Y) 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 to sqlite3_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.  The unlikely(X) function is short-hand for likelihood(X,0.0625).
load_extension(X)
 load_extension(X,Y)
嘗試載入一個SQLite擴充庫
lower(X) 轉換為小寫
ltrim(X)
 ltrim(X,Y)
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,Y,...) 返回一組中的最大值。
min(X,Y,...) 返回一組中的最小值。
nullif(X,Y) 當兩參數不同時返回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 with hex() and/or lower() like this:hex(randomblob(16))
 
 lower(hex(randomblob(16)))
replace(X,Y,Z) The replace(X,Y,Z) function returns a string formed  by substituting string Z for every occurrence of string Y in string X. The BINARY  collating 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,Y)
將X四捨五入,保留小數點後Y位。若忽略Y參數,則預設其為0。
rtrim(X)
 rtrim(X,Y)

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 the SQLITE_SOUNDEX  compile-time option is used when SQLite is built.
sqlite_compileoption_get(N) The sqlite_compileoption_get() SQL function is a  wrapper around the sqlite3_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 the compile_options pragma.
sqlite_compileoption_used(X) The sqlite_compileoption_used() SQL function is a  wrapper around the sqlite3_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 the sqlite3_sourceid() C interface.
sqlite_version() 返回SQLite資料庫版本資訊
substr(X,Y,Z)
 substr(X,Y)
返回輸入字串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,Y)
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, during calls to 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.0625).
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 the sqlite3_result_zeroblob()  routine from the C/C++ interface.

SQLite的37個核心函數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.