使用Hibernate开发租房系统(1)

100%启动oracle数据库步骤:

1.xxx  复制计算机的名字
2.输入net manager 将计算机名复制到服务 和监听程序上
3.输入services.msc启动服务 (listener oracleservice)
4.输入sqlplus进入小窗口
5.登录名 system 密码accp
6.oracle的默认表 dual

 

select * from dual;

伪列
rowid 记录表中某一行数据存放的物理地址
例子:
create table employee
as
select * from scott.emp;
select t.*,rowid from employee t;

rownum 作为一个伪列 如果想用该列查询 必须从第一个索引查起
例子:
(1)select t.*,rownum from employee t where rownum>5 and rownum<=10
(2)select * from
(select t.*,rownum rn from employee t) where rn>5 and rn<=10

因为表结构经过了更改 rownum作为伪列 不允许直接使用
需要经过嵌套查询才可以使用
有order by 3层 没有2层
rownum作为分页必须的查询函数
例子:
select b.* from
(select a.*,rownum rrrr from
(select t.* from employee t order by sal desc) a) b where rrrr>1 and rrrr<=6;

查看表中行数
select count(1) from student ; 效率高
select count(stuid) from student ; 效率高
select count(*) from student ; 效率低

增删改操作存在的是行级锁
表级锁

事务 commit rollback savepoint

union (合并)
完全重复的数据将被合并成1条 不重复的数据将会显示
数据合并做分析用
首列会进行升序排列
必须每一列能对应上 才能合并 否则出错

union all(合并全部)
两表进行合并 不删除重复的数据
首列不进行排序

intersect(交集)

minus
去掉上表重复的数据

to_date
to_char 转换成字符型
to_number

nvl(列名,为空的取值)
nvl2(列名,不为空的取值,为空的取值)
decode(列名,等于值1,结果1,等于值2,结果2,默认结果)

行转列:
例子:
create table score
(
  id int primary key,
  stuname varchar2(32),
  project varchar2(32),
  score int
)


insert into score values(1,'小明1','java',80);
insert into score values(2,'小明2','oracle',90);
insert into score values(3,'小明3','.net',70);
insert into score values(4,'小明4','java',81);
insert into score values(5,'小明5','oracle',70);
insert into score values(6,'小明6','.net',80);
insert into score values(7,'小明7','java',180);

select * from score;

select stuname,max(decode(project,'java',score)) 加瓦,max(decode(project,'oracle',score)) 甲骨文,max(decode(project,'.net',score)) ".net"
from score group by stuname;

rank 同名次 会冲掉后续的连续数字排位
例子:
select ename,deptno,rank() over(partition by deptno order by sal desc) 排名
from employee;

 

dense_rank 同名次 不会冲掉后续的连续数字排位
找到每个部门工资第二高的人
例子:
select * from
(select ename,deptno,dense_rank() over(partition by deptno order by sal desc) rk
from employee) where rk=2;

row_number 同名次不会出现相同排名
例子:
select ename,deptno,row_number() over(partition by deptno order by sal desc) 排名
from employee;

复制员工信息表
create table employee
as
select * from scott.emp;

复制部门表
create table dept
as
select * from scott.dept;
select t.*,rowid from employee t;

添加两列
alter table employee
add
(
empTel_no varchar2(32),
empAddress varchar2(32)
);

删除添加的两列
alter table employee
drop
(
empTel_no,
empAddress
);

按照薪水降序查询5-9条数据
select b.* from
(select a.*,rownum r from
(select t.* from employee t order by sal desc) a) b where r>=5 and r<=9;

显示职员的就职年度详细信息
select ename,to_char(round(hiredate,'yyyy'),'yyyy') || '年度度' from employee;
注:这里如果只写年度两个字的话会少一个字

各种工作类别的最低薪金,显示最低薪金大于1500的记录
select * from
(select * from employee where sal in(
select min(sal) from employee group by job)) where sal>1500;

各月最后一天受雇的所有雇员
select * from employee where last_day(hiredate)=hiredate;

insert into employee values('7777','JOL','CLERK','7172',to_date('1995-1-31','yyyy-MM-dd'),'800.00','2000.00','10');
注:注意to_date

posted on 2017-03-31 00:42  凌雨轩林  阅读(295)  评论(0编辑  收藏  举报

导航