1、substr(): 截取字符串长度
公式 : select substr(‘hello word’,start,subLength);
select substr('hello word',0,1); -- h
select substr('hello word',0,1); -- h 0 和1 都表示截取位置从第一个字符开始
select substr('hello word',2,4); -- ello
select substr('hello word',-1,4); -- word 负数表示截取字符从右端开始
2、instr() : 判断字符串中是否存在某个字符串
公式 instr(‘A’,’B’)
类似 Java 中的 indexof() 函数
select instr('hello word' ,'ell') from dual ; --2
select instr('hello word' ,'ell') from dual where instr('hello word' ,'el1l')>0 ; -- 查不到数据
3、decode() :
公式 : decode(条件,值1,返回值1,值2,返回值2, … ,值n,返回值n )
等同
if(条件 == 值1) then return 返回值1
elseif(条件 == 值2) then return 返回值2
…
elseif (条件 == 值n) then return 返回值n
else
return (缺省值)
end if
select decode(status, 'RETURNED', '已还柜', 'PICKED', '已提柜', '其他') from DUAL;
-- 如果状态为 ‘RETURNED’ 返回 '已还柜' ,如果状态为 '已还柜' 返回 'PICKED' 。依次类推
4、initcap() : 单词首字母大写,以 空格、符号 及其它非字母 限制。
select initcap('hello word') from dual ; -- Hello Word
select initcap('hello,word') from dual ; -- Hello,Word
5、concat() : 连接字符串
公式 concat(A,B) :只能连接两个字符 ;
与 || 的区别 : 可以连接多个字符 ;
select concat('hello','word') from dual ; -- helloword
select 'hello'||'word'||'!' as message from dual ; -- helloword!
6、replace() : 字符替换函数 ,用某个字符串替换现在的字符串
1、update test set name = replace(name,',',''); --逗号换成""
7、inner join on : 内连接
公式 : select * from A a inner join B b on a.id = b.id ;
同 : select * from A a ,B b where a.id = b.id ;