bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/SQL/SQL References
SQL•SQL References

MySQL Functions

MySQL has many built-in functions.

This reference contains string, numeric, date, and some advanced functions in MySQL.

MySQL String Functions

FunctionDescription
ASCIIReturns the ASCII value for the specific character
CHAR_LENGTHReturns the length of a string (in characters)
CHARACTER_LENGTHReturns the length of a string (in characters)
CONCATAdds two or more expressions together
CONCAT_WSAdds two or more expressions together with a separator
FIELDReturns the index position of a value in a list of values
FIND_IN_SETReturns the position of a string within a list of strings
FORMATFormats a number to a format like "#,###,###.##", rounded to a specified number of decimal places
INSERTInserts a string within a string at the specified position and for a certain number of characters
INSTRReturns the position of the first occurrence of a string in another string
LCASEConverts a string to lower-case
LEFTExtracts a number of characters from a string (starting from left)
LENGTHReturns the length of a string (in bytes)
LOCATEReturns the position of the first occurrence of a substring in a string
LOWERConverts a string to lower-case
LPADLeft-pads a string with another string, to a certain length
LTRIMRemoves leading spaces from a string
MIDExtracts a substring from a string (starting at any position)
POSITIONReturns the position of the first occurrence of a substring in a string
REPEATRepeats a string as many times as specified
REPLACEReplaces all occurrences of a substring within a string, with a new substring
REVERSEReverses a string and returns the result
RIGHTExtracts a number of characters from a string (starting from right)
RPADRight-pads a string with another string, to a certain length
RTRIMRemoves trailing spaces from a string
SPACEReturns a string of the specified number of space characters
STRCMPCompares two strings
SUBSTRExtracts a substring from a string (starting at any position)
SUBSTRINGExtracts a substring from a string (starting at any position)
SUBSTRING_INDEXReturns a substring of a string before a specified number of delimiter occurs
TRIMRemoves leading and trailing spaces from a string
UCASEConverts a string to upper-case
UPPERConverts a string to upper-case

MySQL Numeric Functions

FunctionDescription
ABSReturns the absolute value of a number
ACOSReturns the arc cosine of a number
ASINReturns the arc sine of a number
ATANReturns the arc tangent of one or two numbers
ATAN2Returns the arc tangent of two numbers
AVGReturns the average value of an expression
CEILReturns the smallest integer value that is >= to a number
CEILINGReturns the smallest integer value that is >= to a number
COSReturns the cosine of a number
COTReturns the cotangent of a number
COUNTReturns the number of records returned by a select query
DEGREESConverts a value in radians to degrees
DIVUsed for integer division
EXPReturns e raised to the power of a specified number
FLOORReturns the largest integer value that is <= to a number
GREATESTReturns the greatest value of the list of arguments
LEASTReturns the smallest value of the list of arguments
LNReturns the natural logarithm of a number
LOGReturns the natural logarithm of a number, or the logarithm of a number to a specified base
LOG10Returns the natural logarithm of a number to base 10
LOG2Returns the natural logarithm of a number to base 2
MAXReturns the maximum value in a set of values
MINReturns the minimum value in a set of values
MODReturns the remainder of a number divided by another number
PIReturns the value of PI
POWReturns the value of a number raised to the power of another number
POWERReturns the value of a number raised to the power of another number
RADIANSConverts a degree value into radians
RANDReturns a random number
ROUNDRounds a number to a specified number of decimal places
SIGNReturns the sign of a number
SINReturns the sine of a number
SQRTReturns the square root of a number
SUMCalculates the sum of a set of values
TANReturns the tangent of a number
TRUNCATETruncates a number to the specified number of decimal places

MySQL Date Functions

FunctionDescription
ADDDATEAdds a time/date interval to a date and then returns the date
ADDTIMEAdds a time interval to a time/datetime and then returns the time/datetime
CURDATEReturns the current date
CURRENT_DATEReturns the current date
CURRENT_TIMEReturns the current time
CURRENT_TIMESTAMPReturns the current date and time
CURTIMEReturns the current time
DATEExtracts the date part from a datetime expression
DATEDIFFReturns the number of days between two date values
DATE_ADDAdds a time/date interval to a date and then returns the date
DATE_FORMATFormats a date
DATE_SUBSubtracts a time/date interval from a date and then returns the date
DAYReturns the day of the month for a given date
DAYNAMEReturns the weekday name for a given date
DAYOFMONTHReturns the day of the month for a given date
DAYOFWEEKReturns the weekday index for a given date
DAYOFYEARReturns the day of the year for a given date
EXTRACTExtracts a part from a given date
FROM_DAYSReturns a date from a numeric datevalue
HOURReturns the hour part for a given date
LAST_DAYExtracts the last day of the month for a given date
LOCALTIMEReturns the current date and time
LOCALTIMESTAMPReturns the current date and time
MAKEDATECreates and returns a date based on a year and a number of days value
MAKETIMECreates and returns a time based on an hour, minute, and second value
MICROSECONDReturns the microsecond part of a time/datetime
MINUTEReturns the minute part of a time/datetime
MONTHReturns the month part for a given date
MONTHNAMEReturns the name of the month for a given date
NOWReturns the current date and time
PERIOD_ADDAdds a specified number of months to a period
PERIOD_DIFFReturns the difference between two periods
QUARTERReturns the quarter of the year for a given date value
SECONDReturns the seconds part of a time/datetime
SEC_TO_TIMEReturns a time value based on the specified seconds
STR_TO_DATEReturns a date based on a string and a format
SUBDATESubtracts a time/date interval from a date and then returns the date
SUBTIMESubtracts a time interval from a datetime and then returns the time/datetime
SYSDATEReturns the current date and time
TIMEExtracts the time part from a given time/datetime
TIME_FORMATFormats a time by a specified format
TIME_TO_SECConverts a time value into seconds
TIMEDIFFReturns the difference between two time/datetime expressions
TIMESTAMPReturns a datetime value based on a date or datetime value
TO_DAYSReturns the number of days between a date and date "0000-00-00"
WEEKReturns the week number for a given date
WEEKDAYReturns the weekday number for a given date
WEEKOFYEARReturns the week number for a given date
YEARReturns the year part for a given date
YEARWEEKReturns the year and week number for a given date

MySQL Advanced Functions

FunctionDescription
BINReturns a binary representation of a number
BINARYConverts a value to a binary string
CASEGoes through conditions and return a value when the first condition is met
CASTConverts a value (of any type) into a specified datatype
COALESCEReturns the first non-null value in a list
CONNECTION_IDReturns the unique connection ID for the current connection
CONVConverts a number from one numeric base system to another
CONVERTConverts a value into the specified datatype or character set
CURRENT_USERReturns the user name and host name for the MySQL account that the server used to authenticate the current client
DATABASEReturns the name of the current database
IFReturns a value if a condition is TRUE, or another value if a condition is FALSE
IFNULLReturn a specified value if the expression is NULL, otherwise return the expression
ISNULLReturns 1 or 0 depending on whether an expression is NULL
LAST_INSERT_IDReturns the AUTO_INCREMENT id of the last row that has been inserted in a table
NULLIFCompares two expressions and returns NULL if they are equal. Otherwise, the first expression is returned
SESSION_USERReturns the current MySQL user name and host name
SYSTEM_USERReturns the current MySQL user name and host name
USERReturns the current MySQL user name and host name
VERSIONReturns the current version of the MySQL database

Previous

SQL WHERE Keyword

Next

MySQL ASCII() Function

This chapter

Overview
371

Lessons

778m

Read time

1. SQL Data Types for MySQL, SQL Server, and MS Access2. SQL ADD Keyword3. SQL ADD CONSTRAINT Keyword4. SQL ALL Keyword5. SQL ALTER Keyword6. SQL ALTER COLUMN Keyword7. SQL ALTER TABLE Keyword8. SQL ALTER VIEW Keyword9. SQL AND Keyword10. SQL ANY Keyword11. SQL AS Keyword12. SQL ASC Keyword13. SQL BACKUP DATABASE Keyword14. SQL BETWEEN Keyword15. SQL CASE Keyword16. SQL CHECK Keyword17. SQL COLUMN Keyword18. SQL CONSTRAINT Keyword19. SQL CREATE Keyword20. SQL CREATE DATABASE Keyword21. SQL CREATE INDEX Keyword22. SQL CREATE OR REPLACE VIEW Keyword23. SQL CREATE TABLE Keyword24. SQL CREATE PROCEDURE Keyword25. SQL CREATE UNIQUE INDEX Keyword26. SQL CREATE VIEW Keyword27. SQL DATABASE Keyword28. SQL DEFAULT Keyword29. SQL DELETE Keyword30. SQL DESC Keyword31. SQL SELECT DISTINCT Keyword32. SQL DROP Keyword33. SQL DROP COLUMN Keyword34. SQL DROP CONSTRAINT Keyword35. SQL DROP DATABASE Keyword36. SQL DROP DEFAULT Keyword37. SQL DROP INDEX Keyword38. SQL DROP TABLE and TRUNCATE TABLE Keywords39. SQL DROP VIEW Keyword40. SQL EXEC Keyword41. SQL EXISTS Keyword42. SQL FOREIGN KEY Keyword43. SQL FROM Keyword44. SQL FULL OUTER JOIN Keyword45. SQL GROUP BY Keyword46. SQL HAVING Keyword47. SQL IN Keyword48. SQL INDEX Keyword49. SQL INNER JOIN Keyword50. SQL INSERT INTO Keyword51. SQL INSERT INTO SELECT Keyword52. SQL IS NULL Keyword53. SQL IS NOT NULL Keyword54. SQL JOIN Keyword55. SQL LEFT JOIN Keyword56. SQL LIKE Keyword57. SQL SELECT TOP, LIMIT and ROWNUM Keywords58. SQL NOT Keyword59. SQL NOT NULL Keyword60. SQL OR Keyword61. SQL ORDER BY Keyword62. SQL FULL OUTER JOIN Keyword63. SQL PRIMARY KEY Keyword64. SQL CREATE PROCEDURE Keyword65. SQL RIGHT JOIN Keyword66. SQL SELECT TOP, LIMIT and ROWNUM Keywords67. SQL SELECT Keyword68. SQL SELECT DISTINCT Keyword69. SQL SELECT INTO Keyword70. SQL SELECT TOP, LIMIT and ROWNUM Keywords71. SQL SET Keyword72. SQL TABLE Keyword73. SQL SELECT TOP, LIMIT and ROWNUM Keywords74. SQL DROP TABLE and TRUNCATE TABLE Keywords75. SQL UNION Keyword76. SQL UNION ALL Keyword77. SQL UNIQUE Keyword78. SQL UPDATE Keyword79. SQL VALUES Keyword80. SQL VIEW Keyword81. SQL WHERE Keyword82. MySQL Functions83. MySQL ASCII() Function84. MySQL CHAR_LENGTH() Function85. MySQL CHARACTER_LENGTH() Function86. MySQL CONCAT() Function87. MySQL CONCAT_WS() Function88. MySQL FIELD() Function89. MySQL FIND_IN_SET() Function90. MySQL FORMAT() Function91. MySQL INSERT() Function92. MySQL INSTR() Function93. MySQL LCASE() Function94. MySQL LEFT() Function95. MySQL LENGTH() Function96. MySQL LOCATE() Function97. MySQL LOWER() Function98. MySQL LPAD() Function99. MySQL LTRIM() Function100. MySQL MID() Function101. MySQL POSITION() Function102. MySQL REPEAT() Function103. MySQL REPLACE() Function104. MySQL REVERSE() Function105. MySQL RIGHT() Function106. MySQL RPAD() Function107. MySQL RTRIM() Function108. MySQL SPACE() Function109. MySQL STRCMP() Function110. MySQL SUBSTR() Function111. MySQL SUBSTRING() Function112. MySQL SUBSTRING_INDEX() Function113. MySQL TRIM() Function114. MySQL UCASE() Function115. MySQL UPPER() Function116. MySQL ABS() Function117. MySQL ACOS() Function118. MySQL ASIN() Function119. MySQL ATAN() Function120. MySQL ATAN2() Function121. MySQL AVG() Function122. MySQL CEIL() Function123. MySQL CEILING() Function124. MySQL COS() Function125. MySQL COT() Function126. MySQL COUNT() Function127. MySQL DEGREES() Function128. MySQL DIV Function129. MySQL EXP() Function130. MySQL FLOOR() Function131. MySQL GREATEST() Function132. MySQL LEAST() Function133. MySQL LN() Function134. MySQL LOG() Function135. MySQL LOG10() Function136. MySQL LOG2() Function137. MySQL MAX() Function138. MySQL MIN() Function139. MySQL MOD() Function140. MySQL PI() Function141. MySQL POW() Function142. MySQL POWER() Function143. MySQL RADIANS() Function144. MySQL RAND() Function145. MySQL ROUND() Function146. MySQL SIGN() Function147. MySQL SIN() Function148. MySQL SQRT() Function149. MySQL SUM() Function150. MySQL TAN() Function151. MySQL TRUNCATE() Function152. MySQL ADDDATE() Function153. MySQL ADDTIME() Function154. MySQL CURDATE() Function155. MySQL CURRENT_DATE() Function156. MySQL CURRENT_TIME() Function157. MySQL CURRENT_TIMESTAMP() Function158. MySQL CURTIME() Function159. MySQL DATE() Function160. MySQL DATEDIFF() Function161. MySQL DATE_ADD() Function162. MySQL DATE_FORMAT() Function163. MySQL DATE_SUB() Function164. MySQL DAY() Function165. MySQL DAYNAME() Function166. MySQL DAYOFMONTH() Function167. MySQL DAYOFWEEK() Function168. MySQL DAYOFYEAR() Function169. MySQL EXTRACT() Function170. MySQL FROM_DAYS() Function171. MySQL HOUR() Function172. MySQL LAST_DAY() Function173. MySQL LOCALTIME() Function174. MySQL LOCALTIMESTAMP() Function175. MySQL MAKEDATE() Function176. MySQL MAKETIME() Function177. MySQL MICROSECOND() Function178. MySQL MINUTE() Function179. MySQL MONTH() Function180. MySQL MONTHNAME() Function181. MySQL NOW() Function182. MySQL PERIOD_ADD() Function183. MySQL PERIOD_DIFF() Function184. MySQL QUARTER() Function185. MySQL SECOND() Function186. MySQL SEC_TO_TIME() Function187. MySQL STR_TO_DATE() Function188. MySQL SUBDATE() Function189. MySQL SUBTIME() Function190. MySQL SYSDATE() Function191. MySQL TIME() Function192. MySQL TIME_FORMAT() Function193. MySQL TIME_TO_SEC() Function194. MySQL TIMEDIFF() Function195. MySQL TIMESTAMP() Function196. MySQL TO_DAYS() Function197. MySQL WEEK() Function198. MySQL WEEKDAY() Function199. MySQL WEEKOFYEAR() Function200. MySQL YEAR() Function201. MySQL YEARWEEK() Function202. MySQL BIN() Function203. MySQL BINARY Function204. MySQL CASE Function205. MySQL CAST() Function206. MySQL COALESCE() Function207. MySQL CONNECTION_ID() Function208. MySQL CONV() Function209. MySQL CONVERT() Function210. MySQL CURRENT_USER() Function211. MySQL DATABASE() Function212. MySQL IF() Function213. MySQL IFNULL() Function214. MySQL ISNULL() Function215. MySQL LAST_INSERT_ID() Function216. MySQL NULLIF() Function217. MySQL SESSION_USER() Function218. MySQL SYSTEM_USER() Function219. MySQL USER() Function220. MySQL VERSION() Function221. SQL Server Functions222. SQL Server ASCII() Function223. SQL Server CHAR() Function224. SQL Server CHARINDEX() Function225. SQL Server CONCAT() Function226. SQL Server Concat With +227. SQL Server CONCAT_WS() Function228. SQL Server DATALENGTH() Function229. SQL Server DIFFERENCE() Function230. SQL Server FORMAT() Function231. SQL Server LEFT() Function232. SQL Server LEN() Function233. SQL Server LOWER() Function234. SQL Server LTRIM() Function235. SQL Server NCHAR() Function236. SQL Server PATINDEX() Function237. SQL Server QUOTENAME() Function238. SQL Server REPLACE() Function239. SQL Server REPLICATE() Function240. SQL Server REVERSE() Function241. SQL Server RIGHT() Function242. SQL Server RTRIM() Function243. SQL Server SOUNDEX() Function244. SQL Server SPACE() Function245. SQL Server STR() Function246. SQL Server STUFF() Function247. SQL Server SUBSTRING() Function248. SQL Server TRANSLATE() Function249. SQL Server TRIM() Function250. SQL Server UNICODE() Function251. SQL Server UPPER() Function252. SQL Server ABS() Function253. SQL Server ACOS() Function254. SQL Server ASIN() Function255. SQL Server ATAN() Function256. SQL Server ATN2() Function257. SQL Server AVG() Function258. SQL Server CEILING() Function259. SQL Server COUNT() Function260. SQL Server COS() Function261. SQL Server COT() Function262. SQL Server DEGREES() Function263. SQL Server EXP() Function264. SQL Server FLOOR() Function265. SQL Server LOG() Function266. SQL Server LOG10() Function267. SQL Server MAX() Function268. SQL Server MIN() Function269. SQL Server PI() Function270. SQL Server POWER() Function271. SQL Server RADIANS() Function272. SQL Server RAND() Function273. SQL Server ROUND() Function274. SQL Server SIGN() Function275. SQL Server SIN() Function276. SQL Server SQRT() Function277. SQL Server SQUARE() Function278. SQL Server SUM() Function279. SQL Server TAN() Function280. SQL Server CURRENT_TIMESTAMP Function281. SQL Server DATEADD() Function282. SQL Server DATEDIFF() Function283. SQL Server DATEFROMPARTS() Function284. SQL Server DATENAME() Function285. SQL Server DATEPART() Function286. SQL Server DAY() Function287. SQL Server GETDATE() Function288. SQL Server GETUTCDATE() Function289. SQL Server ISDATE() Function290. SQL Server MONTH() Function291. SQL Server SYSDATETIME() Function292. SQL Server YEAR() Function293. SQL Server CAST() Function294. SQL Server COALESCE() Function295. SQL Server CONVERT() Function296. SQL Server CURRENT_USER Function297. SQL Server IIF() Function298. SQL Server ISNULL() Function299. SQL Server ISNUMERIC() Function300. SQL Server NULLIF() Function301. SQL Server SESSION_USER Function302. SQL Server SESSIONPROPERTY() Function303. SQL Server SYSTEM_USER Function304. SQL Server USER_NAME() Function305. MS Access Functions306. MS Access Asc() Function307. MS Access C hr() Function308. MS Access Concat With &309. MS Access CurDir() Function310. MS Access Format() Function311. MS Access InStr() Function312. MS Access InstrRev() Function313. MS Access LCase() Function314. MS Access Left() Function315. MS Access Len() Function316. MS Access LTrim() Function317. MS Access Mid() Function318. MS Access Replace() Function319. MS Access Right() Function320. MS Access RTrim() Function321. MS Access Space() Function322. MS Access Split() Function323. MS Access Str() Function324. MS Access StrComp() Function325. MS Access StrConv() Function326. MS Access StrReverse() Function327. MS Access Trim() Function328. MS Access UCase() Function329. MS Access Abs() Function330. MS Access Atn() Function331. MS Access Avg() Function332. MS Access Cos() Function333. MS Access Count() Function334. MS Access Exp() Function335. MS Access Fix() Function336. MS Access Format() Function337. MS Access Int() Function338. MS Access Max() Function339. MS Access Min() Function340. MS Access Randomize() Function341. MS Access Rnd Function342. MS Access Round() Function343. MS Access Sgn() Function344. MS Access Sqr() Function345. MS Access Sum() Function346. MS Access Val() Function347. MS Access Date() Function348. MS Access DateAdd() Function349. MS Access DateDiff() Function350. MS Access DatePart() Function351. MS Access DateSerial() Function352. MS Access DateValue() Function353. MS Access Day() Function354. MS Access Format() Function355. MS Access Hour() Function356. MS Access Minute() Function357. MS Access Month() Function358. MS Access MonthName() Function359. MS Access Now() Function360. MS Access Second() Function361. MS Access Time() Function362. MS Access TimeSerial() Function363. MS Access TimeValue() Function364. MS Access Weekday() Function365. MS Access WeekdayName() Function366. MS Access Year() Function367. MS Access CurrentUser() Function368. MS Access Environ() Function369. MS Access IsDate() Function370. MS Access IsNull() Function371. MS Access IsNumeric() Function

On this page

MySQL String FunctionsMySQL Numeric FunctionsMySQL Date FunctionsMySQL Advanced Functions