📄 lang.tcl
字号:
<td valign="top">Return a copy of the first non-NULL argument. Ifall arguments are NULL then NULL is returned. There must be at least 2 arguments.</td></tr><tr><a name="globFunc"></a><td valign="top" align="right">glob(<i>X</i>,<i>Y</i>)</td><td valign="top">This function is used to implement the"<b>X GLOB Y</b>" syntax of SQLite. The<a href="capi3ref.html#sqlite3_create_function">sqlite3_create_function()</a> interface canbe used to override this function and thereby change the operationof the <a href="#glob">GLOB</a> operator.</td></tr><tr><td valign="top" align="right">ifnull(<i>X</i>,<i>Y</i>)</td><td valign="top">Return a copy of the first non-NULL argument. Ifboth arguments are NULL then NULL is returned. This behaves the same as <b>coalesce()</b> above.</td></tr><tr><td valign="top" align="right">last_insert_rowid()</td><td valign="top">Return the ROWID of the last row insert from thisconnection to the database. This is the same value that would be returnedfrom the <b>sqlite_last_insert_rowid()</b> API function.</td></tr><tr><td valign="top" align="right">length(<i>X</i>)</td><td valign="top">Return the string length of <i>X</i> in characters.If SQLite is configured to support UTF-8, then the number of UTF-8characters is returned, not the number of bytes.</td></tr><tr><a name="likeFunc"></a><td valign="top" align="right">like(<i>X</i>,<i>Y</i> [,<i>Z</i>])</td><td valign="top">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 theuser-function is invoked with three arguments. Otherwise, it isinvoked with two arguments only. The <a href="capi3ref.html#sqlite3_create_function">sqlite_create_function()</a> interface can be used to override thisfunction and thereby change the operation of the <ahref= "#like">LIKE</a> operator. When doing this, it may be importantto override both the two and three argument versions of the like() function. Otherwise, different code may be called to implement theLIKE operator depending on whether or not an ESCAPE clause was specified.</td></tr><tr><td valign="top" align="right">lower(<i>X</i>)</td><td valign="top">Return a copy of string <i>X</i> will all charactersconverted to lower case. The C library <b>tolower()</b> routine is usedfor the conversion, which means that this function might notwork correctly on UTF-8 characters.</td></tr><tr><td valign="top" align="right">max(<i>X</i>,<i>Y</i>,...)</td><td valign="top">Return the argument with the maximum value. Argumentsmay be strings in addition to numbers. The maximum value is determinedby the usual sort order. Note that <b>max()</b> is a simple function whenit has 2 or more arguments but converts to an aggregate function if givenonly a single argument.</td></tr><tr><td valign="top" align="right">min(<i>X</i>,<i>Y</i>,...)</td><td valign="top">Return the argument with the minimum value. Argumentsmay be strings in addition to numbers. The minimum value is determinedby the usual sort order. Note that <b>min()</b> is a simple function whenit has 2 or more arguments but converts to an aggregate function if givenonly a single argument.</td></tr><tr><td valign="top" align="right">nullif(<i>X</i>,<i>Y</i>)</td><td valign="top">Return the first argument if the arguments are different, otherwise return NULL.</td></tr><tr><td valign="top" align="right">quote(<i>X</i>)</td><td valign="top">This routine returns a string which is the value ofits argument suitable for inclusion into another SQL statement.Strings are surrounded by single-quotes with escapes on interior quotesas needed. BLOBs are encoded as hexadecimal literals.The current implementation of VACUUM uses this function. The functionis also useful when writing triggers to implement undo/redo functionality.</td></tr><tr><td valign="top" align="right">random(*)</td><td valign="top">Return a random integer between -2147483648 and+2147483647.</td></tr><tr><td valign="top" align="right">round(<i>X</i>)<br>round(<i>X</i>,<i>Y</i>)</td><td valign="top">Round off the number <i>X</i> to <i>Y</i> digits to theright of the decimal point. If the <i>Y</i> argument is omitted, 0 is assumed.</td></tr><tr><td valign="top" align="right">soundex(<i>X</i>)</td><td valign="top">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 optionis used when SQLite is built.</td></tr><tr><td valign="top" align="right">sqlite_version(*)</td><td valign="top">Return the version string for the SQLite librarythat is running. Example: "2.8.0"</td></tr><tr><td valign="top" align="right">substr(<i>X</i>,<i>Y</i>,<i>Z</i>)</td><td valign="top">Return a substring of input string <i>X</i> that beginswith the <i>Y</i>-th character and which is <i>Z</i> characters long.The left-most character of <i>X</i> is number 1. If <i>Y</i> is negativethe the first character of the substring is found by counting from theright rather than the left. If SQLite is configured to support UTF-8,then characters indices refer to actual UTF-8 characters, not bytes.</td></tr><tr><td valign="top" align="right">typeof(<i>X</i>)</td><td valign="top">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">upper(<i>X</i>)</td><td valign="top">Return a copy of input string <i>X</i> converted to allupper-case letters. The implementation of this function uses the C libraryroutine <b>toupper()</b> which means it may not work correctly on UTF-8 strings.</td></tr></table><p>The following aggregate functions are available by default. Additionalaggregate functions written in C may be added using the <a href="capi3ref.html#sqlite3_create_function">sqlite3_create_function()</a>API.</p><table border=0 cellpadding=10><tr><td valign="top" align="right" width=120>avg(<i>X</i>)</td><td valign="top">Return the average value of all <i>X</i> within a group.</td></tr><tr><td valign="top" align="right">count(<i>X</i>)<br>count(*)</td><td valign="top">The first form return a count of the number of timesthat <i>X</i> is not NULL in a group. The second form (with no argument)returns the total number of rows in the group.</td></tr><tr><td valign="top" align="right">max(<i>X</i>)</td><td valign="top">Return the maximum value of all values in the group.The usual sort order is used to determine the maximum.</td></tr><tr><td valign="top" align="right">min(<i>X</i>)</td><td valign="top">Return the minimum non-NULL value of all values in the group.The usual sort order is used to determine the minimum. NULL is only returnedif all values in the group are NULL.</td></tr><tr><td valign="top" align="right">sum(<i>X</i>)</td><td valign="top">Return the numeric sum of all values in the group.</td></tr></table>}Section INSERT insertSyntax {sql-statement} {INSERT [OR <conflict-algorithm>] INTO [<database-name> .] <table-name> [(<column-list>)] VALUES(<value-list>) |INSERT [OR <conflict-algorithm>] INTO [<database-name> .] <table-name> [(<column-list>)] <select-statement>}puts {<p>The INSERT statement comes in two basic forms. The first form(with the "VALUES" keyword) creates a single new row in an existing table.If no column-list is specified then the number of values mustbe the same as the number of columns in the table. If a column-listis specified, then the number of values must match the number ofspecified columns. Columns of the table that do not appear in thecolumn list are filled with the default value, or with NULL if notdefault value is specified.</p><p>The second form of the INSERT statement takes it data from aSELECT statement. The number of columns in the result of theSELECT must exactly match the number of columns in the table ifno column list is specified, or it must match the number of columnsname in the column list. A new entry is made in the tablefor every row of the SELECT result. The SELECT may be simpleor compound. If the SELECT statement has an ORDER BY clause,the ORDER BY is ignored.</p><p>The optional conflict-clause allows the specification of an alternativeconstraint conflict resolution algorithm to use during this one command.See the section titled<a href="#conflict">ON CONFLICT</a> for additional information.For compatibility with MySQL, the parser allows the use of thesingle keyword <a href="#replace">REPLACE</a> as an alias for "INSERT OR REPLACE".</p>}Section {ON CONFLICT clause} conflictSyntax {conflict-clause} {ON CONFLICT <conflict-algorithm>} {conflict-algorithm} {ROLLBACK | ABORT | FAIL | IGNORE | REPLACE}puts {<p>The ON CONFLICT clause is not a separate SQL command. It is anon-standard clause that can appear in many other SQL commands.It is given its own section in this document because it is notpart of standard SQL and therefore might not be familiar.</p><p>The syntax for the ON CONFLICT clause is as shown above forthe CREATE TABLE and CREATE INDEX commands. For the COPY, INSERT, andUPDATE commands, the keywords "ON CONFLICT" are replaced by "OR", to makethe syntax seem more natural. But the meaning of the clause is the sameeither way.</p><p>The ON CONFLICT clause specifies an algorithm used to resolveconstraint conflicts. There are five choices: ROLLBACK, ABORT,FAIL, IGNORE, and REPLACE. The default algorithm is ABORT. Thisis what they mean:</p><dl><dt><b>ROLLBACK</b></dt><dd><p>When a constraint violation occurs, an immediate ROLLBACKoccurs, thus ending the current transaction, and the command abortswith a return code of SQLITE_CONSTRAINT. If no transaction isactive (other than the implied transaction that is created on everycommand) then this algorithm works the same as ABORT.</p></dd><dt><b>ABORT</b></dt><dd><p>When a constraint violation occurs, the command backs outany prior changes it might have made and aborts with a return codeof SQLITE_CONSTRAINT. But no ROLLBACK is executed so changesfrom prior commands within the same transactionare preserved. This is the default behavior.</p></dd><dt><b>FAIL</b></dt><dd><p>When a constraint violation occurs, the command aborts with areturn code SQLITE_CONSTRAINT. But any changes to the database thatthe command made prior to encountering the constraint violationare preserved and are not backed out. For example, if an UPDATEstatement encountered a constraint violation on the 100th row thatit attempts to update, then the first 99 row changes are preservedbut changes to rows 100 and beyond never occur.</p></dd><dt><b>IGNORE</b></dt><dd><p>When a constraint violation occurs, the one row that containsthe constraint violation is not inserted or changed. But the commandcontinues executing normally. Other rows before and after the row thatcontained the constraint violation continue to be inserted or updatednormally. No error is returned.</p></dd><dt><b>REPLACE</b></dt><dd><p>When a UNIQUE constraint violation occurs, the pre-existing rowsthat are causing the constraint violation are removed prior to insertingor updating the current row. Thus the insert or update always occurs.The command continues executing normally. No error is returned.If a NOT NULL constraint violation occurs, the NULL value is replacedby the default value for that column. If the column has no defaultvalue, then the ABORT algorithm is used.</p><p>When this conflict resolution strategy deletes rows in order tosatisfy a constraint, it does not invoke delete triggers on thoserows. But that may change in a future release.</p></dl><p>The algorithm specified in the OR clause of a COPY, INSERT, or UPDATEoverrides any algorithm specified in a CREATE TABLE or CREATE INDEX.If no algorithm is specified anywhere, the ABORT algorithm is used.</p>}# <p>For additional information, see # <a href="conflict.html">conflict.html</a>.</p>Section REINDEX reindexSyntax {sql-statement} { REINDEX <collation name>}Syntax {sql-statement} { REINDEX [<database-name> .] <table/index-name>}puts {<p>The REINDEX command is used to delete and recreate indices from scratch.This is primarily useful when the definition of a collation sequence has changed.</p><p>In the first form, all indices in all attached databases that use thenamed collation sequence are recreated. In the second form, if <i>[database-name.]table/index-name</i> identifies a table, then all indicesassociated with the table are rebuilt. If an index is identified, then onlythis specific index is deleted and recreated.</p><p>If no <i>database-name</i> is specified and there exists both a table orindex and a collation sequence of the specified name, then indices associatedwith the collation sequence only are reconstructed. This ambiguity may bedispelled by always specifying a <i>database-name</i> when reindexing aspecific table or index.}Section REPLACE replaceSyntax {sql-statement} {REPLACE INTO [<database-name> .] <table-name> [( <column-list> )] VALUES ( <value-list> ) |REPLACE INTO [<database-name> .] <table-name> [( <column-list> )] <select-statement>}puts {<p>The REPLACE command is an alias for the "INSERT OR REPLACE" variantof the <a href="#insert">INSERT</a> command. This alias is provided forcompatibility with MySQL. See the <a href="#insert">INSERT</a> command documentation for additionalinformation.</p> }Section SELECT selectSyntax {sql-statement} {SELECT [ALL | DISTINCT] <result> [FROM <table-list>]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -