create sequence order_sequence
--查看序列的两个属性
select order_sequence.currval from dual;
select order_sequence.nextval from dual;
insert into orders values(order_sequence.nextval,'订单1',1000);
commit;
declare
begin
--循环500万次没循环一次 插入一条记录
for i in 1..5000000 loop
insert into ORDER_DETAIL values(order_sequence.nextval,'订单'||order_sequence.nextval,1000,null);
end loop;
commit;
end;
select * from order_detall
select * from ORDER_DETAIL t
--1.查询没有索引的状态 记录耗时
--2.创建索引
create index order_index on orders(oname)
--3.查询同样条件的数据 记录耗时
select * from orders where oname='订单3333333' ---0.047
select * from orders where oid=3333333--0.015
/*
三、视图
1.概念
类似数据库的虚拟表 支持数据查询
2.特点
不会存储数据 数据来源为原始表 --重点
3.意义:1)为了数据的安全
2)为了权限的细分
3)视图可以封装复杂的查询语句,简化查询。但是并不能提高查询速度,因为视图不保存数据,实际还需要从表中查询。
4.语法:
1)
create view 视图名 as select 语句
2)只读视图
create view 视图名 as select 语句 with read only
5.说明
修改视图中的数据,实际修改的是对应表中的数据
不建议通过视图对表中的数据做修改,因为会有很多限制
*/
--查询员工信息 员工表 创建视图支持特定的数据查询
create view emp_view as select empno,ename,job,mgr,deptno from scott.emp;
select * from emp_view
--修改SMITH的姓名为SSSS
update emp_view set ename='SSSS' where ename='SMITH';
commit;
create view e_view as select empno,ename,job,mgr,deptno from emp with read only
update e_view set ename='SMITH' where ename='SSSS';
commit;
create synonym emp_syn for scott.emp;
select * from emp_syn;
create synonym sy_emp for scott.emp
/*
五、数据库的导入导出
1使用场景: 1).导出实现数据库备份
2).导入数据数据还原
3).服务器升级 必须整体的数据库迁移 --管理员实现
2实现方式:
1)命令行实现 安装服务器可以 文件格式为dmp
exp 整个数据库导出 exp 用户名/密码 file=文件路径 full=y
按照用户导出 exp 用户名/密码 owner=用户名 file=文件路径
按照表名导出 exp 用户名/密码 file=文件路径 tables=表名,表名2
imp
2)图形化客户端导入导出
A.tools--export user object --导出表结构 不能备份数据
导出对象的建表语句
B.tools --export tables
oracle
sql文件 导出文件勾选create table
pde格式 导入文件勾选create table
*/