1.串接函数:把John和son串接 :
oracle 中 select 'john' || 'son'
SQLserver 中 select 'john' +'son'
mysql 中 select concat ('john' , 'son')
2.translate 函数 : 搜索字符串里的字符病查找特定的字符,标记找到位置,然后用替代字符串里的对应字符替换它
select city , translate (city , 'ind' ,'abc') from employee_tbl; i --a;n---b;d---c
3.replace
4.upper: 大写
select upper(city) from employee_tbl;
5.lower
6.substr(substring)
oracle : substr(column name ,starting position , length)
sqlserver : substring(column name,staring position , length)
7.instr :寻找指定的字符集 ,返回 其所在的位置
select prod_dec , instr(prod_dec ,'a',1,1) from products_tbl;找出a在prod_dec 出现的第一次位置
8.ltrim:截取字符串 从左开始
select position ,ltrim(position,'sales') from employee_tbl;返回职位及职位字符串里从左减除sales后的结果
9.rtrim 截取字符串 从右开始
10.decode
select city ,decode(city,'indianapolis','indy','greeenwood','green','other') from employee_tbl ; indianapolis显示为indy,greeenwood显示为green,其他other
其他字符串函数:
1.lenngth
2.ifnull
select pager, ifnull(pager,999999) from employee_tbl;寻找null 用999999代替
3.coalesce 同2 但是又可以找非null值返回
select emp_id,coalesce (bonus,salary,pay_rate) from employee_tbl;找三个字段的第一个非null值返回
4. lpad 左填充
select lpad(prod_desc,30,'.') product from employee_tbl;左侧添加. 使其总共长30
5.rpad 右填充
6.ascII A 65 B 66 C 67 a 95
算数函数:
常见算数函数:
绝对值 abs
舍入 round
平方根 sqrt
符号 sign
幂 power
上限和下限 ceil , floor
指数 exp
sin cos tan
语法 function(expresstion)
转换函数:
1.字符串转换为数字: select emp_id , to_number(emp_id) from employee_tbl (oracle中的转换)
2.数字转换为字符串:sqlserver : select pay=pay_rate,new_pay=str(pay_rate) from employee_tbl where pay_rate is not null;
orcal : select pay_rate, to_char(pay_rate) from employee_tbl where pay_rate is not null;
字符函数的组合使用:
select concat (last_name , ',' ,first_name ) name , concat(substr(emp_id,1,3)),'-',substr(emp_id,6,4) as id from employee_tbl; 把emp_id 字段分为三个部分,用-连接,concat 组合字符串。