当前位置:网站首页>Oracle-单行函数大全
Oracle-单行函数大全
2022-06-25 08:13:00 【旷世奇才李先生】
工欲善其事必先利其器
文章持续更新,可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。

一、字符串函数
转换为大写函数:upper
转换为小写函数:lower
首字母变为大写:initcap
计算字符串长度:length
字符串替换:replace(类,要替换的值,替换为值)
字符串截取:substr(列,起始点,长度)
1、查询学生的姓名并大写
select upper(name) from student;
2、查询学生的姓名并小写
select lower(name) from student;
3、将"helloword"首字母大写
注意dual是oracle自带的一张表
select initcap('helloword') from dual;
结果:Helloword
4、查询所有的学生姓名并首字母大写
以下两种都可以
select initcap(name) from student;
5、查询所有学生的姓名,并显示姓名的长度
select name, length(name) from student;
6、查询所有学生的姓名,并将“张三”改为“李四”
select replace(name,'张三','李四') from student;
7、将"hello word"中的空格去除
select replace('hello word',' ','') from dual;
9、查询出所有学生的姓氏
注意,截取字符初始是从1开始的,如果初始值写为0也会默认从1开始
select substr(name,1,1) from student;
二、数值函数
四舍五入:round(数据,保留小数位)
直接截取小数位,不进行四舍五入:trunc(数据,保留小数位)
取模函数:mod(被除数,除数)
1、将123.4567保留两位小数
select round(123.4567,2) from dual;
结果:123.46
2、将123.4567保留小数点前两位,小于5的舍去
select round(123.4567,-2) from dual;
结果:100
3、将-123.65取整数
select round(-123.65) from dual;
结果:-124
4、将123.4567直接截取为两位小数
select trunc(123.4567) from dual;
结果:123.45
5、将-123.65直接截取为整数
select trunc(-123.65) from dual;
结果:-123
6、将10与3取模
select mod(10,3) from dual;
结果:1
三、日期函数
oracle自带的当前日期数据列:sysdate
计算两个日期之间相差的月份:months_between(日期1,日期2)
增加若干月后的日期:add_months(日期,月数)
查询当月的最后一天:last_day(日期)
计算下一个指定的日期:next_day(日期,一周时间数)
1、查询当前日期
注意:这里查询的是oracle数据库所安装在的电脑上的日期,比如oracle安装在服务器上,这样你用自己本地的电脑远程查询数据库的日期和自己本机电脑日期会有差距,一般为1分钟左右。
select sysdate from dual;
2、查询三天后的日期
select sysdate + 3 from dual;
3、查询两个日期之间相差的月数
select months_between(date1,date2) from dual;
4、查询两个日期之间相差的年数
select trunc(months_between(date1,date2)/12) years from dual;
5、查询当前日期5个月后的日期
select add_months(sysdate,5) from dual;
6、查询当月的最后一天
select last_day(sysdate) from dual;
7、查询下个星期三
select next_day(sysdate,'星期三') from dual;
四、转换函数
转换为字符串:to_char()
转换为日期:to_date()
转换为数字:to_number()
1、将当前日期格式化为yyyy-mm-dd格式的字符串
select to_char(sysdate,'yyyy-mm-dd') from dual;
2、查询当前日期的年份
select to_char(sysdate,'yyyy') year from dual;
3、将“1998-09-27”转换为日期格式
select to_date('1998-09-27','yyyy-mm-dd') from dual;
4、将“1”转换为数字格式
select to_number('1') from dual;
五、通用函数
如果为空则使用定义的值,如果不为空则用原来的值:nvl(列,定义值)
多值判断:decode(列,匹配内容1,显示内容1,匹配内容2,显示内容2)
1、查询同学的姓名,如果姓名为空就用“张三”代替
select nvl(name,'张三') from student;
2、查询同学年龄为空的就用0代替
select nvl(age,0) from student;
3、查询学生的性别,并将“男”对应“man”,将“女”对应“woman”
select decode(sex,'男','man','女','woman') from student;
六、总结
这里的相关内容还没有整理完毕,文章后面持续更新,建议收藏。
文章中涉及到的命令大家一定要像我一样每个都敲几遍,只有在敲的过程中才能发现自己对命令是否真正的掌握了。
可以微信搜索【小奇JAVA面试】第一时间阅读,回复【资料】获取福利,回复【项目】获取项目源码,回复【简历模板】获取简历模板,回复【学习路线图】获取学习路线图。
边栏推荐
- Exchange:管理日历权限
- 二、训练fashion_mnist数据集
- Is it safe to open an account at Huatai Securities?
- Check whether the point is within the polygon
- Exchange: manage calendar permissions
- Hyper-v:hyper-v generation 1 or generation 2 virtual machines
- 声纹技术(七):声纹技术的未来
- 《乔布斯传》英文原著重点词汇笔记(六)【 chapter three 】
- Find the nearest common ancestor (Sword finger offer) of two nodes in the binary tree (search tree)
- How annotation lib and processor lib reference
猜你喜欢

cazy长安战役八卦迷宫

浏览器查看当前页面所有的监听事件

C language: find all integers that can divide y and are odd numbers, and put them in the array indicated by B in the order from small to large

Meaning of Jieba participle part of speech tagging

wav文件(波形文件)格式分析与详解

Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an

How to solve the 10061 error of MySQL in Linux

Unity--Configurable Joint——简单教程,带你入门可配置关节

C#启动程序传递参数丢失双引号,如何解决?

C#程序终止问题CLR20R3解决方法
随机推荐
Software engineering review questions
Advanced technology Er, meet internship position information
ICer必须知道的35个网站
jmeter中csv参数化
[MySQL] understanding of transactions
IC研发常用英文术语缩写
What is the difference between TP5 and tp6?
声纹技术(三):声纹识别技术
How to design test cases
获取扫码的客户端是微信还是支付宝
View all listening events on the current page by browser
106. 简易聊天室9:使用 Socket 传递音频
配置、软件配置项、软件配置管理项辨析
Analysis of a video website m3u8 non perceptual encryption
如何实现一个系统调用
atguigu----01-脚手架
对常用I/O模型进行比较说明
Unknown table 'column of MySQL_ STATISTICS‘ in information_ schema (1109)
Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed
WebGL发布之后不可以输入中文解决方案