Ref:
http://www.w3school.com.cn/sql/sql_dates.asp
https://blog.csdn.net/qq_20989105/article/details/76190566
Build:
sqlplus Jsj202/Jsj123456@orcl
CREATE TABLE DEPT(DEPTNO INT PRIMARY KEY, DNAME VARCHAR2(14), LOC VARCHAR2(13) );
Insert into DEPT values(10,'ACCOUNTING','LONDON');
Insert into DEPT values(20,'RESEARCH','PERSON');
Insert into DEPT values(30,'SALES','LIVERPOOL');
----------------------------------
CREATE TABLE EMP(EMPNO NUMBER(4) PRIMARY KEY, ENAME VARCHAR2(10), JOB VARCHAR2(9) , MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPTNO NUMBER(2));
//ALTER TABLE EMP ADD HIREDATE date;
//DROP TABLE EMP;
/*?? ALTER TABLE EMP ALTER COLUMN HIREDATE VARCHAR2;*/
Insert into EMP VALUES(7698,'BLAKE','MANAGER',7839,TO_DATE('01-05-95','DD-MM-YY'),2500,null,30);
Insert into EMP VALUES(7782,'CLARK','MANAGER',7839,TO_DATE('09-06-92','DD-MM-YY'),2750,NULL,10);
Insert into EMP VALUES(7839,'KING','PRESIDENT',NULL,TO_DATE('18-11-88','DD-MM-YY'),8750,NULL,20);
Insert into EMP VALUES(7369,'SMITH','CLERK',7902,TO_DATE('18-12-99','DD-MM-YY'),1115,640 ,20);
--------------------------------------
CREATE TABLE SALGRADE(GRADE NUMBER,LOSAL NUMBER,HISAL NUMBER);
INSERT INTO SALGRADE VALUES(1,700,1200);
INSERT INTO SALGRADE VALUES(2,1201,1400);
INSERT INTO SALGRADE VALUES(3,1401,2000);
INSERT INTO SALGRADE VALUES(4,2001,3000);
INSERT INTO SALGRADE VALUES(5,3001,9999);
Select:
用SQL语句实现如下查询:
Select DNAME,ENAME,SAL From DEPT,EMP Where DEPT.DEPTNO=10 AND DEPT.DEPTNO=EMP.DEPTNO;
SELECT A.ENAME FROM EMP A, EMP B WHERE B.ENAME='BLAKE' AND B.MGR=A.EMPNO;
SELECT A.EMPNO,A.ENAME,A.JOB,A.MGR,A.HIREDATE,A.SAL,A.COMM,A.DEPTNO FROM EMP A, EMP B WHERE B.ENAME='SCOTT' AND B.DEPTNO=A.DEPTNO;
SELECT A.EMPNO,A.ENAME,A.JOB,A.MGR,A.HIREDATE,A.SAL,A.COMM,A.DEPTNO FROM EMP A, EMP B WHERE B.ENAME='SMITH' AND B.DEPTNO=A.DEPTNO;
SELECT A.ENAME,A.SAL,A.DEPTNO FROM EMP A WHERE NOT EXISTS(SELECT B.SAL FROM EMP B WHERE B.DEPTNO=30 AND B.SAL>=A.SAL);
SELECT A.ENAME FROM EMP A,EMP B WHERE B.ENAME='SMITH' AND A.JOB=B.JOB AND A.DEPTNO=B.DEPTNO;
SELECT * FROM EMP A WHERE A.SAL > (SELECT AVG(SAL) FROM EMP B);
? SELECT * FROM EMP WHERE EMP.SAL>(SELECT SUM(SAL) FROM EMP B)*(1/3);
? SELECT * FROM EMP EXCEPT EMP.SAL<=2000 ;GROUP BY DEPTNO;
?
Insert into EMP VALUES(1357,'oracle',NULL,NULL,TO_DATE('10-05-18','DD-MM-YY'),2050,NULL,20);
请选择“平面设计”系统
sqlplus user/password@orcl
一、 基本实验内容:
(一). 在自己用户下面创建DEPT、EMP、SALGRADE三个表对象,要求使用SQL语句创建,并将SQL语句用文本保存。其中,
DEPT是部门信息表,包括:部门编号、部门名称、部门地址三个属性,即DEPT(DEPTNO,DNAME,LOC)。
EMP是员工信息表,包括:员工编号、员工姓名、职位、上级领导、雇用时间、薪金、佣金、所属部门编号八个属性,即EMP(EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)。
SALGRADE是工资等级表,包括:工资等级、最低工资、最高工资三个属性,即SALGRADE(GRADE,LOSAL,HISAL)。
DEPT:
DEPTNO PK
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
DEPTNO DNAME LOC
10 ACCOUNTING LONDON
20 RESEARCH PERSTON
30 SALES LIVERPOOL
EMP:
EMPNO PK NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7698 BLAKE MANAGER 7839 01-MAY-95 2500 30
7782 CLARK MANAGER 7839 09-JUN-92 2750 10
7839 KING PRESIDENT 18-NOV-88 8750 20
7369 SMITH CLERK 7902 18-DEC-99 1115 640 20
SALGRADE(GRADE,LOSAL,HISAL)。
GRADE NUMBER
LOSAL NUMBER
HISAL NUMBER
GRADE LOSAL HISAL
1 700 1200
2 1201 1400
3 1401 2000
4 2001 3000
5 3001 9999
(要求定义各表的完整性约束。)
(二)用SQL语句实现如下查询:
三、
Create table t as select * from all_objects;
Create index idx_object_id on t(object_id);
Set autotrace on
Set linesize 1000
Set timing on
Select object_name from t where object_id=29;
Select object_name from t where object_id=29;执行两遍,对比执行时间以及统计信息变化的区别,前后两次执行差异非常大,分析原因。