ORACLE

--;代表sql的结束,是给工具看的,不是数据库看的,sql语法本身不需要
----DQL 查询语句
--select * from 数据源;--查询某一个数据源中的所有字段值
--select 字段名 from 数据源;--查询某一个数据源中的指定字段值
--select 字段1,字段2,字段名3... from 数据源;--查询某一个数据源的多个字段的所有值
--select distinct 字段 from 数据源;--去重,对结果集中完全相等的两条数据只显示一条
--表达式 eg:3*5 select 3*5 from 表;
--伪列:表结构中没有真实存在,但是可查。(表达式/整数/字符串就是一种伪列)
--字符串''--单引号--字符串的拼接 字符串||字符串
select 'tl-'||'oracle' from dual;
--别名 
--【字段的别名】  select 字段 (as) 别名,字段  别名... from 数据源;
--【表的别名】   from 数据源1 别名,数据源2 别名...;
--注:若别名不合法或者需要原封不动的显示,别名前后添加双引号""
select 'tl-'||'oracle' "别  名" from dual;
--虚表:方便查询使用 dual
--关于NULL 值 --字段值没有值,默认为null
--null与数字运算结果为null,null与字符串运算结果为原串
--处理null值 : nvl(值1,值2) 当值1为null nvl 的结果为值2,当值1不为null,nvl函数结果为值1
--条件查询:select 数据 from 数据源 where 行过滤条件;
--where 条件:= ;>; < ;>=;<=;!=;<>;between and (闭区间);and ;not ;or
--注:where 后面不能使用字段的别名可以使用表的别名,执行流程的问题;
--字符串严格区分大小写
--判断是否为null --is null ---is not null
---集合函数
--union 并集去重
--union all 并集不去重
--intersect 交集
--minus 差集
---模糊查询 like ;% 任意个字符 ;_一个任意字符;escape('\')指定转义字符
select * from emp where ename like '%M%';--包含M;
select * from emp where ename like '_M%';--第二位为M;
select * from emp where ename like '%\%%' escape('\') ;
--in(值列表)
select * from emp where sal in (1250,1500,2500,5000);
--=select  * from emp where sal =1250 or sal =1500 or sal =2500 or sal =5000
--定值查找效率更高
--in(select ...)[子查询]【查询语句嵌套查询语句】
--exist 存在就保留[效率比子查询高些]
select * from emp where exists(select deptno from dept where deptno=10);--只要exists()的查询能查到结果,from后面的结果就都保留;
---排序 order by 默认升序--desc 降序;-- nulls last null值在最后;--nulls first null值在最开始;
select * from emp order by sal desc nulls last;
select * from emp order by sal,comm desc;--若sal 一样 按comm降序排序 
---函数
--单行函数【一条记录返回一个结果】
--常用函数
select sysdate from dual;--当前日期;
select current_date from dual;--当前日期;
select sysdate+2 from dual;--两天后;
select add_months(sysdate,3) from dual;--三个月后add_months;
select trunc(months_between(sysdate+2,sysdate))from dual;--months_between 两个日期之间的月数;trunc()对()中的数取整;round(数据,几位小数);
select round(months_between(sysdate+2,sysdate),2)from dual;--round(数据,几位小数)四舍五入;
select last_day(sysdate) from dual; --查询当前月的最后一天;
select next_day(sysdate,3)from dual;--下一周的第3天是几号--周日是一周的第一天,周1是第二天...;
to_date(日期字符串,'模板')--转换成日期
select to_date('2002-12-05 10:35:32','yyyy-mm-dd hh12:mi:ss') from dual;
to_char(日期对象,'模板')--转换成字符串
select to_char(sysdate,'yyyy"汉字"mm"作为"dd"分隔" hh12:mi:ss') from dual;--想用汉字作为分隔用双引号
--多行函数|组函数|聚合函数【多条记录返回一个结果】max();min();count();sum();avg();
--若使用了组函数则要和其他组函数或分组字段[group by 分组字段1,分组字段2... having -组过滤信息-]一起使用!
--注:分组后只能使用分组字段或组函数,无法知道每组有几条数据,存在什么字段是什么值--where 后不能使用组函数
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值