📄 lang_corefunc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>SQLite Query Language: Core Functions</title><style type="text/css">body { margin: auto; font-family: "Verdana" "sans-serif"; padding: 8px 1%;}a { color: #45735f }a:visited { color: #734559 }.logo { position:absolute; margin:3px; }.tagline { float:right; text-align:right; font-style:italic; width:240px; margin:12px; margin-top:58px;}.toolbar { font-variant: small-caps; text-align: center; line-height: 1.6em; margin: 0; padding:1px 8px;}.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }.toolbar a:visited { color: white; }.toolbar a:hover { color: #80a796; background: white; }.content { margin: 5%; }.content dt { font-weight:bold; }.content dd { margin-bottom: 25px; margin-left:20%; }.content ul { padding:0px; padding-left: 15px; margin:0px; }/* rounded corners */.se { background: url(images/se.png) 100% 100% no-repeat #80a796}.sw { background: url(images/sw.png) 0% 100% no-repeat }.ne { background: url(images/ne.png) 100% 0% no-repeat }.nw { background: url(images/nw.png) 0% 0% no-repeat }</style><meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head><body><div><!-- container div to satisfy validator --><a href="index.html"><img class="logo" src="images/SQLite.gif" alt="SQLite Logo" border="0"></a><div><!-- IE hack to prevent disappearing logo--></div><div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div><table width=100% style="clear:both"><tr><td> <div class="se"><div class="sw"><div class="ne"><div class="nw"> <div class="toolbar"> <a href="about.html">About</a> <a href="sitemap.html">Sitemap</a> <a href="docs.html">Documentation</a> <a href="download.html">Download</a> <a href="copyright.html">License</a> <a href="news.html">News</a> <a href="http://www.sqlite.org/cvstrac/index">Developers</a> <a href="support.html">Support</a> </div></div></div></div></div></td></tr></table> <a href="lang.html"><h2>SQL As Understood By SQLite</h2></a><h3>Core Functions</h3><p>The core functions shown below are available by default. Additionalfunctions may be written in C and added to the database engine usingthe <a href="c3ref/create_function.html">sqlite3_create_function()</a> API.</p><table border=0 cellpadding=10><tr><td valign="top" align="right" width="120">abs(<i>X</i>)</td><td valign="top"><a name="abs"></a> Return the absolute value of the numeric argument <i>X</i>. Return NULL if <i>X</i> is NULL. Return 0.0 if <i>X</i> is not a numeric value.</td></tr><tr><td valign="top" align="right" width="120">coalesce(<i>X</i>,<i>Y</i>,...)</td><td valign="top"><a name="coalesce"></a> Return a copy of the first non-NULL argument. If all arguments are NULL then NULL is returned. There must be at least 2 arguments.</td></tr><tr><td valign="top" align="right" width="120">glob(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="glob"></a> This function is used to implement the "<b>X GLOB Y</b>" syntax of SQLite. The <a href="c3ref/create_function.html">sqlite3_create_function()</a> interface can be used to override this function and thereby change the operation of the <a href="lang_expr.html#glob">GLOB</a> operator.</td></td></tr><tr><td valign="top" align="right" width="120">ifnull(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="ifnull"></a> Return a copy of the first non-NULL argument. If both arguments are NULL then NULL is returned. This behaves the same as <a href="lang_corefunc.html#coalesce">coalesce()</a>.</td></td></tr><tr><td valign="top" align="right" width="120">hex(<i>X</i>)</td><td valign="top"><a name="hex"></a> The argument is interpreted as a BLOB. The result is a hexadecimal rendering of the content of that blob.</td></tr><tr><td valign="top" align="right" width="120">last_insert_rowid()</td><td valign="top"><a name="last_insert_rowid"></a> Return the <a href="lang_createtable.html#rowid">ROWID</a> of the last row insert from this connection to the database. This is the same value that would be returned from the <a href="c3ref/last_insert_rowid.html">sqlite3_last_insert_rowid()</a> API function.</td></tr><tr><td valign="top" align="right" width="120">length(<i>X</i>)</td><td valign="top"><a name="length"></a> Return the string length of <i>X</i> in characters. If SQLite is configured to support UTF-8, then the number of UTF-8 characters is returned, not the number of bytes.</td></tr><tr><td valign="top" align="right" width="120">like(<i>X</i>,<i>Y</i>)<br></br>like(<i>X</i>,<i>Y</i>,<i>Z</i>)</td><td valign="top"><a name="like"></a> This function is used to implement the "<b>X LIKE Y [ESCAPE Z]</b>" syntax of SQL. If the optional ESCAPE clause is present, then the user-function is invoked with three arguments. Otherwise, it is invoked with two arguments only. The <a href="c3ref/create_function.html">sqlite3_create_function()</a> interface can be used to override this function and thereby change the operation of the <a href="lang_expr.html#like">LIKE</a> operator. When doing this, it may be important to override both the two and three argument versions of the like() function. Otherwise, different code may be called to implement the <a href="lang_expr.html#like">LIKE</a> operator depending on whether or not an ESCAPE clause was specified.</td></tr><tr><td valign="top" align="right" width="120">load_extension(<i>X</i>)<br></br>load_extension(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="load_extension"></a> Load SQLite extensions out of the shared library file named <i>X</i> using the entry point <i>Y</i>. The result is a NULL. If <i>Y</i> is omitted then the default entry point of <b>sqlite3_extension_init</b> is used. This function raises an exception if the extension fails to load or initialize correctly. <p>This function will fail if the extension attempts to modify or delete a SQL function or collating sequence. The extension can add new functions or collating sequences, but cannot modify or delete existing functions or collating sequences because those functions and/or collating sequences might be used elsewhere in the currently running SQL statement. To load an extension that changes or deletes functions or collating sequences, use the <a href="c3ref/load_extension.html">sqlite3_load_extension()</a> C-language API.</p></td></tr><tr><td valign="top" align="right" width="120">lower(<i>X</i>)</td><td valign="top"><a name="lower"></a> Return a copy of string <i>X</i> will all ASCII characters converted to lower case. The C library <b>tolower()</b> routine is used for the conversion, which means that this function might not work correctly on non-ASCII UTF-8 characters.</td></tr><tr><td valign="top" align="right" width="120">ltrim(<i>X</i>)<br></br>ltrim(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="ltrim"></a> Return a string formed by removing any and all characters that appear in <i>Y</i> from the left side of <i>X</i>. If the <i>Y</i> argument is omitted, spaces are removed.</td></tr><tr><td valign="top" align="right" width="120">max(<i>X</i>,<i>Y</i>,...)</td><td valign="top"><a name="maxCoreFunc"></a> Return the argument with the maximum value. Arguments may be strings in addition to numbers. The maximum value is determined by the usual sort order. Note that <b>max()</b> is a simple function when it has 2 or more arguments but converts to an aggregate function if given only a single argument.</td></tr><tr><td valign="top" align="right" width="120">min(<i>X</i>,<i>Y</i>,...)</td><td valign="top"><a name="minCoreFunc"></a> Return the argument with the minimum value. Arguments may be strings in addition to numbers. The minimum value is determined by the usual sort order. Note that <b>min()</b> is a simple function when it has 2 or more arguments but converts to an aggregate function if given only a single argument.</td></tr><tr><td valign="top" align="right" width="120">nullif(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="nullif"></a> Return the first argument if the arguments are different, otherwise return NULL.</td></tr><tr><td valign="top" align="right" width="120">quote(<i>X</i>)</td><td valign="top"><a name="quote"></a> This routine returns a string which is the value of its argument suitable for inclusion into another SQL statement. Strings are surrounded by single-quotes with escapes on interior quotes as needed. BLOBs are encoded as hexadecimal literals. The implementation of <a href="lang_vacuum.html">VACUUM</a> uses this function. The function is also useful when writing triggers to implement undo/redo functionality.</td></tr><tr><td valign="top" align="right" width="120">random()</td><td valign="top"><a name="random"></a> Return a pseudo-random integer between -9223372036854775808 and +9223372036854775807.</td></tr><tr><td valign="top" align="right" width="120">randomblob(<i>N</i>)</td><td valign="top"><a name="randomblob"></a> Return an <i>N</i>-byte blob containing pseudo-random bytes. <i>N</i> should be a postive integer. <p>Hint: applications can generate globally unique identifiers using this function together with <a href="lang_corefunc.html#hex">hex()</a> and/or <a href="lang_corefunc.html#lower">lower()</a> like this:</p> <blockquote> hex(randomblob(16))<br></br> lower(hex(randomblob(16))) </blockquote></td></tr><tr><td valign="top" align="right" width="120">replace(<i>X</i>,<i>Y</i>,<i>Z</i>)</td><td valign="top"><a name="replace"></a> Return a string formed by substituting string <i>Z</i> for every occurrance of string <i>Y</i> in string <i>X</i>. The <a href="datatype3.html#collation">BINARY</a> collating sequence is used for comparisons.</td></tr><tr><td valign="top" align="right" width="120">round(<i>X</i>)<br></br>round(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="round"></a> Round off the number <i>X</i> to <i>Y</i> digits to the right of the decimal point. If the <i>Y</i> argument is omitted, 0 is assumed.</td></tr><tr><td valign="top" align="right" width="120">rtrim(<i>X</i>)<br></br>rtrim(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="rtrim"></a> Return a string formed by removing any and all characters that appear in <i>Y</i> from the right side of <i>X</i>. If the <i>Y</i> argument is omitted, spaces are removed.</td></tr><tr><td valign="top" align="right" width="120">soundex(<i>X</i>)</td><td valign="top"><a name="soundex"></a> Compute the soundex encoding of the string <i>X</i>. The string "?000" is returned if the argument is NULL. This function is omitted from SQLite by default. It is only available the -DSQLITE_SOUNDEX=1 compiler option is used when SQLite is built.</td></tr><tr><td valign="top" align="right" width="120">sqlite_version(<i>X</i>)</td><td valign="top"><a name="sqlite_version"></a> Return the version string for the SQLite library that is running. Example: "3.5.9"</td></tr><tr><td valign="top" align="right" width="120">substr(<i>X</i>,<i>Y</i>,<i>Z</i>)<br></br>substr(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="substr"></a> Return a substring of input string <i>X</i> that begins with the <i>Y</i>-th character and which is <i>Z</i> characters long. If <i>Z</i> is omitted then all character through the end of the string are returned. The left-most character of <i>X</i> is number 1. If <i>Y</i> is negative the the first character of the substring is found by counting from the right rather than the left. If <i>X</i> is string then characters indices refer to actual UTF-8 characters. If <i>X</i> is a BLOB then the indices refer to bytes.</td></tr><tr><td valign="top" align="right" width="120">trim(<i>X</i>)<br></br>trim(<i>X</i>,<i>Y</i>)</td><td valign="top"><a name="trim"></a> Return a string formed by removing any and all characters that appear in <i>Y</i> from both ends of <i>X</i>. If the <i>Y</i> argument is omitted, spaces are removed.</td></tr><tr><td valign="top" align="right" width="120">typeof(<i>X</i>)</td><td valign="top"><a name="typeof"></a> Return the type of the expression <i>X</i>. The only return values are "null", "integer", "real", "text", and "blob". SQLite's type handling is explained in <a href="datatype3.html">Datatypes in SQLite Version 3</a>.</td></tr><tr><td valign="top" align="right" width="120">upper(<i>X</i>)</td><td valign="top"><a name="upper"></a> Return a copy of input string <i>X</i> converted to all upper-case letters. The implementation of this function uses the C library routine <b>toupper()</b> which means it may not work correctly on non-ASCII UTF-8 strings.</td></tr><tr><td valign="top" align="right" width="120">zeroblob(<i>N</i>)</td><td valign="top"><a name="zeroblob"></a> Return 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 <a href="c3ref/blob_open.html">incremental BLOB I/O</a>.</td></tr></table><hr><small><i>This page last modified 2008/04/27 17:48:52 UTC</i></small></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -