1基本查询
1.1语法格式
1.2案例
- select * from employee;
- select id, name,salary from employee;
- select id as 员工号, name 姓名,salary 月薪,salary*12 年薪 from employee;
- 在使用别名中
- as 可以省略
- 如果别名中有空格需要使用" "引起来。
1.3特殊函数和关键字
1.3.1nvl()函数
- select id as 员工号, name 姓名,nvl(salary,0) 月薪,salary*12 年薪 from employee;
- 因为包含NULL的表达式都会为空 ,导致整个查询语句都为空,所以查询的行有一个列为空都无法查到整个行
- 解决方法:nvl(a,b) 若a为NULL 则去b值
1.3.2distinct
SELECT distinct sname,salary from class;
1.4 注意点
1.4.1查询系统当前日期
- select sysdate from dual;
- dual 是个伪表 主要是为了满足sql语法的规定
1.4.2C
- 在编写sql语句是,出现语法错误 则可以用C
1.4.3保存查询结果
-- 地址加文件名
spool D:\result;
select * from emp;
spool off;
2where条件
2.1where后面使用比较运算符
> < = != (< >) between and
select * from employee where name