ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Oracle常用函数(略微少了点 不过是自己稍微整理的)

2019-12-20 09:01:53  阅读:297  来源: 互联网

标签:略微 return 稍微 999 char dual Oracle n1 select


DECODE

​ DECODE(value ,if 1, then 1,if 2,then 2, ....,else)

​ 解析:

​ if 条件=1

​ return (value 1)

​ if条件=2

​ return (value 2)

​ else

​ return (default)

NVL

​ NVL(n1 ,n2)

解析:

​ if n1==null return n2 else return n1

​ if n1==null and n2==null return null

NVL2

解析:

​ NVL2(n1,n2,n3)

​ if n1==null return NVL2()==n3 else return NVL2()==n2

NULLIF

​ NULLIF(n1,n2)

解析:

​ if n1==n2 return null else return n1

SUM

​ 计算数据总和

SUBSTR

1、SUBSTR(string string, int a, int b)
参数1: String要处理的字符串
参数2: a 截取字符串的开始位置(起始位置是0)
参数3: b 截取的字符串的长度(而不是字符串的结束位置)
例如:
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, 3); //返回:EFG,注意参数-3,为负值时表示从尾部开算起,字符串排列位置不变。

TO_CHAR

一、日期格式转换

  **to_char(date,'格式');**

```
`select to_date(``'2005-01-01 '``,``'yyyy-MM-dd'``) from dual;``select to_char(sysdate,``'yyyy-MM-dd HH24:mi:ss'``) from dual;`  
```

二、数字格式转换

**to_char(number,'格式');**

```
`select to_char(``88877``) from dual;``select to_char(``1234567890``,``'099999999999999'``) from dual;``select to_char(``12345678``,``'999,999,999,999'``) from dual;``select to_char(``123456``,``'99.999'``) from dual;``select to_char(``1234567890``,``'999,999,999,999.9999'``) from dual;`
```

三、金钱格式转换

**to_char(salary,'$99,99');**

```
`select TO_CHAR(``123``,``'$99,999.9'``) from dual;`
```

四、**进制转换:10进制转化为16进制**

```
`select to_char(``4567``,``'xxxx'``) from dual;``select to_char(``123``,``'xxx'``) from dual;`
```

 

WM_CONCAT
实现行转列功能,即将查询出的某一列值使用逗号进行隔开拼接,成为一条数据。相当于group_concat

标签:略微,return,稍微,999,char,dual,Oracle,n1,select
来源: https://www.cnblogs.com/-821L/p/12071265.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有