以下三个查询语句的结构是相同的:
Select * from emp where job!=’CLERK’;
Select * from emp where job<>’CLERK’;
Select * from emp where not job=’CLERK’ --这三种语法都可以在 SQL Server 中使
用;
对 between and 求反:
Select * from emp where not sal between 1500 and 3000
Between and 不只是对数据,对日期也一样进行操作;
Select * from emp where hiredate between ’01-1 月-1981’ and ’31-12 月-81’
Set linesize 300;
Set pagesize 200;
★ 对于 like 操作符,不止可以用于字符串型的数据,而且可以用于其他类型的数据;
★ Order by 子句是写在所有语句最后的子句;
★ INITCAP 函数,将字符串首字母变为大写;→而所有剩余的字母会变成小写;
★ Oracle 数据库中为了查询的方便,专门提供了一个 dual 的虚拟表,这样 from 后边便
可以跟这个表名进行查询;
★ Select * from emp where ename=UPPER(‘&hh’);中的单引号中间的字符表示一
个变量,下一步系统会让用户输入该变量的值,然后系统进行查询:结果图如下:
★ SQL> select * from emp where ename=upper('&hh');
★ 输入 hh 的值: smith
★ 原值 1: select * from emp where ename=upper('&hh')
★ 新值 1: select * from emp where ename=upper('smith')
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 17-12 月-80 800 20
★ 字符串操作有两种方式:
语法一:substr(字符串,开始点)表示截取该字符串从开始点一直到结尾的部分;
语法二:substr(字符串,开始点,结束点)
截取字符串倒数三个字符:
除了可以用 length(字符串)-2 以外,还可以使用负数表示:
SQL> select substr(ename,-3) from emp;
SUBSTR
------
ITH
LEN
ARD
NES
TIN