/*Oracle查询语句*/

概念

select sysdate from dual; dual 临时的表,使语法结构完整,没有什么意义。 Oracle中的select语句必须要有from 而sql2008中可以没有。

sql语句和函数

起别名
--起别名(as起别名,不用加双引号. 加空格起别名,要加双引号)
select name as 姓名 from student where rownum<=2;
select name "姓名" from student where rownum<=2;
无重复行
--选择无重复的行,使用DISTINCT关键字
select distinct name from student
伪列
--伪列 rowed 固定为18个字母
select rowid,name,sex from student

序列号rownum

这里写图片描述

行号rownum
select name from student where rownum<=2;
select * from student where rownum<=2;
系统时间向后推一个月 sysdate 系统时间 dual 系统表名
select add_months(sysdate,1) from dual;
select add_months(sysdate,3) from dual;
系统日期与指定日期间相差的月份
select months_between(sysdate,date'2015-01-01') from dual;
select months_between(sdata,to_date('2015-01-01','2015-01-01')) from dual;
取指定日期的最后一天
select last_day(sysdate) from dual;
将指定时间舍入到指定的单位:yyyy,mm,dd,q
select round(sysdate,'mm') from dual;
select trunc(sysdate,'mm') from dual;

--四舍五入,取整
select round(100.5) from dual;
--舍去小数,取整。
select trunc(100.6) from dual;
字符函数
select rtrim(name,'炅') from student;
填充 lpad 左边填充 rpad 右边填充
select lpad('num',15,'=') from dual;
select lpad('num',15,'=!') From dual;
select rpad('num',15,'=!') From dual;
去掉所有的数字9 trim
select trim(9 from 9999876789999) from dual;
求字符长度
Select length('frances') from dual;
yyyy-mm-dd  hh24-mi-ss  年月日 时分秒
yy/yyy/yyyy
Mm/mon/month
dd—当月第几天
ddd—当年第几天
Dy /day   当周第几天
Q 季度
WW 当年的第几周
W     当月的第几周
hh    12小时制
hh24   24小时制
dy    当周第几天简写  
day  当周第几天全写  
用来转换空值
select nvl(sex,’性别’)from student;--如果字段为null,则显示值
select nvl2(sex,’非空’,‘为空’)from student ;

case 语句
select  num, case
when num<5 then '中等'
when 5<num and num<7 then '良好'
when 7<num then '高级'
else '顶级'
end
from student;
union 两个表中相同的去除 不显示重复
select *from student
union
select *from score;
--union all 全部显示 显示重复
select *from student
union all
select *from score;
intersect 操作符只返回两个查询的公共行
select num from student
intersect
select num from score;
minus 操作符返回从第一个查询结果中排除第二个查询中出现的行
select num from student
minus
select num from score;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值