_Oracle数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

Oracle9i sql语句练习

作者:黑客防线网安Oracle维护基地 来源:黑客防线网安Oracle维护基地 浏览次数:0

--创建部门表 
create table 部门表
(
       部门编号 number(12) primary key not null,
       部门名称 varchar2(20) not null,
       部门所在地 varchar2(100) not null
);
--插入数据
insert into 部门表 values(10, ’总部’, ’神龙岛’);
insert into 部门表 values(20, ’技术部’, ’黑木崖’);
insert into 部门表 values(30, ’市场部’, ’光明顶’);
insert into 部门表 values(40, ’行政部’, ’嵩山’);

select * from 部门表;

--创建员工表
create table 员工表
(
    员工编号 number(12) primary key not null,
    员工姓名 varchar2(20) not null,
    员工职位 varchar2(20) not null,
    经理编号 number(4),
    入职日期 date default(sysdate) not null,
    基本工资 number(8,2) not null,
    奖金 number(8,2),
    部门编号 number(12)  references 部门表
);
--插入数据
insert into 员工表 values(7369, ’任盈盈’, ’职员’, 7902, to_date(’1980-12-17’,’yyyy-mm-dd’), 800, NULL, 20);
insert into 员工表 values(7499, ’杨逍’, ’销售人员’, 7698, to_date(’1981-2-20’,’yyyy-mm-dd’), 1600, 300, 30);
insert into 员工表 values(7521, ’范遥’, ’销售人员’, 7698, to_date(’1981-2-22’,’yyyy-mm-dd’), 1250, 500, 30);
insert into 员工表 values(7566, ’任我行’, ’经理’, 7839,to_date( ’1981-4-2’,’yyyy-mm-dd’), 2975, NULL, 20);
insert into 员工表 values(7698, ’张无忌’, ’经理’, 7839,to_date( ’1981-5-1’,’yyyy-mm-dd’), 2850, NULL, 30);
insert into 员工表 values(7782, ’苏荃’, ’经理’, 7839, to_date(’1981-6-9’,’yyyy-mm-dd’), 2450, NULL, 10);
insert into 员工表 values(7788, ’东方不败’, ’分析员’, 7566, to_date(’1982-12-9’,’yyyy-mm-dd’), 3000, NULL, 20);
insert into 员工表 values(7839, ’韦小宝’, ’总裁’, NULL, to_date(’1981-11-17’,’yyyy-mm-dd’), 5000, NULL, 10);
insert into 员工表 values(7844, ’紫衫龙王’, ’销售人员’, 7698, to_date(’1981-9-8’,’yyyy-mm-dd’), 1500, 0, 30);
insert into 员工表 values(7876, ’向问天’, ’职员’, 7788, to_date(’1983-1-12’,’yyyy-mm-dd’), 1100, NULL, 20);
insert into 员工表 values(7900, ’小昭’, ’职员’, 7698, to_date(’1981-12-3’,’yyyy-mm-dd’), 950, NULL, 30);
insert into 员工表 values(7902, ’令狐冲’, ’分析员’, 7566, to_date(’1981-12-3’,’yyyy-mm-dd’), 3000, NULL, 20);
insert into 员工表 values(7934, ’双儿’, ’职员’, 7782, to_date(’1982-1-23’,’yyyy-mm-dd’), 1300, NULL, 10);
insert into 员工表 values(7933, ’石中玉’, ’销售人员’, 7782, to_date(’1984-12-23’,’yyyy-mm-dd’), 2850, NULL, 10);

select * from 员工表;

--commit; --执行事务(执行事务后数据才会被保存)

--1、查询员工表所有数据
select * from 员工表;

--2、查询总裁的基本工资
select 员工职位,基本工资 from 员工表 where 员工职位 = ’总裁’;

--3、所有奖金为空或为0元的员工
select 员工姓名,奖金 from 员工表 where 奖金 = 0 or 奖金 is null;

--4、查询基本工资最高的三个人
select 员工姓名,基本工资,rownum from (select * from 员工表 order by 基本工资 desc ) where
rownum <= 3;

--5、查询入职日期在1981-5-1到1981-12-31之间的所有员工
select * from 员工表 where 
入职日期 between to_date(’1981-5-1’,’yyyy-mm-dd’) and to_date(’1981-12-31’,’yyyy-mm-dd’);

    黑客防线网安服务器维护方案本篇连接:http://shop.rongsen.com.cn/show-12678-1.html
网站维护教程更新时间:2012-03-23 00:44:34  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer