1.sqlplus / as sysdba --管理员登陆
2.grant create view to scott --授权
3.视图只能简化操作,不能提高性能
4.with check option操作只能看得到的部分,不建议通过视图对表的数据进行修改
5.orclae里面有物化视图,可以返回数据
6.序列:就是一个数组,装在内存中,所以可以提高速度
create sequence myseq(默认是1)
使用序列:
insert into test(id) values(myseq.nextvalue)
7.索引:
创建索引:create index myindex on emp(deptno)
8.索引所在的列经常别更新,不适合建索引
9.授予scott权限
grant select on hr.employee to scott
10.同义词(可以代表,视图,序列)
create synonym hremp for hr.employee
同义词有私有和公有
11. plsql语言
declare
--说明部分
begin
--程序
dbms_output.put_line("Hello Word");
end;
set serveroutput om--打开输出开关
12.引用变量:
--查询并打印7839的姓名和薪水
declare
--定义变量姓名和薪水
pname emp.ename%type;
psal emp.sal%type
begin
--得到7830的姓名和薪水
select ename,sal into pename,psal from emp where deptno=7839;
dbms_output.put_line(pname||'薪水是'||psal);
end;
13.记录型变量
--查询并打印7839的姓名和薪水
declare
emp_rec emp%rowtype--表的一行
begin
select * into emp_rec from emp where deptno=7839;
dbms_output.put_line(emp_rec.ename||'薪水是'||emp_rec.sal);
end;
14.if联系:
判断从键盘中输入数字
--接收键盘输入
--num:地址值,在该地址上保存输入的值
accept num prompt '请输入数字';
declare
--定义变量保存输入的数字
--隐式转换
pnum number:=#
begin
if pnumber=0 then
elsif pnumber=0 then
else
end if;
end;
15.循环练习:打印1-10
declare
pnum:=1
begin
loop
--退出条件
exit when pnum>10;
dbms_output.put_line(pnum);
--加一
pnum:=pnum+1;
end loop;
end;
16.例外练习(被0除)
declare
pnum number;
begin
pnum:=1/0;
exception
when zero_divide then dbms_output.put_line('0不能被除数');
when value_error then
dbms_output.put_line('算术转换错误');
when other then dbms_output.put_line('处理其他的例外');
end;
17.自定义例外练习(查询50号的部门,如果没有抛出自定义例外)
declare
cursor cemp is select ename from emp where deptno=50;
pname emp.ename%type;
--自定义例外
no_emp_found ecxeption;
begin
open cemp;
--取一条记录
fetch cemp into pename;
if cemp%notfound then
--抛出例外
raise no_emp_found;
end if;
--后台进程会自动关闭
colse cemp;
exception
when no_emp_found then
dbms_output.put_line('没有员工');
when other then dbms_output.put_line('处理其他的例外');
end;
2016/2/9 10:58pm