mysql常用內建變數 MySql中常用的內建函式

2021-10-17 20:11:10 字數 2112 閱讀 2866

以下是常用的mysql常用內建函式詳解說明,希望大家用幫助

一、數值函式     abs(x):返回絕對值     ceil(x):返回大於x的最小整數     floor(x):返回小於x的最大整數     mod(x,y):返回x與y的模     rand():返回0-1之間的隨機數   select round(rand()*100);     round(x,y):返回引數x的y位小數的四捨五入結果     truncate(x,y):返回數字x截斷為y位小數的結果

二、字串函式     php中用的,mysql中大部分都有

1.concat(s1,s2....sn):把傳入的引數連線成乙個字串     2.insert(str,x,y,insert):從str的x位置開始,替換y長度的字串為insert       select insert('abcdefg',2,3,'hello');     3.lower(str),upper(str):將字串轉換為大寫,小寫     4.left(str,x) right(str,x) 返回str左邊(右邊)x個字元,x為null則返回null     5.lpad(str,n,pad) rpad(str,n,pad)  用pad對字串str從最左邊(右邊)進行填充,直到總長度

達到n        select name,lpad(name,10,'#'),rpad(name,10,'(') from cats;     6.trim(),ltrim(),rtrim()去掉兩邊,左邊,右邊空格       select concat('1',trim('   abc   '),'2'),concat('1',ltrim('   abc   '),'2'),concat

('1',rtrim('   abc   '),'2')\g;       7.replace(str,a,b) 在字串str中用字串b替換所有的字串a     8.strcmp(s1,s2):如果s1比s2小,返回-1;如果s1比s2大則返回1;如果相等則返回0(比較的是

asc2碼)     9.substring(str,x,y) 返回字串str中從位置x起,長度為y的子字串

三、日期函式     用php時間戳來完成     curdate() curtime() now();   select curdate();         select unix_timestamp(now());         select from_unixtime(1331110656);         select week(now()),year(now());         select hour(curtime()),minute(curtime());         select monthname(now());         select date_format(now(),"%y-%m-%d %h:%i:%s"); 四、流程控制語句     create table salary(id int,salary decimal(9,2));

if(value,t,f);   select id,salary,if(salary>300,'high','low') from salary;     ifnull(t,f)    select id,salary,ifnull(salary,0) from salary;     case when [value1] then [result1]...else[default]end;          select case when salary<=300 then 'low' else 'high' end from salary;  五、其它函式(\s可以看到)     database()  select database();     version()     user()     inet_aton(ip)  將字串位址轉換為網路位址     password()  對mysql使用者加密     md5() 對使用者密碼加密       select * from mysql.user \g;

mysql中的全文索引型別fulltext的索引。  fulltext 索引僅可用於 myisam 表;他們可以從char、varchar或text列中作為create table語句的一部分被建立,或是隨後使用alter table 或 create index被新增。對於較大的資料集,將你的資料輸入乙個沒有fulltext索引的表中,然後建立索引,其速度比把資料輸入現有fulltext索引的速度更為快。

mysql內建變數 MySQL常用內建變數

mysql用很多常用的內建變數,掌握這些內建變數後對於我們快速獲取當前mysql的配置有很大幫助,下面就來列舉幾個常用的變數。檢視當前mysql版本號資訊。show variables like version mariadb none show variables like version var...

nginx常用內建變數

內建變數存放在 ngx http core module 模組中,變數的命名方式和apache 伺服器變數是一致的。總而言之,這些變數代表著客戶端請求頭的內容,例如 http user agent,http cookie,等等。下面是nginx支援的所有內建變數 arg name 請求中的的引數名,...

Python 常用內建變數

usr bin env python coding utf 8 author 小菠蘿測試筆記 blog time 2021 7 21 11 29 下午 file 5 list 列表.py import keyword from pprint import pprint print keyword.k...