--create or replace 创建或替换,如果存在就替换,不存在就创建

create or replace procedure p

is

  cursor c

  is

  select * from dept2 for update;

begin

  for row_record in c loop

    if (row_record.deptno = 30) then

      update dept2 set dname = substr(dname, 0, length(dname) - 3) where current of c;

    end if;

  end loop;

end;

 

exec p;

 

begin

p;

end;

 

--带参存储过程

--in 输入参数,不带in out 默认输入参数

--out 输出参数

--in out 同时带的是输入输入参数

create or replace procedure p2(

       a in number,

       b number,

       s_result out number,

       s_temp in out number

  )

is

begin

  if (a > b) then

    s_result := a;

  else

    s_result := b;

  end if;

  s_temp := s_temp + 3;

end;

 

--调用存储过程

declare

  v_a number := 4;

  v_b number := 6;

  v_result number;

  v_temp number := 5;

begin

  p2(v_a, v_b, v_result, v_temp);

  dbms_output.put_line(v_a);

  dbms_output.put_line(v_b);

  dbms_output.put_line(v_result);

  dbms_output.put_line(v_temp);

end;

 

---删除一个表的过程

create or replace procedure drop_table(tname varchar2)

as

  total int := 0;

begin

     select count(*) into total from user_tables 

            where table_name = upper(tname);

     if total >= 1 then

        execute immediate 'drop table '||tname; --此处必须用动态sql

     end if;

end;

select * from user_tables;

 

--递归存储过程

create or replace procedure pro_emp(sEmpno emp.empno%type, sLevel integer)

is

       cursor c is select * from emp where mgr = sEmpno;

       prefixStr varchar(255);

begin

  for i in 1..sLevel loop

    prefixStr := prefixStr || '----';

  end loop;

  

  for row_data in c loop

    dbms_output.put_line(prefixStr || row_data.ename);

    pro_emp(row_data.empno, sLevel + 1);

  end loop;

end;

 

select * from emp;

begin

  pro_emp(7839, 0);

end;

Oracle笔记 十、PL/SQL存储过程的更多相关文章

  1. PL/SQL存储过程编程

    PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...

  2. 每周一书《Oracle 12 c PL(SQL)程序设计终极指南》

    本周为大家送出的书是<Oracle 12 c PL(SQL)程序设计终极指南>,此书由机械工业出版社出版, 孙风栋,王澜,郭晓惠 著. 内容简介: <Oracle 12c PL/SQ ...

  3. Oracle数据库之PL/SQL触发器

    Oracle数据库之PL/SQL触发器 1. 介绍 触发器(trigger)是数据库提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是 ...

  4. Oracle数据库之PL/SQL过程与函数

    Oracle数据库之PL/SQL过程与函数 PL/SQL块分为匿名块与命名块,命名块又包含子程序.包和触发器. 过程和函数统称为PL/SQL子程序,我们可以将商业逻辑.企业规则写成过程或函数保存到数据 ...

  5. Oracle数据库之PL/SQL程序设计简介

    PL/SQL程序设计简介 一.什么是PL/SQL? PL/SQL是 Procedure Language & Structured Query Language 的缩写. ORACLE的SQL ...

  6. oracle数据库之PL/SQL 块结构和组成元素

    一.PL/SQL 块 (一)PL/SQL 程序由三个块组成,即声明部分.执行部分.异常处理部分 PL/SQL 块的结构如下: 1.DECLARE /* 声明部分: 在此声明 PL/SQL 用到的变量, ...

  7. ORACLE中的PL/SQL

    一. 1.过程,函数,触发器是pl/sql编写.                2. 过程函数触发器是在Oracle中.                      3.pl/sql是非常强大的数据库过 ...

  8. 《oracle每日一练》免安装Oracle客户端使用PL/SQL

    免安装Oracle客户端使用PL/SQL Oracle客户端挺招人烦的,部署连接它的应用通常需要先安装它的客户端,安装程序要求在目标机器上写注册表,假设你没有洁癖的话,你仍可能被下面的事情绊住:当你的 ...

  9. Oracle 客户端安装 + pl/sql工具安装配置

    Oracle 客户端安装 +  pl/sql工具安装配置 下载oracle客户端,并在本地安装. 11g下载地址为: http://www.oracle.com/technetwork/databas ...

  10. oracle instantclient basic +pl/sql 安装和配置

    oracle instantclient basic +pl/sql 安装和配置 大家都知道,用PL/SQL连接Oracle,是需要安装Oracle客户端软件的,oracle客户端有点大,比较耗资源. ...

随机推荐

  1. HTML document对象(2)

    五.相关元素操作: var a = document.getElementById("id");找到a: var b = a.nextSibling,找a的下一个同辈元素,注意包含 ...

  2. linux命令行下导出导入.sql文件

    一.导出数据库用mysqldump命令(注意mysql的安装路径,即此命令的路径):1.导出数据和表结构(以管理员身份运行): ------------------------------------ ...

  3. git查看历史命令

    1 git show git show 分支名/HEAD/hash值 2 git log参数 --oneline 单行信息--decorate 输出commit引用信息--graph 图形化输出--a ...

  4. Linux 下绑定域名与IP地址

    在 Linux 下,hosts 文件的路径是 /etc/hosts,此文件需要有root权限才可编辑,条目也是通过“IP 域名”的格式将域名与IP进行绑定. 对 Linux 的 hosts 配置文件的 ...

  5. 第十章 Vim程序编辑器学习

    1.Vim是进阶版的vi,vim不但可以用不同颜色显示文字内容,还能进行诸如shell script,C program等程序编辑功能. 区别:vi是老师的字处理器,不过功能已经很齐全,但还是有可以进 ...

  6. [Java] File类的常用操作

    package test.file; import java.io.File; import java.io.IOException; public class TestFile { public s ...

  7. Ubuntu 之 initramfs 报错解决之一

    问题出现: ubuntu 更新后,编辑文件提示权限不够,并提示更新错误,重启后进入 initramfs ,仔细看提示错误有: file system check of the root filesys ...

  8. Javascript 原型编程初探

    创建两个对象独立运行 var PlayTrace = function (interVal,name) { this.interVal = interVal; this.playName = name ...

  9. 基于nginx和uWSGI在Ubuntu上部署Djan

    http://www.jianshu.com/p/e6ff4a28ab5a 文/Gevin(简书作者)原文链接:http://www.jianshu.com/p/e6ff4a28ab5a著作权归作者所 ...

  10. 光流算法:Brox光流的OpenCV源码解析

    OpenCV中DeepFlow代码其实是Brox光流,而非真正的DeepFlow光流,在将近一个月的研究.移植及优化过程中,对Brox光流有了较深刻的认识.我对OpenCV中源码进行了详细的分析,并以 ...