日期:2014-05-16 浏览次数:20577 次
create table dept_xxx( deptno number(2), dname char(20), location char(20));
创建一个表。
插入如下代码
insert into emp_xxx values( 1001,'张无忌','Manager', 10000,2000,'12-7月-10',1005,10); insert into emp_xxx values( 1002,'刘苍松','Analyst', 8000,1000,'01-6月-11',1001,10); insert into emp_xxx values( 1003,'李翊','Analyst', 9000,1000,'11-6月-10',1001,10); insert into emp_xxx values( 1004,'郭芙蓉','Programmer', 5000,null,'01-1月-11',1001,10); insert into emp_xxx values( 1005,'张三丰','President', 8000,1000,'01-6月-11',null,20); insert into emp_xxx values( 1006,'燕小六','Manager', 5000,400,'01-2月-11',1005,20); insert into emp_xxx values( 1007,'陆无双','clerk', 3000,500,'01-6月-09',1006,20); insert into emp_xxx values( 1008,'黄蓉','Manager', 5000,500,'01-5月-09',1005,30); insert into emp_xxx values( 1009,'韦小宝','salesman', 4000,null,'20-2月-09',1008,30); insert into emp_xxx values( 1010,'郭靖','salesman', 4500,500,'10-5月-09',1008,30);
正确写法为:
select ename,salary,bonus, salary+nvl(bonus,0)month_sal from emp_xxx;nvl(d1,d2)方法演示,如果d1为null则用d2替代。 nvl函数的两个蚕食可以是数字,字符或日期,但两个
参数的数据类型必须一致。 指定字段插入値
insert into emp_xxx values(1011,'余则成',null,null,null,null,null,null);简写形式为:
insert into emp_xxx (empno,ename)values(1012,'姜涛');案例2
查询emp_xxx表,如果没有职位,显示'no position',
如果有职位,则显示员工的职位
select ename,nvl(job,'no position')from emp_xxx;
查询emp_xxx表,如果没有入职时间,则显示为
2000年01月01日
select ename,nvl(hiredate,'10-1月-01')from emp_xxx;案例4
复制表 复制表emp_yyy为emp_xxx
create table emp_yyy as select * from emp_xxx;案例4 distinct 关键字,
select distinct job from emp_xxx;
select distinct deptno from emp_xxx;
select distinct deptno,job from emp_xxx;
select * from emp_xxx where salary>=10000;
select * from emp_xxx where job='Analyst'; select * from emp_xxx where job='ANalyst';
select * from emp_xxx where lower(job)='analyst'; select * from emp_xxx where upper(job)='ANALYST';
select * from emp_xxx where salary between 1000 and 10000;
select * from emp_xxx where hiredate between'01-1月-11'and'31-12月-11';
select * from emp_xxx where job='Manager' or job='Analyst';