1.用sqlplus连接数据库时,为什么会出Oracle not available错误?Oracle server(即通常所说的数据库)是否启动,ORACLE_SID是否正确设置。
2.找出员工的姓中(last_name)第三个字母是a的员工名字select last_name from s_emp where last_name like '_ _a%';3.找出员工名字中含有a和e的select first_name from s_emp where first_name like '%a%' and first_name like '%e%';比较:select first_name from s_emp where first_name like '%a%e%';此种方式查询出来的数据,只是先出现“a”然后出现“e”的数据表记录。
总的记录条数可能少于第一种方式的。
4.找出所有有提成的员工,列出名字、工资、提出,显示结果按工资从小到大,提成从小到大.select first_name,salary,commission_pct from s_emp where commission_pct is not null order by salary desc,commission_pct;5.42部门有哪些职位select distinct title from s_emp where dept_id=42;6.哪些部门不是Sales部select id,name,region_id from s_dept where name <> 'Sales';注意大小写!7.显示工资不在1000到1550之间的员工信息:名字、工资,按工资从大到小排序。
select first_name,salary from s_emp where salary not between 1000 and 1550 order by salary desc;需要使用到not between and 函数,不能使用salary > 1550 and salary <10008.显示职位为Stock Clerk和Sales Representative,年薪在14400和17400之间的员工的信息:名字、职位、年薪。
select first_name,title,salary*12 ann_sal from s_emp where title in ('Stock Clerk','Sales Representative') and salary between 1200 and 1450;注意把年薪的范围换算成了每月的工资salary,而不是salary*12。
以提高查询效率。
9.解释select id,commission_pct from s_emp where commission_pct is null和select id,commission_pct from s_emp where commission_pct = null的输出结果。
is null判断是否为空,= null判断某个值是否等于null,null=null和null<>null 都为null。
第一条语句有输出结果,就是没有提成的ID号。
第二条语句没有输出。
10.select语句的输出结果为select * from s_dept;select * from s_emp;select * from s_region;select * from s_customer;……当前用户有多少张表,结果集有多少条记录。
select 'select * from '||table_name||';' from user_tables;11.判断select first_name,dept_id from s_emp where salary > '1450'是否抱错,为什么?隐式数据类型转换✧(CORE-E-002)综合练习▪定义CORE-F-006——CORE-F-008的综合练习:1.改变NLS_LANG的值,让select to_char(salary*12,’L99,999.99’) from s_emp输出结果的货币单位是¥和$setenv NLS_LANG 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK'setenv NLS_LANG 'AMERICAN_7ASCII'L99,999.99和L00,000.00的区别:99,999.99只显示有效位数;00,000.00的方式默认显示位数大于有效位数,以0填充。
2.列出每个员工的名字,工资、涨薪后工资(涨幅为8%),元为单位进行四舍五入select first_name,salary,round(salary*1.08) from s_emp;3.找出谁是最高领导,将名字按大写形式显示select upper(first_name) from s_emp where manager_id is null;4.Ben的领导是谁(Ben向谁报告)。
select e1.first_name from s_emp e1,s_emp e2 where e2.manager_id = e1.id and e2.first_name = 'Ben';用子查询也可以实现,如下:select first_name from s_emp e1,s_emp e2 where id = (select manager_id from s_emp where first_name = 'Ben');5.Ben领导谁。
(谁向Ben报告)。
select e1.first_name from s_emp e1,s_emp e2 where e1.manager_id = e2.id and e2.first_name = 'Ben';6.哪些员工的工资高于他直接上司的工资,列出员工的名字和工资,上司的名字和工资7.哪些员工和Biri(last_name)同部门8.哪些员工跟Smith(last_name)做一样职位9.哪些员工跟Biri(last_name)不在同一个部门10.哪些员工跟Smith(last_name)做不一样的职位11.显示有提成的员工的信息:名字、提成、所在部门名称、所在地区的名称12.显示Operations部门有哪些职位13.整个公司中,最高工资和最低工资相差多少14.提成大于0的人数15.显示整个公司的最高工资、最低工资、工资总和、平均工资,保留到整数位。
16.整个公司有多少个领导17.列出在同一部门入职日期晚但工资高于其他同事的员工:名字、工资、入职日期(CORE-E-003)综合练习定义CORE-F-009——CORE-F-011的综合练习:1.各个部门平均、最大、最小工资、人数,按照部门号升序排列2.各个部门中工资大于1500的员工人数3.各个部门平均工资和人数,按照部门名字升序排列4.列出每个部门中有同样工资的员工的统计信息,列出他们的部门号,工资,人数5.该部门中工资高于1000的员工数量超过2人,列出符合条件的部门:显示部门名字、地区名称6.哪些员工的工资,高于整个公司的平均工资,列出员工的名字和工资(降序)7.哪些员工的工资,介于32和33部门(33高些)平均工资之间8.所在部门平均工资高于1500的员工名字9.列出各个部门中工资最高的员工的信息:名字、部门号、工资10.最高的部门平均工资值的是多少11.哪个部门的平均工资是最高的,列出部门号、平均工资。
12.哪些部门的人数比32号部门的人数多13.Ben的领导是谁(非关联子查询)14.Ben领导谁(非关联子查询)15.Ben的领导是谁(关联子查询)16.Ben领导谁(关联子查询)17.列出在同一部门共事,入职日期晚但工资高于其他同事的员工:名字、工资、入职日期(关联子查询)18.哪些员工跟Biri(last_name)不在同一个部门(非关联子查询)19.哪些员工跟Biri(last_name)不在同一个部门(关联子查询)20.Operations部门有哪些职位(非关联子查询)21.Operations部门有哪些职位(关联子查询)(CORE-E-004)综合练习定义CORE-F-012——CORE-F-017的综合练习:1.工资在1500至3000之间的员工,各自工作的年限(四舍五入,降序)。
2.公司规定,每个员工在工作25年的第一个周五,可以申请退休,查询每个员工的这天显示格式:2010-01-013.显示员工的名字、入职日期、周几入职(用英文全拼),显示顺序从周一至周日。
4.写一个sql脚本,实现多对多关系(暂时不实现约束):学生表、课程表、学生选课表,学生表包含如下信息:学号、姓名、性别、出生日期、政治面貌,课程表包含如下信息:课程号、课程名称、学分、学时、学期,学生选课表包含如下信息:学号、课程号、成绩并插入数据。
Create table student(Id char(10),Name varchar2(20),Gender char(2),Birth date,Party varchar(10));Create table course(Id char(10),Name varchar2(20),Credit number(2,1),Period number(3),Term number(1));Create table st_c(Sid char(10),Cid char(10),Grade number(3,1));Insert into student values('2006015001','Mary','F','15-MAY-1988','A');Insert into student values('2006015002','John','M','15-JAN-1988','A');Insert into student values('2006015003','Kitty','F','23-MAY-1987','B');Insert into student values('2006015004','Tony','M','18-MAY-1989','A');Insert into student values('2006015005','Elice','F','15-MAY-1989','B');Insert into course values('MUST200901','Data structure',4,72,2);Insert into course values('MUST200902','Operating Systems',2,54,1);Insert into course values('MUST200903','Design Pattern',4,72,2);Insert into course values('MUST200904','Core Java',5,108,1);Insert into st_c values('2006015001','MUST200901',85);Insert into st_c values('2006015001','MUST200902',90);Insert into st_c values('2006015001','MUST200903',85);Insert into st_c values('2006015002','MUST200902',92);Insert into st_c values('2006015002','MUST200903',78);Insert into st_c values('2006015004','MUST200901',96);Insert into st_c values('2006015004','MUST200902',86);Insert into st_c values('2006015004','MUST200903',98);Insert into st_c values('2006015004','MUST200904',70);Insert into st_c values('2006015003','MUST200904',67);5.在建好表的基础上完成查询:某个学生选了哪些课程。