📄 lang.tcl
字号:
ROLLBACK) and the current query terminates. An error code of SQLITE_CONSTRAINT is returned to the user, along with the specified error message.</p><p>When RAISE(IGNORE) is called, the remainder of the current trigger program,the statement that caused the trigger program to execute and any subsequent trigger programs that would of been executed are abandoned. No database changes are rolled back. If the statement that caused the trigger program to execute is itself part of a trigger program, then that trigger program resumes execution at the beginning of the next step.</p><p>Triggers are removed using the <a href="#droptrigger">DROP TRIGGER</a>statement. Non-temporary triggers cannot be added on a table in an attached database.</p>}Section {CREATE VIEW} {createview}Syntax {sql-command} {CREATE [TEMP | TEMPORARY] VIEW [<database-name>.] <view-name> AS <select-statement>}puts {<p>The CREATE VIEW command assigns a name to a pre-packaged <a href="#select">SELECT</a>statement. Once the view is created, it can be used in the FROM clauseof another SELECT in place of a table name.</p><p>If the "TEMP" or "TEMPORARY" keyword occurs in between "CREATE"and "TABLE" then the table that is created is only visible to theprocess that opened the database and is automatically deleted whenthe database is closed.</p><p> If a <database-name> is specified, then the view is created in the named database. It is an error to specify both a <database-name>and the TEMP keyword, unless the <database-name> is "temp". If nodatabase name is specified, and the TEMP keyword is not present,the table is created in the main database.</p><p>You cannot COPY, DELETE, INSERT or UPDATE a view. Views are read-only in SQLite. However, in many cases you can use a <a href="#createtrigger">TRIGGER</a> on the view to accomplish the same thing. Views are removed with the <a href="#dropview">DROP VIEW</a> command. Non-temporary views cannot be created on tables in an attached database.</p>}Section DELETE deleteSyntax {sql-statement} {DELETE FROM [<database-name> .] <table-name> [WHERE <expr>]}puts {<p>The DELETE command is used to remove records from a table.The command consists of the "DELETE FROM" keywords followed bythe name of the table from which records are to be removed.</p><p>Without a WHERE clause, all rows of the table are removed.If a WHERE clause is supplied, then only those rows that matchthe expression are removed.</p>}Section {DETACH DATABASE} detachSyntax {sql-command} {DETACH [DATABASE] <database-name>}puts {<p>This statement detaches an additional database connection previously attached using the <a href="#attach">ATTACH DATABASE</a> statement. Itis possible to have the same database file attached multiple times using different names, and detaching one connection to a file will leave the others intact.</p><p>This statement will fail if SQLite is in the middle of a transaction.</p>}Section {DROP INDEX} dropindexSyntax {sql-command} {DROP INDEX [<database-name> .] <index-name>}puts {<p>The DROP INDEX statement removes an index addedwith the <a href="#createindex">CREATE INDEX</a> statement. The index named is completely removed fromthe disk. The only way to recover the index is to reenter theappropriate CREATE INDEX command.</p><p>The DROP INDEX statement does not reduce the size of the database file. Empty space in the database is retained for later INSERTs. To remove free space in the database, use the <a href="#vacuum">VACUUM</a> command.</p>}Section {DROP TABLE} droptableSyntax {sql-command} {DROP TABLE [<database-name>.] <table-name>}puts {<p>The DROP TABLE statement removes a table added with the <a href="#createtable">CREATE TABLE</a> statement. The name specified is thetable name. It is completely removed from the database schema and the disk file. The table can not be recovered. All indices associated with the table are also deleted. Non-temporary tables in an attached database cannot be dropped.</p><p>The DROP TABLE statement does not reduce the size of the database file. Empty space in the database is retained for later INSERTs. To remove free space in the database, use the <a href="#vacuum">VACUUM</a> command.</p>}Section {DROP TRIGGER} droptriggerSyntax {sql-statement} {DROP TRIGGER [<database-name> .] <trigger-name>}puts { <p>The DROP TRIGGER statement removes a trigger created by the <a href="#createtrigger">CREATE TRIGGER</a> statement. The trigger is deleted from the database schema. Note that triggers are automatically dropped when the associated table is dropped. Non-temporary triggers cannot be dropped on attached tables.</p>}Section {DROP VIEW} dropviewSyntax {sql-command} {DROP VIEW <view-name>}puts {<p>The DROP VIEW statement removes a view created by the <a href="#createview">CREATE VIEW</a> statement. The name specified is the view name. It is removed from the database schema, but no actual data in the underlying base tables is modified. Non-temporary views in attached databases cannot be dropped.</p>}Section EXPLAIN explainSyntax {sql-statement} {EXPLAIN <sql-statement>}puts {<p>The EXPLAIN command modifier is a non-standard extension. Theidea comes from a similar command found in PostgreSQL, but the operationis completely different.</p><p>If the EXPLAIN keyword appears before any other SQLite SQL commandthen instead of actually executing the command, the SQLite library willreport back the sequence of virtual machine instructions it would haveused to execute the command had the EXPLAIN keyword not been present.For additional information about virtual machine instructions seethe <a href="arch.html">architecture description</a> or the documentationon <a href="opcode.html">available opcodes</a> for the virtual machine.</p>}Section expression exprSyntax {expr} {<expr> <binary-op> <expr> |<expr> <like-op> <expr> [ESCAPE <expr>] |<expr> <glob-op> <expr> |<unary-op> <expr> |( <expr> ) |<column-name> |<table-name> . <column-name> |<database-name> . <table-name> . <column-name> |<literal-value> |<function-name> ( <expr-list> | STAR ) |<expr> ISNULL |<expr> NOTNULL |<expr> [NOT] BETWEEN <expr> AND <expr> |<expr> [NOT] IN ( <value-list> ) |<expr> [NOT] IN ( <select-statement> ) |<expr> [NOT] IN [<database-name> .] <table-name> |[EXISTS] ( <select-statement> ) |CASE [<expr>] LP WHEN <expr> THEN <expr> RPPLUS [ELSE <expr>] END} {like-op} {LIKE | NOT LIKE} {glob-op} {GLOB | NOT GLOB}puts {<p>This section is different from the others. Most other sections ofthis document talks about a particular SQL command. This section doesnot talk about a standalone command but about "expressions" which are subcomponents of most other commands.</p><p>SQLite understands the following binary operators, in order fromhighest to lowest precedence:</p><blockquote><pre><font color="#2c2cf0"><big>||* / %+ -<< >> & |< <= > >== == != <> </big>INAND OR</font></pre></blockquote><p>Supported unary operators are these:</p><blockquote><pre><font color="#2c2cf0"><big>- + ! ~</big></font></pre></blockquote><p>Any SQLite value can be used as part of an expression. For arithmetic operations, integers are treated as integers.Strings are first converted to real numbers using <b>atof()</b>.For comparison operators, numbers compare as numbers and stringscompare using the <b>strcmp()</b> function.Note that there are two variations of the equals and not equalsoperators. Equals can be either}puts "[Operator =] or [Operator ==].The non-equals operator can be either[Operator !=] or [Operator {<>}].The [Operator ||] operator is \"concatenate\" - it joins togetherthe two strings of its operands.The operator [Operator %] outputs the remainder of its left operand modulo its right operand.</p>"puts {<a name="like"></a><p>The LIKE operator does a pattern matching comparison. The operandto the right contains the pattern, the left hand operand contains thestring to match against the pattern. }puts "A percent symbol [Operator %] in the pattern matches anysequence of zero or more characters in the string. An underscore[Operator _] in the pattern matches any single character in thestring. Any other character matches itself or it's lower/upper caseequivalent (i.e. case-insensitive matching). (A bug: SQLite onlyunderstands upper/lower case for 7-bit Latin characters. Hence theLIKE operator is case sensitive for 8-bit iso8859 characters or UTF-8characters. For example, the expression <b>'a' LIKE 'A'</b>is TRUE but <b>'æ' LIKE 'Æ'</b> is FALSE.).</p>"puts {<p>If the optional ESCAPE clause is present, then the expressionfollowing the ESCAPE keyword must evaluate to a string consisting ofa single character. This character may be used in the LIKE patternto include literal percent or underscore characters. The escapecharacter followed by a percent symbol, underscore or itself matches aliteral percent symbol, underscore or escape character in the string,respectively. The infix LIKE operator is implemented by calling theuser function <a href="#likeFunc"> like(<i>X</i>,<i>Y</i>)</a>.</p>}puts {<p>The LIKE operator does a wildcard comparison. The operandto the right contains the wildcards.}puts "A percent symbol [Operator %] in the right operandmatches any sequence of zero or more characters on the left.An underscore [Operator _] on the rightmatches any single character on the left."puts {The LIKE operator is not case sensitive and will match upper casecharacters on one side against lower case characters on the other. (A bug: SQLite only understands upper/lower case for 7-bit Latincharacters. Hence the LIKE operator is case sensitive for 8-bitiso8859 characters or UTF-8 characters. For example, the expression<b>'a' LIKE 'A'</b> is TRUE but<b>'æ' LIKE 'Æ'</b> is FALSE.). The infix LIKEoperator is identical the user function <a href="#likeFunc">like(<i>X</i>,<i>Y</i>)</a>.</p><a name="glob"></a><p>The GLOB operator is similar to LIKE but uses the Unixfile globbing syntax for its wildcards. Also, GLOB is casesensitive, unlike LIKE. Both GLOB and LIKE may be preceded bythe NOT keyword to invert the sense of the test. The infix GLOB operator is identical the user function <a href="#globFunc">glob(<i>X</i>,<i>Y</i>)</a>.</p><p>A column name can be any of the names defined in the CREATE TABLEstatement or one of the following special identifiers: "<b>ROWID</b>","<b>OID</b>", or "<b>_ROWID_</b>".These special identifiers all describe theunique random integer key (the "row key") associated with every row of every table.The special identifiers only refer to the row key if the CREATE TABLEstatement does not define a real column with the same name. Row keysact like read-only columns. A row key can be used anywhere a regularcolumn can be used, except that you cannot change the valueof a row key in an UPDATE or INSERT statement."SELECT * ..." does not return the row key.</p><p>SELECT statements can appear in expressions as either theright-hand operand of the IN operator, as a scalar quantity, oras the operand of an EXISTS operator.As a scalar quantity or the operand of an IN operator,the SELECT should have only a single column in itsresult. Compound SELECTs (connected with keywords like UNION orEXCEPT) are allowed.With the EXISTS operator, the columns in the result set of the SELECT areignored and the expression returns TRUE if one or more rows existand FALSE if the result set is empty.If no terms in the SELECT expression refer to value in the containingquery, then the expression is evaluated once prior to any otherprocessing and the result is reused as necessary. If the SELECT expressiondoes contain variables from the outer query, then the SELECT is reevaluatedevery time it is needed.</p><p>When a SELECT is the right operand of the IN operator, the INoperator returns TRUE if the result of the left operand is any ofthe values generated by the select. The IN operator may be precededby the NOT keyword to invert the sense of the test.</p><p>When a SELECT appears within an expression but is not the rightoperand of an IN operator, then the first row of the result of theSELECT becomes the value used in the expression. If the SELECT yieldsmore than one result row, all rows after the first are ignored. Ifthe SELECT yields no rows, then the value of the SELECT is NULL.</p><p>Both simple and aggregate functions are supported. A simplefunction can be used in any expression. Simple functions returna result immediately based on their inputs. Aggregate functionsmay only be used in a SELECT statement. Aggregate functions computetheir result across all rows of the result set.</p><p>The functions shown below are available by default. Additionalfunctions may be written in C and added to the database engine usingthe <a href="capi3ref.html#cfunc">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">Return the absolute value of argument <i>X</i>.</td></tr><tr><td valign="top" align="right">coalesce(<i>X</i>,<i>Y</i>,...)</td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -