資料庫 相關函式

2021-08-25 22:26:01 字數 1566 閱讀 6676

函式:

常用的日期函式:

select curren_date();(當前日期)

select current_time();(當前時間)

select curren_timestamp;(時間戳)

select date_add('2017-10-28',interval 10 day)(在日期的基礎上加日期)

select date_add(curren_date().interval 2 day)

select date_sub('2017-10-28',interval -1 day)(減去)

select datediff('2018-08-26','2018-09-01') (相差多少天)

select now();

select * from msg where date_add(sendtime, interval 2 minute) > now();(查詢兩分鐘之內發表的帖子)

字串函式:

select charset(ename) from emp;(獲取emp表中的ename列的字符集)

select concat(name, '的語文是',chinese,'分,數學是',math,'分') as '分數' from student;

(顯示student表中的資訊,顯示格式:「***的語文是***分,數學***分,英語***分「)

select length(name), name from student;(求學生表中學生姓名占用的位元組數)

select ename replace(ename, 's', '上海') ,ename from emp;(將emp表中所有名字中有s的替換成'上海')

select ename substring(ename, 2, 2), ename from emp;(擷取emp表中ename欄位的第二個到第三個字元,下標從1開始)

select ename concat(lcase(substring(ename, 1, 1)),substring(ename,2)) from emp;(以首字母小寫的方式顯示所有員工的姓名)

數學函式:

select abs(-100.2);(絕對值)

select ceiling(23,04);(向上取整)

select floor(23.7);(向下取整)

select format(12.3456, 2);(保留2位小數(四捨五入))

select rand();(產生隨機數)

select bin(10), hex(10),conv(10,10,8);(進製轉化)

其他常用函式:

select user();(查詢當前使用者)

select database();(顯示當前使用的資料庫)

select md5('admin');(對乙個字串進行md5摘要,摘要的到乙個32位字串)——防偽鑑別

select password ('root');(mysql 資料庫使用該函式對應使用者加密)

select ifnull(val1,val2);(如果val1為null,返回val2,否則返回val1的值)

資料庫相關

1.操作類 godb public goosundb open throws sqlexception public void close public cursor search int mark mark mark,null,null,null,col date desc if cursor n...

資料庫相關

資料庫的設計 分庫分表,記憶體資料庫,主從讀寫分離,資料庫中介軟體mycat 整合了主從讀寫分離,分庫分表等功能 資料庫優化 sql語句優化,資料庫配置優化,索引優化,資料庫設計優化 資料庫的鎖 1.樂觀鎖,表中增加版本字段,每次更改加1,查的時候先把版本字段查出來,更新的時候加上條件版本欄位沒變,...

資料庫相關

1 多顯示乙個字段,格式 使用者名稱 手機號 select concat name,tel from user 2 手機號顯示 132 22 select concat left tel,3 right tel,2 as 安全手機號 from user 1 多顯示乙個字段,格式 使用者名稱 手機號 ...