oracle 高级查询一

聚合函数

select max(stu_score),min(stu_id),avg(stu_score),sum(stu_score),count(stu_id) from student;

转换为字符:

select to_char(sysdate,'yyyy-mm-dd') from dual;

转换为日期:

select to_date('2017-08-20','yyyy-mm-dd') from dual;

日期相减:

select to_date('2017-08-20','yyyy-mm-dd')-sysdate from dual;

查询指定字符在字符串中的下标

select instr('this is a str','i') from dual;

截取字符串从指定下标开始

select substr('this is a str',6) from dual;

截取字符串从指定下标取对应个数

select substr('this is a str',5,2) from dual;

转换为数字:

select to_number('1021') from dual;

从左开始填充,填充位数为6-字符串位数,填充内容为第三个参数

select lpad('aa',6,'-') from dual;

查询两个日期间的月数

select months_between(sysdate,to_date('2017-01-01','yyyy-mm-dd')) from dual;

向下取整

select floor(20.5) from dual;

向上取整

select ceil(20.5) from dual;

四舍五入

select round(20.5) from dual;

取指定位数

select trunc(100.5555,1) from dual;

生成随机数并取整

select floor(dbms_random.value(100,1000)) from dual;

生成0-1间的随机

select dbms_random.value from dual;

替换字符串中的字符

update card set id=replace(id,'i','1');

替换字符,嵌套写法

update card set id=replace(replace(id,'d','kk'),'f','dd');

给12-13,13-15,15-14...........排序

select listnumber from student order by o_number(substr(listnumber,1,instr(listnumber,'-')-1)),to_number(substr(listnumber,'-')+1));

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...