1. 程式人生 > >Oracle計算單個字元在字串中出現的次數

Oracle計算單個字元在字串中出現的次數

計算單個字元在字串中出現的次數: select length('HELLO WORLD!')-length(replace('HELLO WORLD!','L','')) from dual;

--計算單個字元在字串中出現的次數: select length('10-11-30-22:dbsaleinst1_138-FRA')-length(replace('10-11-30-22:dbsaleinst1_138-FRA','-','')) from dual; --擷取最後一個'-'後面的字串 select substr('10-11-30-22:dbsaleinst1_138-FRA',instr('10-11-30-22:dbsaleinst1_138-FRA','-',1,(length('10-11-30-22:dbsaleinst1_138-FRA')-length(replace('10-11-30-22:dbsaleinst1_138-FRA','-',''))))+1,50) instring from dual;