一、数据库的导入导出
--全导出:
exp 登录名/密码@数据库名称 file = 路径\文件的名称.dmp full = y;
---指定表导出:
exp 登录名/密码@数据库名称 file = 路径\文件的名称.dmp tables=(table1,teble2...)
--导出指定表的指定数据:
exp 登录名、密码@数据库名称 file=路径、文件名.dmp tables=(table) query=\"where条件\"
--导入 如果对已经存在的表导入不报错 在命令后面加上 ignore=y:
imp 登录名、密码@数据库名称 file=路径、文件名.dmp ignore=y
--不同用户之间的导入:
imp 登录名、密码@数据库名称 fromuser=导出用户名 touser=导入用户 file=路径\文件.dmp
二、条件查询
1、精确查询(=)
--查询性别是女生的学生信息
例: select * from t_student where sex = '2';
2、模糊查询(%)
例:
--查询名字最后一位是8 的学生信息
select * from t_student where name like '%8';
--查询密码用123开头的学生信息
select * from t_student where password like '123%';
--查询名字含有8 的学生信息
select * from t_student where name like '%8%';
三、运算符
1、算术运算符(+ 、- 、* 、/ 、mod(取模))
例:
--计算语文、英语、数学三科成绩总和。
select (s.chinese + s.math + s.english) 总分 from t_score s
--计算语文、英语、数学三科成绩平均成绩
select (s.chinese + s.math + s.english)/3 平均成绩 from t_score s
2、--比较运算符( '>' ,'<' ,'>=' ,'<=' ,'=' ,'!=' ,'<>' , between...and...)
①--查询年龄大于13且小于等于18的学生】
select * from t_student s where s.age > 13 and s.age <=18;
② --查询身高在1.60m(含)到1.80m(含)的学生(两种方法,最后使用between......and(当查询的量达到一定数量时,效率更高))
select * from t_student s where s.height >=160 and s.height <=180;
select * from t_student s where s.height between 160 and 180;
③ --查询性别不是男的老师信息
select * from t_teacher t where t.sex != 1;
④--当查询内容不连续的时候用in 不能用or
--in
--查询语文分数是80 ,85,86,88的学号及语文分数
select o.student_no, o.chinese from t_score o where o.chinese in (80,85,88,86);
--not like 不等、不像
--查询非南宁的学生
select * from t_student t where t.address not like '%南宁%';
3、--to_char ,to_date ,to_number
①--to_char:是把时间或者数字转换为字符串
例:to_char(时间,‘yyyy-mm-dd’)
②--to_date:是把值转换为数据库中的日期类型
例:to_date('1990-08-09','yyyy-mm-dd')
③--to_number:把值转换成number类型
4、--集合运算符:把两个或以上的结果集合成一个结果的运算
①--union :集合合并 去除重复的记录,只留下不存在重复且重复中的一条(对应列的数据类型必须一致)
例:
--查询性别为1的学生信息
--查询ID为1,4,5,6,8,10 的学生记录
select id,name,birthday,age from t_student t where t.sex=1
union
select id,name,birthday,age from t_student t where t.id in(1,4,5,6,8,10);
②--union all :集合合并 所有集合的记录数相加,不去除任何一条
例:
--查询性别为1的学生信息
--查询ID为1,4,5,6,8,10 的学生记录
select id,name,birthday,age from t_student t where t.sex=1
union all
select id,name,birthday,age from t_student t where t.id in(1,4,5,6,8,10);
③--intersect :集合的交集 去掉不重复的只留下重复的记录
例:
select id,name,birthday,age from t_student t where t.sex='1'
intersect
select id,name,birthday,age from t_student t where t.id in(1,4,5,6,8,10);
④--minus (数学中的补集) 集合相减 ,把重复的全部去掉只留下第一个集合中不重复的记录
例:
例:
select id,name,birthday,age from t_student t where t.sex='1'
minus
select id,name,birthday,age from t_student t where t.id in(1,4,5,6,8,10);
#想要例题中的数据表的,可以私聊。。。。。。。。。。。。。感谢观看!!!#