對錶中的字元型字段可以進行操作
一、計算字元的長度
格式:length('string')
使用:select length('string') from 表名1
二、全部轉化為小寫
格式:lower('string')
使用:select lower('string') from 表名1
三、全部轉化為大寫
格式:upper('string')
使用:select upper('string') from 表名1
四、擷取字串
格式1:substr('string',start,length)
start代表開始位置,length代表擷取長度。
格式2:substring_index('string','符號','次數')
格式2針對的是字串中有符號的情況,「符號」位填入的是碰到之後要停止的符號,「次數」位是填入第幾次碰到這個符號後停止 擷取。
example:
select substring_index('hello:world:woshi:shui',':',2)
此時擷取到的字串為:hello:world
使用:select substr() from 表1
五、從指定左側讀取字串
格式:left('string',length)
使用:select left('string') from 表1
六、從指定右讀取字串
格式:right('string',length)
七、去掉左側的空格
ltrim(' string')
八、去掉右側的空格
rtrim('string ')
九、去掉兩側的空格或者指定字元
trim(both|leading|trailing'set'from'string')
解釋:both是trim預設的引數,為去掉兩邊的空格;
leading是去掉左側的指定字元,需要和from搭配
trailing是去掉右側的指定字元,需要和from搭配
set為指定字元
example:select trim(' shangbonihao ')
select trim(leading'sh'from'shangbonihao')
十、給左側新增空格
格式:lpad('string','padstring',length)
使用:select lpad('string','padstring',length)
十一、給右側新增空格
格式:rpad('string',length,'padstring')
使用:select lpad('string',length,'padstring')
十二、取得指定子串在字串中的位置
格式1:instr('string','子串')
格式2:position('string','子串')
格式3:locate('string','子串',start)
start為開始位置
使用:select instr('子串','string')
十三、顛倒字串
格式:reverse('string')
使用:select reverse('string')
十四、替換指定字串
格式:replace('srting','子串','替換')
使用:select replace.........
十五、拼接字串
格式:concat('sting1','string2')
使用:select concat('string1','string2')
十六、取得字元的ascii碼
格式:ascii('string')
使用:select ascii('string')
十七、將ascii轉化為字元
格式:char('ascii碼')
使用:select char('ascii')
十八、匹配發音
格式:soundex('string')
使用:select soundex('string')
十九、將制定字串重複值得次數
格式:repeat('string',count)
count為重複次數
使用:select('string',count)
資料庫常用函式 數字函式
對錶中的數字型字段可以進行操作 一 求絕度值 格式 select abs n 二 求平方 mysql不支援 格式 select square n 三 求平方根 格式 select sqrt n 四 求對數 1.自然對數 格式 select log n 2.以十為底 格式 select log10 n...
資料庫基本函式 字元函式(Oracle)
一 字元函式 1 ascii str 是字串,返回str 第乙個字母的ascii碼,它的逆函式是chr 例如 select ascii a big a ascii z big z from emp 返回結果 big a big z 65 122 2 chr nchar cs i是乙個數字,函式返回十...
達夢資料庫常用函式 字串函式
字串函式一般接受字元型別 包括 char 和 varchar 和數值型別的引數,返回值一 般是字元型別或是數值型別。語法 ascii char 功能 返回字元 char 對應的整數 assic 值 例select ascii b ascii 中 查詢結果為 66 54992 語法 bit lengt...