1:捕获plsql抛出的异常

declare
v_ename emp.ename%type;
begin
select ename into v_ename from emp where empno=10;
exception
when too_many_rows then
dbms_output.put_line('太多值了');
when others then
dbms_output.put_line('error');
end;
/

2:游标

declare
cursor c is
select * from emp;
v_emp c%rowtype;
begin
open c;
loop
fetch c into v_emp;
exit when(c%notfound);
dbms_output.put_line(v_emp.ename);
end loop;
close c;
end;
/

declare
cursor c is
select * from emp;
v_emp c%rowtype;
begin
open c;
fetch c into v_emp;
while(c%found) loop
dbms_output.put_line(v_emp.ename);
fetch c into v_emp;
end loop;
close c;
end;
/

for循环:

declare
cursor c is
select * from emp;
v_emp c%rowtype;
begin
for v_emp in c loop
dbms_output.put_line(v_emp.ename);
end loop;
end;
/

--带参数的游标

declare
cursor c(v_deptno emp.deptno%type) is
select * from emp where deptno = v_deptno;
v_emp c%rowtype;
begin
for v_emp in c('10') loop
dbms_output.put_line(v_emp.ename);
end loop;
end;
/

3:procedure存储过程

create or replace procedure p(v_a in number,v_b number,v_retu out number,v_temp in out number)
is
begin
if(v_a>v_b) then
v_retu := v_a;
else
v_retu :=v_b;
end if;
v_temp := v_temp+1;
end;
/

调用存储过程 p:

declare
v_a number :=3;
v_b number :=4;
v_retu number;
v_temp number :=5;
begin
p(v_a,v_b,v_retu,v_temp);
dbms_output.put_line(v_retu);
dbms_output.put_line(v_temp);
end;
/

4:函数

create or replace function sal_tax(sal number)
return number
is
begin
if(sal>3000) then
return 0.1;
elsif(sal>4000) then
return 0.2;
else
return 0.3;
end if;
end;
/

5:触发器
create or replace trigger trig
after insert or update or delete on emp for each row
begin
if inserting then
insert into emp_log values(USER ,'insert',sysdate);
elsif updating then
insert into emp_log values(USER ,'update',sysdate);
elsif deleting then
insert into emp_log values(USER ,'delete',sysdate);
end if;
end;
/

oracle学习总结5(游标、触发器、过程、方法)的更多相关文章

  1. 【Oracle学习笔记】游标

    1. 分类 常见的游标可分为显示游标.隐式游标.静态游标和动态游标四大类: 1.1 显示游标 显式是相对与隐式cursor而言的,就是有一个明确的声明的cursor.显式游标的声明类似如下: delc ...

  2. Oracle学习笔记十一 游标

    游标的简介 游标的概念 游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用fetch语句可以移动该指针,从而对游标中的数据进行各种操作 ...

  3. Oracle PL/SQL,游标,过程

    1.PL/SQL  语法相关 -- SQL 语言只是访问,操作数据库的语言,而比并不是程序设计语言,因此不能用于程序开发. -- PL/SQL 是在标准SQl语言上进行过程性扩展后形成的程序设计语言, ...

  4. Oracle学习【索引及触发器】

    索引B_Tree结构 请参照 响应图例 索引是一种允许直接访问数据表中某一数据行的树形结构,为了提高查询效率而引入,是独立于表的对象,可以存放在与表不同的表空间中.索引记录中存有索引关键字和指向表中数 ...

  5. Oracle学习笔记之游标详解

    游标 游标存在意义:解决"select *"返回空.多行记录问题,但凡select,就可能多行结果集,也就需要用游标. 游标分4步走:cursor.open.fetch.close ...

  6. Oracle学习(12):存储过程,函数和触发器

    存储过程和存储函数 l存储在数据库中供全部用户程序调用的子程序叫存储过程.存储函数. 注意:存储过程与存储函数声明变量时,用的是as   而不是declare 存储过程与存储函数差别 存储过程不带有返 ...

  7. oracle 学习笔记之触发器

    说明 数据库触发器是一个与表相关联的.存储的PL/SQL程序. 每当一个特定的数据操作语句(Insert,update,delete)在指定的表上发出时,Oracle自己主动地运行触发器中定义的语句序 ...

  8. Oracle学习的一些建议(转)

    核心提示:学习Oracle是一个漫长艰辛的过程.如果没有兴趣,只是被迫学习,那么是很难学好的.学习到一定程度的时候,要想进一步提高,就不得不接触很多Oracle之外的东西 学习Oracle是一个漫长艰 ...

  9. Oracle学习-Power Designer、visio 2003、Oracle sql developer、OEM、expdp

    Oracle的体系太庞大了.对于刚開始学习的人来说,难免有些无从下手的感觉. 经过一学期的学习对Oracle学习有了一些深入的了解,由于之前学习过Oracle的一些主要的知识.所以学习起来上手比較快一 ...

随机推荐

  1. Webdriver API (一)

    (转载) 1.1  下载selenium2.0的包 官方download包地址:http://code.google.com/p/selenium/downloads/list 官方User Guid ...

  2. IE兼容性问题解决方案1--ajax请求不发送到后台

    相信很多小伙伴会遇到这种问题,用ajax做异步请求的时候,在IE浏览器下,并没有发送出去.但是相关程序确实执行了.为什么呢? 原来这是IE缓存方式的原因,所以呢,用下边的解决方案吧. 1.在请求的UR ...

  3. 【转】ExcelHelper类,用npoi读取Excel文档

    //------------------------------------------------------------------------------------- // All Right ...

  4. When to Redis ? when to MongoDB?

    120down voteaccepted I would say, it depends on kind of dev team you are and your application needs. ...

  5. css div 不能贴边

    *{margin:0;padding:0} 在css 最前加上这句,取消所有内边距和外边距.

  6. SQL2008-分页显示3种方法

    方法1: 适用于 SQL Server 2000/2005/2008 SELECT TOP 10 * FROM YieldRole WHERE id NOT IN ( SELECT TOP (10*( ...

  7. python 定义函数

    在Python中,定义一个函数要使用def语句,依次写出函数名.括号.括号中的参数和冒号:,然后,在缩进块中编写函数体,函数的返回值用return语句返回. 我们以自定义一个求绝对值的my_abs函数 ...

  8. 【Stage3D学习笔记续】山寨Starling(六):动画实现和测试

    我发布了一个版本v0.2,该版本是未优化版本,且没有添加Touch事件体系,但是由于是最基础且未优化的,所以可以通过参考代码快速的了解实现原理. 接下来的一段笔记开始进行渲染优化,我会把所有的目光都集 ...

  9. MSSQLSERVER- CharIndex的妙用,找出有妙用

    CharIndex 1:CharIndex语法: CharIndex(expression1,expression2[,start_location]) 2:参数 expression1 一个表达式, ...

  10. [置顶] [BZOJ]2127: happiness 最小割

    happiness: Description 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与理科有着自己 ...