您的位置:首页 > 数据库 > Oracle

oracle基础:使用字符串

2015-04-21 19:33 106 查看
--提取字符 substr(字段,开始位置,提取字符个数)    replace(字段,查找字符,被替换成的字符串)

select substr(b.book_author,1,1) as 作者的姓   from book b;

select replace(b.book_name,'<<','') as 书名   from book b;

--使用正则表达式  regexp_replace(字段,正则表达式,被替换成的字符串)   regexp_like(字段,正则表达式);

/* 注意:^ 字符串开始, $字符串结束   regexp_like(b.book_name,'^A');  等价于 like 'A%' */

select  regexp_replace(b.book_name,'\<<|\>>','') as 书名   from book b;

select * from book b where b.book_name like '%平凡的%';

select * from book b where   regexp_like(b.book_name,'平凡的|孙子');

--分析函数listagg(字段,'连接符')或者 wmsys.wm_concat(字段)的运用

select deptno as 部门编号,

       sum(sal) as 工资合计,

       wmsys.wm_concat(ename)  as 部门全部员工姓名

from emp  group by deptno;

--将ip地址分离

select regexp_substr(v.ip,'[^.]+',1,1) a,

       regexp_substr(v.ip,'[^.]+',1,2) b,

       regexp_substr(v.ip,'[^.]+',1,3) c,

       regexp_substr(v.ip,'[^.]+',1,4) d

 from (select '192.168.1.110' as ip from dual) v;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle sql