oracle小结

视图
create view v_view as select * from emp;
创建视图指定视图的名称 指定为哪张表进行创建视图
select * from v_view
视图可以直接进行查询,也可以进行增删改操作,但是不建议直接在视图中进行增删改操作,
操作会直接影响到原表中的数据所以一般讲视图设置为只读create view v_view as select * from emp with read only;

索引
单列索引
create index i_index on emp
复合索引
create index i_index on emp(ename,job)
为哪个表创建索引,
创建索引的意义在于提高查询的效率,一般在大表中才会创建索引 ,
如果表中的数据进行频繁的修改操作,不推荐使用索引,
在where子句后面或者连接的条件上的字段建立索引

pl/sql
基本的语法
declare
变量名 变量的类型,(可以直接写类型,也可以进行类型的引用(表明.字段%type))
begin

end;

存储过程
完成特定功能的sql语句集
create [or replace] procedure 名
{as|is} begin
pl/sql体
(比如:dbms_output.put_line('helloworld');)
end 名;
如果调用在pl/sql中进行调用

范例:给指定的员工涨 100 工资,并打印出涨前和涨后的工资
分析:我们需要使用带有参数的存储过程
create or replace procedure addSal1(eno in number) is
pemp myemp%rowtype;
begin
select * into pemp from myemp where empno = eno;
update myemp set sal = sal + 100 where empno = eno;
dbms_output.put_line('涨工资前' || pemp.sal || '涨工资后' ||
(pemp.sal + 100));
end addSal1;
调用
begin
-- Call the procedure
addsal1(eno => 7902);
commit;
end;


oracle的存储过程中is和as区别?

1、在存储过程(PROCEDURE)和函数(FUNCTION)中没有区别;
2、在视图(VIEW)中,只能用AS不能用IS;
3、在游标(CURSOR)中,只能用IS不能用AS。

扫描二维码关注公众号,回复: 4208719 查看本文章


存储函数
create or replace function 函数名(变量名 in 类型,变量名 in 类型) return 数据类型 is
结果变量 类型;
begin

return(结果变量);
end 函数名;

猜你喜欢

转载自www.cnblogs.com/aniymx/p/10012360.html