Debian Codegraph @

www/lang_corefunc.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>Built-In Scalar SQL Functions</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 Built-In Scalar SQL Functions
122 </div>
123 </div>
124
125
126
127
128
129 <h1 id="overview"><span>1. </span>Overview</h1>
130
131 <p>The core functions shown below are available by default.
132 <a href="lang_datefunc.html">Date &amp; Time functions</a>,
133 <a href="lang_aggfunc.html">aggregate functions</a>,
134 <a href="windowfunctions.html">window functions</a>,
135 <a href="lang_mathfunc.html">math functions</a>, and
136 <a href="json1.html">JSON functions</a> are documented separately. An
137 application may define additional
138 functions written in C and added to the database engine using
139 the <a href="c3ref/create_function.html">sqlite3_create_function()</a> API.</p>
140
141 <p><b><a href="syntax/simple-function-invocation.html">simple-function-invocation:</a></b></p><div class='imgcontainer'>
142 <div style="max-width:414px"><svg xmlns='http://www.w3.org/2000/svg' class="pikchr" viewBox="0 0 414.49 126.792">
143 <circle cx="5" cy="55" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
144 <polygon points="32,55 20,59 20,50" style="fill:rgb(0,0,0)"/>
145 <path d="M9,55L26,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
146 <path d="M47,70L126,70A15 15 0 0 0 141 55A15 15 0 0 0 126 39L47,39A15 15 0 0 0 32 55A15 15 0 0 0 47 70Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
147 <text x="86" y="55" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">simple-func</text>
148 <polygon points="164,55 152,59 152,50" style="fill:rgb(0,0,0)"/>
149 <path d="M141,55L158,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
150 <path d="M179,70A15 15 0 0 0 194 55A15 15 0 0 0 179 39A15 15 0 0 0 164 55A15 15 0 0 0 179 70Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
151 <text x="179" y="55" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">(</text>
152 <polygon points="248,55 237,59 237,50" style="fill:rgb(0,0,0)"/>
153 <path d="M194,55L242,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
154 <path d="M248,70L297,70L297,39L248,39Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
155 <text x="273" y="55" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">expr</text>
156 <polygon points="351,55 340,59 340,50" style="fill:rgb(0,0,0)"/>
157 <path d="M297,55L346,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
158 <path d="M366,70A15 15 0 0 0 382 55A15 15 0 0 0 366 39A15 15 0 0 0 351 55A15 15 0 0 0 366 70Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
159 <text x="366" y="55" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">)</text>
160 <polygon points="405,55 393,59 393,50" style="fill:rgb(0,0,0)"/>
161 <path d="M382,55L399,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
162 <circle cx="408" cy="55" r="3.6" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
163 <path d="M273,32A15 15 0 0 0 288 17L288,17A15 15 0 0 0 273 2A15 15 0 0 0 258 17L258,17A15 15 0 0 0 273 32Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
164 <text x="273" y="17" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">,</text>
165 <polygon points="288,17 299,12 299,21" style="fill:rgb(0,0,0)"/>
166 <path d="M297,55 L 305,55 Q 312,55 312,40 L 312,32 Q 312,17 303,17 L 294,17" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
167 <path d="M258,17 L 237,17 Q 222,17 222,32 L 222,40 Q 222,55 229,55 L 237,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
168 <polygon points="273,82 261,86 261,77" style="fill:rgb(0,0,0)"/>
169 <path d="M194,55 L 202,55 Q 209,55 209,68 Q 209,82 224,82 L 252,82 L 267,82" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
170 <path d="M273,82 L 310,82 Q 325,82 325,68 Q 325,55 332,55 L 340,55" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
171 <path d="M273,124A15 15 0 0 0 288 109A15 15 0 0 0 273 94A15 15 0 0 0 258 109A15 15 0 0 0 273 124Z" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
172 <text x="273" y="109" text-anchor="middle" font-weight="bold" fill="rgb(0,0,0)" dominant-baseline="central">*</text>
173 <polygon points="258,109 246,113 246,105" style="fill:rgb(0,0,0)"/>
174 <path d="M194,55 L 202,55 Q 209,55 209,70 L 209,94 Q 209,109 224,109 L 237,109 L 252,109" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
175 <path d="M288,109 L 310,109 Q 325,109 325,94 L 325,85 L 325,70" style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
176 </svg>
177 </div>
178 </div>
179
180
181 <p>
182 See the <a href="lang_expr.html#*funcinexpr">functions within expressions</a> documentation for
183 more information about how SQL function invocations fit into the context
184 of an SQL expression.
185
186 </p><h1 id="list_of_core_functions"><span>2. </span>List Of Core Functions</h1>
187
188 <p>
189 <div class='columns' style='columns: 15em auto;'>
190 <ul style='padding-top:0;'>
191 <li><a href='lang_corefunc.html#abs'>abs(X)</a></li>
192 <li><a href='lang_corefunc.html#changes'>changes()</a></li>
193 <li><a href='lang_corefunc.html#char'>char(X1,X2,...,XN)</a></li>
194 <li><a href='lang_corefunc.html#coalesce'>coalesce(X,Y,...)</a></li>
195 <li><a href='lang_corefunc.html#concat'>concat(X,...)</a></li>
196 <li><a href='lang_corefunc.html#concat_ws'>concat_ws(SEP,X,...)</a></li>
197 <li><a href='lang_corefunc.html#format'>format(FORMAT,...)</a></li>
198 <li><a href='lang_corefunc.html#glob'>glob(X,Y)</a></li>
199 <li><a href='lang_corefunc.html#hex'>hex(X)</a></li>
200 <li><a href='lang_corefunc.html#ifnull'>ifnull(X,Y)</a></li>
201 <li><a href='lang_corefunc.html#iif'>iif(X,Y,Z)</a></li>
202 <li><a href='lang_corefunc.html#instr'>instr(X,Y)</a></li>
203 <li><a href='lang_corefunc.html#last_insert_rowid'>last_insert_rowid()</a></li>
204 <li><a href='lang_corefunc.html#length'>length(X)</a></li>
205 <li><a href='lang_corefunc.html#like'>like(X,Y)</a></li>
206 <li><a href='lang_corefunc.html#like'>like(X,Y,Z)</a></li>
207 <li><a href='lang_corefunc.html#likelihood'>likelihood(X,Y)</a></li>
208 <li><a href='lang_corefunc.html#likely'>likely(X)</a></li>
209 <li><a href='lang_corefunc.html#load_extension'>load_extension(X)</a></li>
210 <li><a href='lang_corefunc.html#load_extension'>load_extension(X,Y)</a></li>
211 <li><a href='lang_corefunc.html#lower'>lower(X)</a></li>
212 <li><a href='lang_corefunc.html#ltrim'>ltrim(X)</a></li>
213 <li><a href='lang_corefunc.html#ltrim'>ltrim(X,Y)</a></li>
214 <li><a href='lang_corefunc.html#max_scalar'>max(X,Y,...)</a></li>
215 <li><a href='lang_corefunc.html#min_scalar'>min(X,Y,...)</a></li>
216 <li><a href='lang_corefunc.html#nullif'>nullif(X,Y)</a></li>
217 <li><a href='lang_corefunc.html#octet_length'>octet_length(X)</a></li>
218 <li><a href='lang_corefunc.html#printf'>printf(FORMAT,...)</a></li>
219 <li><a href='lang_corefunc.html#quote'>quote(X)</a></li>
220 <li><a href='lang_corefunc.html#random'>random()</a></li>
221 <li><a href='lang_corefunc.html#randomblob'>randomblob(N)</a></li>
222 <li><a href='lang_corefunc.html#replace'>replace(X,Y,Z)</a></li>
223 <li><a href='lang_corefunc.html#round'>round(X)</a></li>
224 <li><a href='lang_corefunc.html#round'>round(X,Y)</a></li>
225 <li><a href='lang_corefunc.html#rtrim'>rtrim(X)</a></li>
226 <li><a href='lang_corefunc.html#rtrim'>rtrim(X,Y)</a></li>
227 <li><a href='lang_corefunc.html#sign'>sign(X)</a></li>
228 <li><a href='lang_corefunc.html#soundex'>soundex(X)</a></li>
229 <li><a href='lang_corefunc.html#sqlite_compileoption_get'>sqlite_compileoption_get(N)</a></li>
230 <li><a href='lang_corefunc.html#sqlite_compileoption_used'>sqlite_compileoption_used(X)</a></li>
231 <li><a href='lang_corefunc.html#sqlite_offset'>sqlite_offset(X)</a></li>
232 <li><a href='lang_corefunc.html#sqlite_source_id'>sqlite_source_id()</a></li>
233 <li><a href='lang_corefunc.html#sqlite_version'>sqlite_version()</a></li>
234 <li><a href='lang_corefunc.html#substr'>substr(X,Y)</a></li>
235 <li><a href='lang_corefunc.html#substr'>substr(X,Y,Z)</a></li>
236 <li><a href='lang_corefunc.html#substr'>substring(X,Y)</a></li>
237 <li><a href='lang_corefunc.html#substr'>substring(X,Y,Z)</a></li>
238 <li><a href='lang_corefunc.html#total_changes'>total_changes()</a></li>
239 <li><a href='lang_corefunc.html#trim'>trim(X)</a></li>
240 <li><a href='lang_corefunc.html#trim'>trim(X,Y)</a></li>
241 <li><a href='lang_corefunc.html#typeof'>typeof(X)</a></li>
242 <li><a href='lang_corefunc.html#unhex'>unhex(X)</a></li>
243 <li><a href='lang_corefunc.html#unhex'>unhex(X,Y)</a></li>
244 <li><a href='lang_corefunc.html#unicode'>unicode(X)</a></li>
245 <li><a href='lang_corefunc.html#unlikely'>unlikely(X)</a></li>
246 <li><a href='lang_corefunc.html#upper'>upper(X)</a></li>
247 <li><a href='lang_corefunc.html#zeroblob'>zeroblob(N)</a></li>
248 </ul>
249 </div>
250
251
252 <h1 id="descriptions_of_built_in_scalar_sql_functions"><span>3. </span>Descriptions of built-in scalar SQL functions</h1>
253 <dl>
254
255 <a name="abs"></a>
256 <dt><p><b>abs(<i>X</i>)</b></dt><dd><p>
257 The abs(X) function returns the absolute value of the numeric
258 argument X. Abs(X) returns NULL if X is NULL.
259 Abs(X) returns 0.0 if X is a string or blob
260 that cannot be converted to a numeric value. If X is the
261 integer -9223372036854775808 then abs(X) throws an integer overflow
262 error since there is no equivalent positive 64-bit two complement value.
263 </dd>
264 <a name="changes"></a>
265 <dt><p><b>changes()</b></dt><dd><p>
266 The changes() function returns the number of database rows that were changed
267 or inserted or deleted by the most recently completed INSERT, DELETE,
268 or UPDATE statement, exclusive of statements in lower-level triggers.
269 The changes() SQL function is a wrapper around the <a href="c3ref/changes.html">sqlite3_changes64()</a>
270 C/C++ function and hence follows the same rules for counting changes.
271 </dd>
272 <a name="char"></a>
273 <dt><p><b>char(<i>X1</i>,<i>X2</i>,...,<i>XN</i>)</b></dt><dd><p>
274 The char(X1,X2,...,XN) function returns a string composed of characters having the
275 unicode code point values of integers X1 through XN, respectively.
276 </dd>
277 <a name="coalesce"></a>
278 <dt><p><b>coalesce(<i>X</i>,<i>Y</i>,...)</b></dt><dd><p>
279 The coalesce() function returns a copy of its first non-NULL argument, or
280 NULL if all arguments are NULL. Coalesce() must have at least
281 2 arguments.
282 </dd>
283 <a name="concat"></a>
284 <dt><p><b>concat(<i>X</i>,...)</b></dt><dd><p>
285 The concat(...) function returns a string which is the concatenation of the
286 string representation of all of its non-NULL arguments. If all arguments are
287 NULL, then concat() returns an empty string.
288 </dd>
289 <a name="concat_ws"></a>
290 <dt><p><b>concat_ws(<i>SEP</i>,<i>X</i>,...)</b></dt><dd><p>
291 The concat_ws(SEP,...) function returns a string that is the concatenation of
292 all non-null arguments beyond the first argument, using the text value of the
293 first argument as a separator. If the first argument is NULL, then concat_ws()
294 returns NULL. If all arguments other than the first are NULL, then concat_ws()
295 returns an empty string.
296 </dd>
297 <a name="format"></a>
298 <dt><p><b>format(<i>FORMAT</i>,...)</b></dt><dd><p>
299 The format(FORMAT,...) SQL function works like the <a href="c3ref/mprintf.html">sqlite3_mprintf()</a> C-language
300 function and the printf() function from the standard C library.
301 The first argument is a format string that specifies how to construct the output
302 string using values taken from subsequent arguments. If the FORMAT argument is
303 missing or NULL then the result is NULL. The %n format is silently ignored and
304 does not consume an argument. The %p format is an alias for %X. The %z format
305 is interchangeable with %s. If there are too few arguments in the argument list,
306 missing arguments are assumed to have a NULL value, which is translated into
307 0 or 0.0 for numeric formats or an empty string for %s. See the
308 <a href="printf.html">built-in printf()</a> documentation for additional information.
309 </dd>
310 <a name="glob"></a>
311 <dt><p><b>glob(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
312 The glob(X,Y) function is equivalent to the
313 expression "<b>Y GLOB X</b>".
314 Note that the X and Y arguments are reversed in the glob() function
315 relative to the infix <a href="lang_expr.html#glob">GLOB</a> operator. Y is the string and X is the
316 pattern. So, for example, the following expressions are equivalent:
317 <blockquote><pre>
318 name GLOB '*helium*'
319 glob('*helium*',name)
320 </pre></blockquote>
321 <p>If the <a href="c3ref/create_function.html">sqlite3_create_function()</a> interface is used to
322 override the glob(X,Y) function with an alternative implementation then
323 the <a href="lang_expr.html#glob">GLOB</a> operator will invoke the alternative implementation.
324 </dd>
325 <a name="hex"></a>
326 <dt><p><b>hex(<i>X</i>)</b></dt><dd><p>
327 The hex() function interprets its argument as a BLOB and returns
328 a string which is the upper-case hexadecimal rendering of the content of
329 that blob.
330 <p>
331 If the argument <i>X</i> in "hex(<i>X</i>)" is an
332 integer or floating point number, then "interprets its argument as a BLOB" means
333 that the binary number is first converted into a UTF8 text representation, then
334 that text is interpreted as a BLOB. Hence, "hex(12345678)" renders
335 as "3132333435363738" not the binary representation of the integer value
336 "0000000000BC614E".
337 <p>
338 See also: <a href="lang_corefunc.html#unhex">unhex()</a>
339 </dd>
340 <a name="ifnull"></a>
341 <dt><p><b>ifnull(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
342 The ifnull() function returns a copy of its first non-NULL argument, or
343 NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments.
344 The ifnull() function is equivalent to <a href="lang_corefunc.html#coalesce">coalesce()</a> with two arguments.
345 </dd>
346 <a name="iif"></a>
347 <dt><p><b>iif(<i>X</i>,<i>Y</i>,<i>Z</i>)</b></dt><dd><p>
348 The iif(X,Y,Z) function returns the value Y if X is true, and Z otherwise.
349 The iif(X,Y,Z) function is logically equivalent to and generates the same
350 <a href="opcode.html">bytecode</a> as the <a href="lang_expr.html#case">CASE expression</a> "CASE WHEN X THEN Y ELSE Z END".
351 </dd>
352 <a name="instr"></a>
353 <dt><p><b>instr(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
354 The instr(X,Y) function finds the first occurrence of string Y within
355 string X and returns the number of prior characters plus 1, or 0 if
356 Y is nowhere found within X.
357 Or, if X and Y are both BLOBs, then instr(X,Y) returns one
358 more than the number bytes prior to the first occurrence of Y, or 0 if
359 Y does not occur anywhere within X.
360 If both arguments X and Y to instr(X,Y) are non-NULL and are not BLOBs
361 then both are interpreted as strings.
362 If either X or Y are NULL in instr(X,Y) then the result is NULL.
363 </dd>
364 <a name="last_insert_rowid"></a>
365 <dt><p><b>last_insert_rowid()</b></dt><dd><p>
366 The last_insert_rowid() function returns the <a href="lang_createtable.html#rowid">ROWID</a>
367 of the last row insert from the database connection which invoked the
368 function.
369 The last_insert_rowid() SQL function is a wrapper around the
370 <a href="c3ref/last_insert_rowid.html">sqlite3_last_insert_rowid()</a> C/C++ interface function.
371 </dd>
372 <a name="length"></a>
373 <dt><p><b>length(<i>X</i>)</b></dt><dd><p>
374 For a string value X, the length(X) function returns the number of
375 characters (not bytes) in X prior to the first NUL character.
376 Since SQLite strings do not normally contain NUL characters, the length(X)
377 function will usually return the total number of characters in the string X.
378 For a blob value X, length(X) returns the number of bytes in the blob.
379 If X is NULL then length(X) is NULL.
380 If X is numeric then length(X) returns the length of a string
381 representation of X.
382 <p>
383 Note that for strings, the length(X) function returns the <i>character</i>
384 length of the string, not the byte length. The character length is the number
385 of characters in the string. The character length is always different from
386 the byte length for UTF-16 strings, and can be different from the byte length
387 for UTF-8 strings if the string contains multi-byte characters. Use the
388 <a href="lang_corefunc.html#octet_length">octet_length()</a> function to find the byte length of a string.
389 <p>
390 For BLOB values, length(X) always returns the byte-length of the BLOB.
391 <p>
392 For string values, length(X) must read the entire string into memory in order
393 to compute the character length. But for BLOB values, that is not necessary as
394 SQLite knows how many bytes are in the BLOB. Hence, for multi-megabyte values,
395 the length(X) function is usually much faster for BLOBs than for strings, since
396 it does not need to load the value into memory.
397 </dd>
398 <a name="like"></a>
399 <dt><p><b>like(<i>X</i>,<i>Y</i>)<br />like(<i>X</i>,<i>Y</i>,<i>Z</i>)</b></dt><dd><p>
400 The like() function is used to implement the
401 "<b>Y LIKE X &#91;ESCAPE Z&#93;</b>" expression.
402 If the optional ESCAPE clause is present, then the
403 like() function is invoked with three arguments. Otherwise, it is
404 invoked with two arguments only. Note that the X and Y parameters are
405 reversed in the like() function relative to the infix <a href="lang_expr.html#like">LIKE</a> operator.
406 X is the pattern and Y is the string to match against that pattern.
407 Hence, the following expressions are equivalent:
408 <blockquote><pre>
409 name LIKE '%neon%'
410 like('%neon%',name)
411 </pre></blockquote>
412 <p>The <a href="c3ref/create_function.html">sqlite3_create_function()</a> interface can be used to override the
413 like() function and thereby change the operation of the
414 <a href="lang_expr.html#like">LIKE</a> operator. When overriding the like() function, it may be important
415 to override both the two and three argument versions of the like()
416 function. Otherwise, different code may be called to implement the
417 <a href="lang_expr.html#like">LIKE</a> operator depending on whether or not an ESCAPE clause was
418 specified.
419 </dd>
420 <a name="likelihood"></a>
421 <dt><p><b>likelihood(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
422 The likelihood(X,Y) function returns argument X unchanged.
423 The value Y in likelihood(X,Y) must be a floating point constant
424 between 0.0 and 1.0, inclusive.
425 The likelihood(X) function is a no-op that the code generator
426 optimizes away so that it consumes no CPU cycles during run-time
427 (that is, during calls to <a href="c3ref/step.html">sqlite3_step()</a>).
428 The purpose of the likelihood(X,Y) function is to provide a hint
429 to the query planner that the argument X is a boolean that is
430 true with a probability of approximately Y.
431 The <a href="lang_corefunc.html#unlikely">unlikely(X)</a> function is short-hand for likelihood(X,0.0625).
432 The <a href="lang_corefunc.html#likely">likely(X)</a> function is short-hand for likelihood(X,0.9375).
433 </dd>
434 <a name="likely"></a>
435 <dt><p><b>likely(<i>X</i>)</b></dt><dd><p>
436 The likely(X) function returns the argument X unchanged.
437 The likely(X) function is a no-op that the code generator
438 optimizes away so that it consumes no CPU cycles at
439 run-time (that is, during calls to <a href="c3ref/step.html">sqlite3_step()</a>).
440 The purpose of the likely(X) function is to provide a hint
441 to the query planner that the argument X is a boolean value
442 that is usually true. The likely(X) function is equivalent
443 to <a href="lang_corefunc.html#likelihood">likelihood</a>(X,0.9375). See also: <a href="lang_corefunc.html#unlikely">unlikely(X)</a>.
444 </dd>
445 <a name="load_extension"></a>
446 <dt><p><b>load_extension(<i>X</i>)<br />load_extension(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
447 The load_extension(X,Y) function loads <a href="loadext.html">SQLite extensions</a> out of the shared
448 library file named X using the entry point Y. The result of load_extension()
449 is always a NULL. If Y is omitted then the default entry point name is used.
450 The load_extension() function raises an exception if the extension fails to
451 load or initialize correctly.
452
453 <p>The load_extension() function will fail if the extension attempts to
454 modify or delete an SQL function or collating sequence. The
455 extension can add new functions or collating sequences, but cannot
456 modify or delete existing functions or collating sequences because
457 those functions and/or collating sequences might be used elsewhere
458 in the currently running SQL statement. To load an extension that
459 changes or deletes functions or collating sequences, use the
460 <a href="c3ref/load_extension.html">sqlite3_load_extension()</a> C-language API.</p>
461
462 <p>For security reasons, extension loading is disabled by default and must
463 be enabled by a prior call to <a href="c3ref/enable_load_extension.html">sqlite3_enable_load_extension()</a>.</p>
464 </dd>
465 <a name="lower"></a>
466 <dt><p><b>lower(<i>X</i>)</b></dt><dd><p>
467 The lower(X) function returns a copy of string X with all ASCII characters
468 converted to lower case. The default built-in lower() function works
469 for ASCII characters only. To do case conversions on non-ASCII
470 characters, load the ICU extension.
471 </dd>
472 <a name="ltrim"></a>
473 <dt><p><b>ltrim(<i>X</i>)<br />ltrim(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
474 The ltrim(X,Y) function returns a string formed by removing any and all
475 characters that appear in Y from the left side of X.
476 If the Y argument is omitted, ltrim(X) removes spaces from the left side
477 of X.
478 </dd>
479 <a name="max_scalar"></a>
480 <dt><p><b>max(<i>X</i>,<i>Y</i>,...)</b></dt><dd><p>
481 The multi-argument max() function returns the argument with the
482 maximum value, or return NULL if any argument is NULL.
483 The multi-argument max() function searches its arguments from left to right
484 for an argument that defines a collating function and uses that collating
485 function for all string comparisons. If none of the arguments to max()
486 define a collating function, then the BINARY collating function is used.
487 Note that <b>max()</b> is a simple function when
488 it has 2 or more arguments but operates as an
489 <a href="lang_aggfunc.html#max_agg">aggregate function</a> if given only a single argument.
490 </dd>
491 <a name="min_scalar"></a>
492 <dt><p><b>min(<i>X</i>,<i>Y</i>,...)</b></dt><dd><p>
493 The multi-argument min() function returns the argument with the
494 minimum value.
495 The multi-argument min() function searches its arguments from left to right
496 for an argument that defines a collating function and uses that collating
497 function for all string comparisons. If none of the arguments to min()
498 define a collating function, then the BINARY collating function is used.
499 Note that <b>min()</b> is a simple function when
500 it has 2 or more arguments but operates as an
501 <a href="lang_aggfunc.html#min_agg">aggregate function</a> if given
502 only a single argument.
503 </dd>
504 <a name="nullif"></a>
505 <dt><p><b>nullif(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
506 The nullif(X,Y) function returns its first argument if the arguments are
507 different and NULL if the arguments are the same. The nullif(X,Y) function
508 searches its arguments from left to right for an argument that defines a
509 collating function and uses that collating function for all string
510 comparisons. If neither argument to nullif() defines a collating function
511 then the BINARY collating function is used.
512 </dd>
513 <a name="octet_length"></a>
514 <dt><p><b>octet_length(<i>X</i>)</b></dt><dd><p>
515 The octet_length(X) function returns the number of bytes in the encoding
516 of text string X. If X is NULL then octet_length(X) returns NULL. If X is
517 a BLOB value, then octet_length(X) is the same as <a href="lang_corefunc.html#length">length(X)</a>. If X is a
518 numeric value, then octet_length(X) returns the number of bytes in a text
519 rendering of that number.
520 <p>
521 Because octet_length(X) returns the number of bytes in X, not the number
522 of characters, the value returned depends on the database encoding. The
523 octet_length() function can return different answers for the same input string
524 if the database encoding is UTF16 instead of UTF8.
525 <p>
526 If argument X is a table column and the value is of type text or blob,
527 then octet_length(X) avoids reading the content of X from disk, as the byte
528 length can be computed from metadata. Thus, octet_length(X) is efficient
529 even if X is a column containing a multi-megabyte text or blob value.
530 </dd>
531 <a name="printf"></a>
532 <dt><p><b>printf(<i>FORMAT</i>,...)</b></dt><dd><p>
533 The printf() SQL function is an alias for the <a href="lang_corefunc.html#format">format() SQL function</a>.
534 The format() SQL function was originally named printf(). But the name was
535 later changed to format() for compatibility with other database engines.
536 The printf() name is retained as an alias so as not to break legacy code.
537 </dd>
538 <a name="quote"></a>
539 <dt><p><b>quote(<i>X</i>)</b></dt><dd><p>
540 The quote(X) function returns the text of an SQL literal which
541 is the value of its argument suitable for inclusion into an SQL statement.
542 Strings are surrounded by single-quotes with escapes on interior quotes
543 as needed. BLOBs are encoded as hexadecimal literals.
544 Strings with embedded NUL characters cannot be represented as string
545 literals in SQL and hence the returned string literal is truncated prior
546 to the first NUL.
547 </dd>
548 <a name="random"></a>
549 <dt><p><b>random()</b></dt><dd><p>
550 The random() function returns a pseudo-random integer
551 between -9223372036854775808 and +9223372036854775807.
552 </dd>
553 <a name="randomblob"></a>
554 <dt><p><b>randomblob(<i>N</i>)</b></dt><dd><p>
555 The randomblob(N) function return an N-byte blob containing pseudo-random
556 bytes. If N is less than 1 then a 1-byte random blob is returned.
557
558 <p>Hint: applications can generate globally unique identifiers
559 using this function together with <a href="lang_corefunc.html#hex">hex()</a> and/or
560 <a href="lang_corefunc.html#lower">lower()</a> like this:</p>
561
562 <blockquote>
563 hex(randomblob(16))<br></br>
564 lower(hex(randomblob(16)))
565 </blockquote>
566 </dd>
567 <a name="replace"></a>
568 <dt><p><b>replace(<i>X</i>,<i>Y</i>,<i>Z</i>)</b></dt><dd><p>
569 The replace(X,Y,Z) function returns a string formed by substituting
570 string Z for every occurrence of string Y in string X. The <a href="datatype3.html#collation">BINARY</a>
571 collating sequence is used for comparisons. If Y is an empty
572 string then return X unchanged. If Z is not initially
573 a string, it is cast to a UTF-8 string prior to processing.
574 </dd>
575 <a name="round"></a>
576 <dt><p><b>round(<i>X</i>)<br />round(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
577 The round(X,Y) function returns a floating-point
578 value X rounded to Y digits to the right of the decimal point.
579 If the Y argument is omitted or negative, it is taken to be 0.
580 </dd>
581 <a name="rtrim"></a>
582 <dt><p><b>rtrim(<i>X</i>)<br />rtrim(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
583 The rtrim(X,Y) function returns a string formed by removing any and all
584 characters that appear in Y from the right side of X.
585 If the Y argument is omitted, rtrim(X) removes spaces from the right
586 side of X.
587 </dd>
588 <a name="sign"></a>
589 <dt><p><b>sign(<i>X</i>)</b></dt><dd><p>
590 The sign(X) function returns -1, 0, or +1 if the argument X is a numeric
591 value that is negative, zero, or positive, respectively. If the argument
592 to sign(X) is NULL or is a string or blob that cannot be losslessly converted
593 into a number, then sign(X) returns NULL.
594 </dd>
595 <a name="soundex"></a>
596 <dt><p><b>soundex(<i>X</i>)</b></dt><dd><p>
597 The soundex(X) function returns a string that is the soundex encoding
598 of the string X.
599 The string "?000" is returned if the argument is NULL or contains
600 no ASCII alphabetic characters.
601 This function is omitted from SQLite by default.
602 It is only available if the <a href="compile.html#soundex">SQLITE_SOUNDEX</a> compile-time option
603 is used when SQLite is built.
604 </dd>
605 <a name="sqlite_compileoption_get"></a>
606 <dt><p><b>sqlite_compileoption_get(<i>N</i>)</b></dt><dd><p>
607 The sqlite_compileoption_get() SQL function is a wrapper around the
608 <a href="c3ref/compileoption_get.html">sqlite3_compileoption_get()</a> C/C++ function.
609 This routine returns the N-th compile-time option used to build SQLite
610 or NULL if N is out of range. See also the <a href="pragma.html#pragma_compile_options">compile_options pragma</a>.
611 </dd>
612 <a name="sqlite_compileoption_used"></a>
613 <dt><p><b>sqlite_compileoption_used(<i>X</i>)</b></dt><dd><p>
614 The sqlite_compileoption_used() SQL function is a wrapper around the
615 <a href="c3ref/compileoption_get.html">sqlite3_compileoption_used()</a> C/C++ function.
616 When the argument X to sqlite_compileoption_used(X) is a string which
617 is the name of a compile-time option, this routine returns true (1) or
618 false (0) depending on whether or not that option was used during the
619 build.
620 </dd>
621 <a name="sqlite_offset"></a>
622 <dt><p><b>sqlite_offset(<i>X</i>)</b></dt><dd><p>
623 The sqlite_offset(X) function returns the byte offset in the database
624 file for the beginning of the record from which value would be read.
625 If X is not a column in an ordinary table, then sqlite_offset(X) returns
626 NULL. The value returned by sqlite_offset(X) might reference either the
627 original table or an index, depending on the query. If the value X would
628 normally be extracted from an index, the sqlite_offset(X) returns the
629 offset to the corresponding index record. If the value X would be
630 extracted from the original table, then sqlite_offset(X) returns the offset
631 to the table record.
632
633 <p>The sqlite_offset(X) SQL function is only available if SQLite is built
634 using the <a href="compile.html#enable_offset_sql_func">-DSQLITE_ENABLE_OFFSET_SQL_FUNC</a> compile-time option.
635 </dd>
636 <a name="sqlite_source_id"></a>
637 <dt><p><b>sqlite_source_id()</b></dt><dd><p>
638 The sqlite_source_id() function returns a string that identifies the
639 specific version of the source code that was used to build the SQLite
640 library. The string returned by sqlite_source_id() is
641 the date and time that the source code was checked in followed by
642 the SHA3-256 hash for that check-in. This function is
643 an SQL wrapper around the <a href="c3ref/libversion.html">sqlite3_sourceid()</a> C interface.
644 </dd>
645 <a name="sqlite_version"></a>
646 <dt><p><b>sqlite_version()</b></dt><dd><p>
647 The sqlite_version() function returns the version string for the SQLite
648 library that is running. This function is an SQL
649 wrapper around the <a href="c3ref/libversion.html">sqlite3_libversion()</a> C-interface.
650 </dd>
651 <a name="substr"></a>
652 <dt><p><b>substr(<i>X</i>,<i>Y</i>,<i>Z</i>)<br />substr(<i>X</i>,<i>Y</i>)<br />substring(<i>X</i>,<i>Y</i>,<i>Z</i>)<br />substring(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
653 The substr(X,Y,Z) function returns a substring of input string X that begins
654 with the Y-th character and which is Z characters long.
655 If Z is omitted then substr(X,Y) returns all characters through the end
656 of the string X beginning with the Y-th.
657 The left-most character of X is number 1. If Y is negative
658 then the first character of the substring is found by counting from the
659 right rather than the left. If Z is negative then
660 the abs(Z) characters preceding the Y-th character are returned.
661 If X is a string then characters indices refer to actual UTF-8
662 characters. If X is a BLOB then the indices refer to bytes.
663 <p>
664 "substring()" is an alias for "substr()" beginning with SQLite version 3.34.
665 </dd>
666 <a name="total_changes"></a>
667 <dt><p><b>total_changes()</b></dt><dd><p>
668 The total_changes() function returns the number of row changes
669 caused by INSERT, UPDATE or DELETE
670 statements since the current database connection was opened.
671 This function is a wrapper around the <a href="c3ref/total_changes.html">sqlite3_total_changes64()</a>
672 C/C++ interface.
673 </dd>
674 <a name="trim"></a>
675 <dt><p><b>trim(<i>X</i>)<br />trim(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
676 The trim(X,Y) function returns a string formed by removing any and all
677 characters that appear in Y from both ends of X.
678 If the Y argument is omitted, trim(X) removes spaces from both ends of X.
679 </dd>
680 <a name="typeof"></a>
681 <dt><p><b>typeof(<i>X</i>)</b></dt><dd><p>
682 The typeof(X) function returns a string that indicates the <a href="datatype3.html">datatype</a> of
683 the expression X: "null", "integer", "real", "text", or "blob".
684 </dd>
685 <a name="unhex"></a>
686 <dt><p><b>unhex(<i>X</i>)<br />unhex(<i>X</i>,<i>Y</i>)</b></dt><dd><p>
687 The unhex(X,Y) function returns a BLOB value which is the decoding of the
688 hexadecimal string X. If X contains any
689 characters that are not hexadecimal digits and which are not in Y,
690 then unhex(X,Y) returns NULL. If Y is omitted, it is
691 understood to be an empty string and hence X must be a pure hexadecimal string.
692 All hexadecimal digits in X must occur in pairs, with both digits of each
693 pair beginning immediately adjacent to one another, or else unhex(X,Y)
694 returns NULL.
695 If either parameter X or Y is NULL, then unhex(X,Y) returns NULL.
696 The X input may contain an arbitrary mix of upper and lower case hexadecimal
697 digits.
698 Hexadecimal digits in Y have no affect on the translation of X. Only
699 characters in Y that are not hexadecimal digits are ignored in X.
700 <p>
701 See also: <a href="lang_corefunc.html#hex">hex()</a>
702 </dd>
703 <a name="unicode"></a>
704 <dt><p><b>unicode(<i>X</i>)</b></dt><dd><p>
705 The unicode(X) function returns the numeric unicode code point corresponding to
706 the first character of the string X. If the argument to unicode(X) is not a string
707 then the result is undefined.
708 </dd>
709 <a name="unlikely"></a>
710 <dt><p><b>unlikely(<i>X</i>)</b></dt><dd><p>
711 The unlikely(X) function returns the argument X unchanged.
712 The unlikely(X) function is a no-op that the code generator
713 optimizes away so that it consumes no CPU cycles at
714 run-time (that is, during calls to <a href="c3ref/step.html">sqlite3_step()</a>).
715 The purpose of the unlikely(X) function is to provide a hint
716 to the query planner that the argument X is a boolean value
717 that is usually not true. The unlikely(X) function is equivalent
718 to <a href="lang_corefunc.html#likelihood">likelihood</a>(X, 0.0625).
719 </dd>
720 <a name="upper"></a>
721 <dt><p><b>upper(<i>X</i>)</b></dt><dd><p>
722 The upper(X) function returns a copy of input string X in which all
723 lower-case ASCII characters are converted to their upper-case equivalent.
724 </dd>
725 <a name="zeroblob"></a>
726 <dt><p><b>zeroblob(<i>N</i>)</b></dt><dd><p>
727 The zeroblob(N) function returns a BLOB consisting of N bytes of 0x00.
728 SQLite manages these zeroblobs very efficiently. Zeroblobs can be used to
729 reserve space for a BLOB that is later written using
730 <a href="c3ref/blob_open.html">incremental BLOB I/O</a>.
731 This SQL function is implemented using the <a href="c3ref/result_blob.html">sqlite3_result_zeroblob()</a>
732 routine from the C/C++ interface.
733 </dd>
734
735 </dl>
736 <p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/lang_corefunc.in?m=a451f26240">2023-12-05 14:43:20</a> UTC </small></i></p>
737