一、数据库语句
CREATE TABLE EMP (
EMPNO INT(4) NOT NULL PRIMARY KEY,
ENAME VARCHAR(10),
JOB VARCHAR(9),
MGR INT(4),
HIREDATE DATE,
SAL DECIMAL(7, 2),
COMM DECIMAL(7, 2),
DEPTNO INT(2)
);
CREATE TABLE DEPT (
DEPTNO INT(2) NOT NULL PRIMARY KEY,
DNAME VARCHAR(14),
LOC VARCHAR(13)
);
INSERT INTO EMP (EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO)
VALUES
(7369, 'SMITH', 'CLERK', 7902, STR_TO_DATE('1980-12-17', '%Y-%m-%d'), 800, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, STR_TO_DATE('1981-02-20', '%Y-%m-%d'), 1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, STR_TO_DATE('1981-02-03', '%Y-%m-%d'), 1250, 500, 30),
(7566, 'JONES', 'MANAGER', 7839, STR_TO_DATE('1981-03-02', '%Y-%m-%d'), 2975, NULL, 20),
(7654, 'MARTIN', 'SALESMAN', 7698, STR_TO_DATE('1981-10-22', '%Y-%m-%d'), 1250, 1400, 30),
(7698, 'BLAKE', 'MANAGER', 7839, STR_TO_DATE('1981-05-01', '%Y-%m-%d'), 2850, NULL, 30),
(7782, 'CLARK', 'MANAGER', 7839, STR_TO_DATE('1981-06-09', '%Y-%m-%d'), 2450, NULL, 10),
(7788, 'SCOTT', 'ANALYST', 7566, STR_TO_DATE('1982-12-09', '%Y-%m-%d'), 3000, NULL, 20),
(7839, 'KING', 'PRESIDENT', NULL, STR_TO_DATE('1981-11-17', '%Y-%m-%d'), 5000, NULL, 10),
(7844, 'TURNER', 'SALESMAN', 7698, STR_TO_DATE('1981-09-08', '%Y-%m-%d'), 1500, 0, 30),
(7876, 'ADAMS', 'CLERK', 7788, STR_TO_DATE('1983-01-12', '%Y-%m-%d'), 1100, NULL, 20),
(7900, 'JAMES', 'CLERK', 7698, STR_TO_DATE('1981-12-03', '%Y-%m-%d'), 950, NULL, 30),
(7902, 'FORD', 'ANALYST', 7566, STR_TO_DATE('1981-12-03', '%Y-%m-%d'), 3000, NULL, 20),
(7934, 'MILLER', 'CLERK', 7782, STR_TO_DATE('1982-01-23', '%Y-%m-%d'), 1300, NULL, 10)
INSERT INTO DEPT (DEPTNO, DNAME, LOC)
VALUES
(10, 'ACCOUNTING', 'NEW YORK'),
(20, 'RESEARCH', 'DALLAS'),
(30, 'SALES', 'CHICAGO'),
(40, 'OPERATIONS', 'BOSTON');
二、限定查询
SELECT EMPNO,ENAME,SAL
FROM EMP
WHERE SAL >1000 AND DEPTNO=30
SELECT DEPTNO, DNAME, LOC
FROM DEPT
WHERE DEPTNO=10
SELECT ENAME,JOB,SAL
FROM EMP
WHERE JOB='PRESIDENT'
SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO
FROM EMP
WHERE COMM > 0
SELECT EMPNO, ENAME
FROM EMP
WHERE ENAME LIKE'____'
SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO
FROM EMP
WHERE (DEPTNO = 10 AND JOB = 'MANAGER') AND (DEPTNO = 10 AND ENAME = 'CLERK')
SELECT JOB,SAL
FROM EMP
WHERE JOB = 'MANAGER'
SELECT EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO
FROM EMP
WHERE COMM > SAL
SELECT ENAME,SAL+NVL(COMM,0)
FROM EMP
WHERE ENAME LIKE'%S'
SELECT ENAME
FROM EMP
WHERE ENAME LIKE'__A%'
SELECT ENAME,SAL
FROM EMP
WHERE SAL < 1000 OR SAL > 2000
SELECT ENAME,JOB
FROM EMP
WHERE MGR IS NULL
三、函数
SELECT LENGTH(ENAME),EMPNO,ENAME
FROM EMP
SELECT LOWER(ENAME),EMPNO,ENAME
FROM EMP
SELECT ENAME,REPLACE(ENAME,'A','ABC')
FROM EMP
SELECT SUBSTR(ENAME,2,1)
FROM EMP
SELECT EMPNO,ENAME,SUBSTR(ENAME,2)
FROM EMP
SELECT EMPNO,ENAME,SUBSTR(ENAME,3,3)
FROM EMP
SELECT EMPNO,ENAME,INSTR(ENAME,'A')
FROM EMP
SELECT EMPNO,ENAME,SUBSTR(ENAME,INSTR(ENAME,'A'),2)
FROM EMP
WHERE ENAME LIKE'%A%'
SELECT REPLACE('abc,bdc,def',',',' ')
FROM DUAL
SELECT REPLACE('ABCDEFADE','A','m')
FROM DUAL
SELECT TRIM(' abcdef '),' abcdef '
FROM DUAL
SELECT LTRIM(' mnop'),' mnop'
FROM DUAL
SELECT RTRIM('nqwd '),'nqwd '
FROM DUAL
SELECT REPLACE('hi jk mno',' ','')
FROM DUAL
SELECT ASCII('D')
FROM DUAL
SELECT CHR(65)
FROM DUAL