Qracle学习:字符串相关函数
生活随笔
收集整理的這篇文章主要介紹了
Qracle学习:字符串相关函数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
(1)lower : 小寫, upper :大寫,initcap :單詞的首字母大寫
select lower('HELLO WORLD') "小寫", upper('Hello world') "大寫", initcap('hello world') "首字母大寫" from dual;(2) concat ( 連接符|| )
select concat('hello ','world') from dual;注意:concat 函數(shù)只能連接兩個(gè)字符串,若想連接三個(gè)的話只能嵌套調(diào)用
select concat(concat('hello ','world'), ' nihao') from dual;select 'hello ' || 'world ' || 'nihao' from dual;// || 可以連接多個(gè)字符串, 建議使用||來連接字符串(3)substr(str, pos, len) 截取字符串
select substr('helloworld',1,3), substr('helloworld',1), substr('helloworld',-3) from dual;//pos 是從 1 開始的,若 len 為 0 表示從 pos 開始, 截取到最后,若 pos 為負(fù)數(shù),表示從末尾倒數(shù)開始截取(4) instr(str, substr):判斷 substr 是否在 str 中存在,
select instr('hello llo', 'llo'), instr('hello llo', 'ow')from dual;//若存在返回第一次出現(xiàn)的位置,若不存在則返回 0(5)lpad 和 rpad
返回 len 長度的字符串,如果 str 不夠 len 的話,在左(右)填充 ch 這個(gè)字符
(5)trim:去掉首部和尾部的空格;中間的空格不去掉
select 'aaa'||trim(' hello world ')||'bbb' from dual;(6)trim(c from str):去掉 str 中的 c 字符
select trim('x' from 'xxxxxhello worldxxxxx') from dual;(7) replace(str, old, new):將 str 字符串中的 old 字符串替換成 new 字符串
select replace('hello world','llo','yy') from dual;(8)length 和 lengthb
select length('hello world') 字符數(shù), lengthb('hello world') 字節(jié)數(shù) from dual;總結(jié)
以上是生活随笔為你收集整理的Qracle学习:字符串相关函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qracle学习:排序
- 下一篇: Oracle学习:数值函数与转换函数