首页 > 技术文章 > oracle 常用sql函数

caihonghai 2021-02-02 17:12 原文

随手记

 

1、oracel的limit函数(12c+)

select * from xxx where a=b order by c offset 0 rows fetch next 1 rows only;
                                                               偏移从0开始 拿1条数据
 

2、结果列拼接成字符串

select  listagg(列, 连接符如chr(10) )within GROUP(order by 排序列) from xxx;

select  rtrim(xmlagg(XMLELEMENT(e,列,'').EXTRACT('//text()')).getclobval(),',') as 列名 from xxx;

select  xmlagg(xmlparse(content 列||' ' wellformed) order by 排序列).getclobval() as 列名 from xxx;

 

3、oracel的输出

DBMS_OUTPUT.PUT_LINE(输出内容);

 

4、like模糊查询忽略大小写

select * from  xxx  where regexp_like(列 ,'匹配字符','i')  ;  i表示忽略大小写

 

5、去掉字符串最后的换行

select   rtrim(rtrim(列,chr(13) ) ,chr(10)) from xxxx;

 

6、先排序后rownum

select row_number() over(order by 排序列) 别名, a.* from ps_user a;

 

7、填充0,如把5转为0005

select LPAD(列,4,'0') from xxxx;

 

8、截取空格前的字符串,如 aaxx rree截取aaxx

 select  substr(列,0,instr(列,' ')-1)  from xxxx t where xxxx=xxxx;

 

 

 

 

推荐阅读