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. 陈灯WGF双缓冲绘图框架

    “木丸子童屋”,专售各类儿童玩具,价格优惠,请大家多多支持:http://shop65552598.taobao.com/ WGF(windows graphic foundation)为window ...

  2. 判断A树是否包含B树结构

    题目:输入两棵二叉树A和B,判断B是不是A的子结构 分析:根据数的遍历方法,首先想到的是采用递归的方式要更简单些,树A从根节点进行遍历,首先判断与B的根节点值是否相等,如果相等则进行递归遍历验证,否则 ...

  3. NOIP2005 篝火晚会

    篝火晚会 (fire.pas/c/cpp) [问题描述] 佳佳刚进高中,在军训的时候,由于佳佳吃苦耐劳,很快得到了教官的赏识,成为了“小教官”.在军训结束的那天晚上,佳佳被命令组织同学们进行篝火晚会. ...

  4. CCF 认证4

    题意:求强联通分量 Tarjan算法 #include<iostream> #include<stdio.h> #include<stdlib.h> #includ ...

  5. 在Visual Studio中利用NTVS创建Pomelo项目

    刚看新闻,才知道微软发布了Node.js Tools for Visual Studio(NTVS),受够了WebStorm输入法Bug的困扰,这下终于可以解脱了.以Pomelo为例,运行命令:pom ...

  6. jexus asp.net Linux Web Server

    Jexus简介 Jexus web server for linux 是运行在Linux上的Web服务器.其安装和部署及其简单,直接支持Asp.net . 下载Jexus wget http://li ...

  7. [C++]VisualAssistX中文注释提示错误 解决办法

    问题情况:Visual Assist X中文注释为提醒注释错误,而且在注释下面以红线标.问题原因:这是因为Visual Assist X认为中文的注释是拼写错误.问题处理: 1.打开 Microsof ...

  8. 第十一章、认识与学习 BASH 管线命令 (pipe)

    管线命令使用『 | 』界定符号 [root@www ~]# ls -al /etc | less 管线命令『 | 』仅能处理经由前面一个命令传来的正确信息,也就是 standard output 的信 ...

  9. js难点之闭包理解

    如何从外部读取局部变量? 闭包就是能够读取其他函数内部变量的函数. 由于在Javascript语言中,只有函数内部的子函数才能读取局部变量,因此可以把闭包简单理解成“定义在一个函数内部的函数”. 所以 ...

  10. 测试JS基本类型以及对象的引用

    自己敲的. 1 <script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js&qu ...