📄 lang.tcl
字号:
<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 pseudo-random integerbetween -9223372036854775808 and +9223372036854775807.</td></tr><tr><td valign="top" align="right"><a name="replaceFunc">replace(<i>X</i>,<i>Y</i>,<i>Z</i>)</td><td valign="top">Return a string formed by substituting string <i>Z</i> forevery occurrance of string <i>Y</i> in string <i>X</i>. The BINARYcollating sequence is used for comparisons.</td></tr><tr><td valign="top" align="right"><a name="randomblobFunc">randomblob(<i>N</i>)</td><td valign="top">Return a <i>N</i>-byte blob containing pseudo-random bytes.<i>N</i> should be a postive integer.</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"><a name="rtrimFunc">rtrim(<i>X</i>)<br>rtrim(<i>X</i>,<i>Y</i>)</td><td valign="top">Return a string formed by removing any and allcharacters 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">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 <i>X</i> is stringthen 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"><a name="trimFunc">trim(<i>X</i>)<br>trim(<i>X</i>,<i>Y</i>)</td><td valign="top">Return a string formed by removing any and allcharacters 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">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><tr><td valign="top" align="right">zeroblob(<i>N</i>)</td><td valign="top"><a name="zeroblob">Return a BLOB consisting of N bytes of 0x00. SQLitemanages these zeroblobs very efficiently. Zeroblobs can be used toreserve space for a BLOB that is later written using <a href="capi3ref.html#sqlite3_blob_open">incremental BLOB I/O</a>.</td></tr></table><b>Date And Time Functions</b><p>Date and time functions are documented in the <a href="http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions">SQLite Wiki</a>.</p><a name="aggregatefunctions"></a><b>Aggregate Functions</b><p>The aggregate functions shown below 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><p>In any aggregate function that takes a single argument, that argumentcan be preceeded by the keyword DISTINCT. In such cases, duplicateelements are filtered before being passed into the aggregate function.For example, the function "count(distinct X)" will return the numberof distinct values of column X instead of the total number of non-nullvalues in column X.</p><table border=0 cellpadding=10 class="pdf_functions"><tr><td valign="top" align="right" width=120>avg(<i>X</i>)</td><td valign="top">Return the average value of all non-NULL <i>X</i> within agroup. String and BLOB values that do not look like numbers areinterpreted as 0.The result of avg() is always a floating point value even if allinputs are integers. </p></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>)<br>total(<i>X</i>)</td><td valign="top">Return the numeric sum of all non-NULL values in the group. If there are no non-NULL input rows then sum() returns NULL but total() returns 0.0. NULL is not normally a helpful result for the sum of no rows but the SQL standard requires it and most other SQL database engines implement sum() that way so SQLite does it in the same way in order to be compatible. The non-standard total() function is provided as a convenient way to work around this design problem in the SQL language.</p> <p>The result of total() is always a floating point value. The result of sum() is an integer value if all non-NULL inputs are integers. If any input to sum() is neither an integer or a NULL then sum() returns a floating point value which might be an approximation to the true sum.</p> <p>Sum() will throw an "integer overflow" exception if all inputs are integers or NULL and an integer overflow occurs at any point during the computation. Total() never throws an exception.</p></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.</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 command. For the INSERT andUPDATE commands, the keywords "ON CONFLICT" are replaced by "OR", to makethe syntax seem more natural. For example, instead of"INSERT ON CONFLICT IGNORE" we have "INSERT OR IGNORE".The keywords change 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. If a CHECK constraint violationoccurs then the IGNORE 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. This behavior might change in a future release.</p></dl><p>The algorithm specified in the OR clause of a INSERT or UPDATEoverrides any algorithm specified in a CREATE TABLE.If no algorithm is specified anywhere, the ABORT algorithm is used.</p>}Section REINDEX reindexSyntax {sql-statement} { REINDEX <collation name>}Syntax {sql-sta
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -