本文整理自网络,侵删。
本文主要介绍的是关于Oracle中的简单查询和限定查询,下面话不多说,来一起看看吧。
SQL:
1,DML(数据操作语言):主要指的是数据库的查询与更新的操作,查询操作是整个sql语法 中最麻烦也是笔试中最常用的部分。
2,DDL(数据定义语言):主要指的是数据对象的创建(表、用户、)例如:creat.需要相关的设计范式。
3,DCL(数据控制语言):主要进行权限的操作(需要结合用户来观察),此部分由DBA负责。
简单查询:
1,利用select
子句控制要显示的数据列:
select empno,ename,ename,job,sal from emp;
2,可以使用distinct
来消除重复的数据行显示:
select distinct job from emp;
3,select
子句可以进行四则运算,可以直接输出常量内容,但是对于字符串使用单引号数字直接编写,日期格式按照字符格式:
select empno,ename,(sal*15+(200+100)) income from emp;
4,||负责输出内容连接此类的操作很少直接在查询中出现:
select empno||ename from emp;
5,where
子句一般都写在from
子句之后,但是是紧跟着from
子句之后执行的,where
子句控制显示数据行的操作,而select
控制数据列,select
子句要落后于where
子句执行,所以在select
子句之中定义的别名无法在where
中使用。
限定查询:
1,关系运算符:
select * from emp where sal>1500; select * from emp where ename ='SMITH' select empno,ename,job from emp where job<>'SALESMAN';
2,逻辑运算符:
select * from emp where sal>1500 and sal<3000; select * from emp where sal>2000 or job='CLERK'; select * from emp where not sal >=2000;
3,范围查询:
select * from emp where sal between 1500 and 2000; select * from emp where hiredate between '01-1月-1981'and'31-12月-1981';
4,空判断(空在数据库上表示不确定,如果在数据列使用null不表示0)
select * from emp where comm is not null;
5,IN操作符(类似于between and
而in给出的是指定的范围):
select * from emp where empno in (7369,7566,7788,9999);
关于not in
与null
的问题:
在使用not in
进行范围判断的时候,如果范围有null
,那么不会有任何结果返回。
6,模糊查询:
“-”:匹配任意一位字符;
“%”:匹配任意的0,1,,或者多位字符;
相关阅读 >>
[oracle] data guard cpupsu补丁安装详细教程
更多相关阅读请进入《oracle》频道 >>
数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。