Oracle数据库的n基本sql语句


一、SQL  简介

SQL 全名是结构化查询语言(Structured Query Language),是用于数据库中的标准数据查
询语言,IBM 公司最早使用在其开发的数据库系统中。1986 年 10 月,美国 ANSI 对 SQL
进行规范后,以此作为关系式数据库管理系统的标准语言 (ANSI X3. 135-1986),1987 年
得到国际标准组织的支持下成为国际标准。不过各种通行的数据库系统在其实践过程中都
对 SQL 规范作了某些编改和扩充。所以,实际上不同数据库系统之间的 SQL 语言不能完
全相互通用
DML 语句(数据操作语言)Insert、Update、 Delete、Merge
DDL 语句(数据定义语言)Create、Alter、 Drop、Truncate
DCL 语句(数据控制语言)Grant、Revoke

事务控制语句 Commit 、Rollback、Savepoint


二、入门语句

1.创建表空间:create tablespace 表空间名 logging datafile  'E:\oracle\product\10.2.0\oradata\orcl\tf27.dbf' size 64m autoextend on next 16m maxsize unlimited extent  management local;

2.创建用户:create user 用户名 identified by 密码 default tablespace 表空间名 temporary tablespace temp;

3.用户授权:grant dba,connect to 用户名;

4.普通用户连接:conn 密码/账号

5..超级管理员连接: conn “sys/sys as sysdba”

6.断开连接:Disconnect; 

7.退出:quit;

8.创建表create table emp(id number,name varchar(20),pass number);

9.添加数据:insert into emp (id,name,sal) values (1,'xzt',12344);

10.修改数据:update emp set name='冼焯庭' where id=1;把id为1的员工名字改为冼焯庭;

11.描述 Emp 表结构:desc emp; 

12.查看该用户下的所有对象:Select * from emp; 

13.删除表一条数据:detele from emp where id=1;

14.删除表:drop table 表名;

15. 显示当前用户:Show user;

16.分页查询:select t.*,rownum from (select user1.*,rownum from user1 where rownum<=3 order by rownum desc) t                       where rownum<=3 order by id  第一页

                   select t.*,rownum from (select user1.*,rownum from user1 where rownum<=6 order by rownum desc) t                         where rownum<=3 order by id  第二页


三、练习

1.选择在部门 30 中员工的所有信息

Select * from emp where deptno=30;

2.列出职位为(MANAGER)的员工的编号,姓名

Select empno,ename from emp where job = 'Manager';

3.找出奖金高于工资的员工

Select * from emp where comm>sal;

4.找出每个员工奖金和工资的总和

Select sal+comm,ename from emp;

5.找出部门 10 中的经理(MANAGER)和部门 20 中的普通员工(CLERK)

Select * from emp where (deptno=10 and job=‟MANAGER‟) or (deptno=20 and job=‟CLERK‟);

6.找出部门 10 中既不是经理也不是普通员工,而且工资大于等于 2000 的员工

Select * from emp where deptno=10 and job not in(„MANAGER‟,‟CLERK) ‟ and sal>=2000;

7.找出有奖金的员工的不同工作

Select distinct job from emp where comm is not null and comm>0;

8.找出没有奖金或者奖金低于 500 的员工

Select * from emp where comm<500 or comm is null;

9.显示雇员姓名,根据其服务年限,将最老的雇员排在最前面
select ename from emp order by hiredate

猜你喜欢

转载自blog.csdn.net/superXZT/article/details/79836533