MySQL function library

Source: Internet
Author: User

function library  mysql stored procedure basic functions include: String type, numeric type, date type   A, String class  charset (str)//return string Character set  concat (string2 [,...])//connection string  INSTR (string, substring)//returns the position where substring first appeared in string, does not exist return 0 lcase (string2)//converted to lowercase  left (string2, Length)//From the left side of the string2, take the length character  length (string)//string  load_file (file_name)//read content from File  locate ( substring, string [, Start_position]) with InStr, but can be specified starting position  lpad (string2, length, pad)//repeat pad plus string beginning until string length is Lengt H ltrim (string2)//Remove front-end space  repeat (string2, count)//Repeat Count times  replace (str, SEARCH_STR, REPLACE_STR)//In Use REPLACE_STR in str to replace Search_str rpad (string2, length, pad)//after STR with pad until length is Length rtrim (string2)// Remove the back-end space  strcmp (string1, string2)//character comparison two-string size,  substring (str, position [, length])//starting with the position of STR, Take length characters,  Note: When working with strings in MySQL, the default first character subscript is 1, i.e. the parameter position must be greater than or equal to 1 mysql> select substring (' ABCD ', 0,2);  + ——————— –+ | SUBSTRING (' ABCD ', 0,2) | + ——————— –+ |                      | + ——————— –+ 1 row in Set (0.00 sec )  mysql> Select substring (' ABCD ',  + ——————— –+ | SUBSTRING (' ABCD ', | + ——————— –+ | AB                    | + ——————— –+ 1 row in Set (0.02 sec) &nbs P TRIM ([[[Both| Leading| TRAILING] [padding] from]string2)//Remove the specified character from the specified position  ucase (string2)//Convert to uppercase  right (string2,length)// Take string2 last length character  space (count)//Generate count of spaces   Two, numeric type  abs (number2)//Absolute value  bin (decimal_number)/ /Decimal to Binary  ceiling (number2)//Up rounding  conv (number2,from_base,to_base)//Conversion  floor (NUMBER2)//Down rounding  format (number,decimal_places)//Reserved decimal place  hex (decimalnumber)//Turn hex   NOTE: Hex () to pass in the string, then return its ASC-11 code, such as Hex (' DEF ') returns 4142143  can also pass in a decimal integer, returning its hexadecimal encoding, such as Hex (25) to return 19 least (number, number2 [,..])///To find the minimum  mod ( Numerator, denominator)//redundancy  power (number, POWER )//Index  rand ([seed])// round (number [, decimals])//rounded, decimals to decimal place]  Note: Return types are not all integers, such as:  (1) The default becomes the Shaping value  mysql> select round (1.23);  + ————-+ | Round (1.23) | + ————-+ |           1 | + ————-+ 1 row in Set (0.00 sec)  mysql> Select round (1.56);  + ————-+ | Round (1.56) | + ————-+ |           2 | + ————-+ 1 row in Set (0.00 sec)   (2) can set the number of decimal digits, return float data  mysql> s Elect round (1.567,2);  + —————-+ | Round (1.567,2) | + —————-+ |           1.57 | + —————-+ 1 row in Set (0.00 sec)  sign (number2)//return symbol, plus or minus or 0&nbsp ; SQRT (NUMBER2)//Open square    III, date type  to_days ()   #SELECT to_days (now ())/365   result is 2014.8822  Yearweek ()   #SELECT yearweek (' 2013-07-18 ') result is 201328 addtime (Date2, Time_interval)//Will Time_ Interval to Date2 convert_tz (datetime2, Fromtz, Totz)//convert time zone   Current_date ()//Current date  current_time ()//Current time  current_timestamp ()//Current timestamp  date (datetime)//Return datetime Date part  date_add (date2, INTERVAL d_value d_type)//in Date2 plus date or time  date_format (datetime, Formatcodes)//use for Matcodes format Display datetime date_sub (Date2, INTERVAL d_value d_type)//Minus one time on Date2  datediff (date1, Date2)//Two days Period Difference  day (date)//date  dayname (date)//English week  dayofweek (date)//week (1-7), 1 for Sunday  dayofyear (date)// The day of the Year  extract (Interval_name from date)//The specified part of the date in the Extract  makedate (year, day)//gives the first days of the years and years, the date string is generated   Maketime (hour, minute, second)//Generate time string  monthname (date)//English month name  now ()//Current time  sec_to_time (seconds)// Seconds turn into Time  str_to_date (string, format)//String to time, display  timediff in format format (datetime1, datetime2)//Two time difference  time _to_sec (time)//times to Seconds] week (Date_time [, Start_of_week])//Weeks  year (DateTime)//year  dayofmonth ( DATETIME)//month of day  hour (datetime)//hour last_day (date)//date The last date of the month  microsecond (datetime)//Microsecond  month (DateTime)//month  minute (datetime) Points   Notes: Types available in interval: day, Day_hour, Day_minute, Day_second, HOUR, Hour_minute, Hour_second, MINUTE, Minute_ Second,month, SECOND, Year declare variable_name [, variable_name ...] datatype [DEFAULT value];  which, datatype for MySQL data type, such as: int, FLOAT, DATE, VARCHAR (length)   Example:  declare l_int INT unsigned default 4000000;  DECLARE l_numeric Numeric (8,2) default 9.95; declare l_date date default ' 1999-12-31 ';  declare l_datetime DATETIME default ' 1999-12-31 23:59:59 ';  declare l_varchar varchar (255) Default ' this would not be padded '; 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.