一、拼接字符串oracle
1)能夠使用「||」來拼接字符串函數
select '拼接'||'字符串' as str from dual
2)經過concat()函數實現spa
select concat('拼接', '字符串') as str from dual
注:oracle的concat函數只支持兩個參數的方法,即只能拼接兩個參數,如要拼接多個參數則嵌套使用concat可實現,如:code
select concat(concat('拼接', '多個'), '字符串') from dual
二、截取字符串blog
SUBSTR(string,start_position,[length]) 求子字符串,返回字符串
解釋:string 源字符串
start_position 開始位置(從0開始)
length 可選項,子字符串的個數字符串
select substr(to_char(sysdate, 'yyyy-mm-dd HH:mi:ss'), 12, 5) as time from dual
substr("ABCDEFG", 0); //返回:ABCDEFG,截取全部字符 substr("ABCDEFG", 2); //返回:CDEFG,截取從C開始以後全部字符 substr("ABCDEFG", 0, 3); //返回:ABC,截取從A開始3個字符 substr("ABCDEFG", 0, 100); //返回:ABCDEFG,100雖然超出預處理的字符串最長度,但不會影響返回結果,系統按預處理字符串最大數量返回。 substr("ABCDEFG", -3); //返回:EFG,注意參數-3,爲負值時表示從尾部開始算起,字符串排列位置不變。
字符串 "AAA-BBB" 截取"AAA" "BBB"string
select substr('AAA-BBB',1,instr('AAA-BBB','-',-1)-1) 值 from dual;
select substr('AAA-BBB',instr('AAA-BBB','-',-1)+1) 值 from dual;
三、查找字符串it
INSTR(string,subString,position,ocurrence)查找字符串位置io
解釋:string:源字符串
subString:要查找的子字符串
position:查找的開始位置
ocurrence:源字符串中第幾回出現的子字符串class
select INSTR('CORPORATE FLOOR','OR', 3, 2) as loc from dual
四、替換字符串
replace(strSource, str1, str2) 將strSource中的str1替換成str2
解析:strSource:源字符串
str1: 要替換的字符串
str2: 替換後的字符串
select '替換字符串' as oldStr, replace('替換字符串', '替換', '修改') as newStr from dual
五、長度
length(nvl(字段,''))=1
六、判斷
SELECT SBXH, SFZJHM, case when length(nvl(XM,''))=1 then XM when length(nvl(XM,''))=2 then substr(XM, 0, 1)||'*' when length(nvl(XM,''))=3 then substr(XM, 0, 1)||'**' when length(nvl(XM,''))=4 then substr(XM, 0, 1)||'***' else substr(XM, 0, 1)||'****' end XM, DJXH, SDNF, DWMC, YNSE FROM ZHZS_SEWSR T WHERE YNSE > 120000.000000 AND DWMC IS NOT NULL AND SFZJHM LIKE '36%' ORDER BY YNSE DESC