1、什么是存储过程:

用于在数据库中完成特定的操作或者任务。是一个PLSQL程序块,可以永久的保存在数据库中以供其他程序调用。

2、无参存储过程的使用:

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

1.  CREATE  OR  REPLACE  PROCEDURE  过程名  [(parameter,...)]

2.  IS

3.  定义变量

4.  Begin

5.  Plsql程序

6.  End;

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

1.  例:创建一个存储过程,用于向数据库中插入一条记录。

2.  第一步:创建

3.  CREATE  OR  REPLACE  PROCEDURE  pro_1

4.  IS

5.  Begin

6.    insert into person values (11,'aa','aav');

7.  End;

8.

9.  第二步:在sql*plus中执行该过程

10.exec pro_1;

11.

12.第三步:通过JDBC使用存储过程。

13.    private Connection conn = null;

14.    private ResultSet rs = null;

15.    private CallableStatement state = null;

16.    //调用一个无参数的存储过程

17.    public void testPro()

18.    {

19.        conn = Tools.getConnection();

20.        try {

21.            state = conn.prepareCall("{call pro_1}");

22.            state.execute();

23.        } catch (Exception e) {

24.            // TODO Auto-generated catch block

25.            e.printStackTrace();

26.        }

27.    }

3、带有IN类型参数的存储过程的使用

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

1.  例:创建一个存储过程,用于向数据库中插入一条记录。

2.  第一步:创建

3.  CREATE  OR  REPLACE  PROCEDURE  pro_2(id number,name varchar2,email varchar2)

4.  IS

5.  Begin

6.    insert into person values (id,name,email);

7.  End;

8.  第二步:在sql*plus中执行该过程

9.  exec pro_2(12,'aaa','aaa');

10.

11.第三步:通过JDBC使用存储过程。

12.    //使用一个带有 IN 类型参数的存储过程

13.    public void testPro_in(int id,String name,String email)

14.    {

15.        conn = Tools.getConnection();

16.        try {

17.            state = conn.prepareCall("{call pro_2(?,?,?)}");

18.            state.setLong(1, id);

19.            state.setString(2, name);

20.            state.setString(3, email);

21.            state.execute();

22.        } catch (Exception e) {

23.            // TODO Auto-generated catch block

24.            e.printStackTrace();

25.        }

26.    }

4、带有OUT类型参数的存储过程的使用

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

1.  例:创建一个存储过程,用于返回数据库中的Person表的总行数。

2.

3.  第一步:创建

4.  CREATE  OR  REPLACE  PROCEDURE  pro_3(num out number)

5.  IS

6.  mynum number;

7.  Begin

8.    select count(*) into mynum from person;

9.    num := mynum;

10.End;

11.或者

12.CREATE  OR  REPLACE  PROCEDURE  pro_3(num out number)

13.IS

14.Begin

15.  select count(*) into num from person;

16.End;

17.

18.第二步:在sql*plus中执行该过程

19.declare

20.a number;

21.begin

22.  pro_3(a);

23.  dbms_output.put_line(a);

24.end;

25.

26.第三步:通过JDBC使用存储过程。

27.public void testPro_out()

28.    {

29.        conn = Tools.getConnection();

30.        try {

31.            state = conn.prepareCall("{call pro_3(?)}");

32.            state.registerOutParameter(1, Types.NUMERIC);

33.            state.execute();

34.            int num = state.getInt(1);

35.            System.out.println(num);

36.        } catch (Exception e) {

37.            // TODO Auto-generated catch block

38.            e.printStackTrace();

39.        }

40.    }

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

5、带有IN-OUT类型参数的存储过程的使用

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

1.  创建:

2.  CREATE  OR  REPLACE  PROCEDURE  pro_4(num in out number)

3.  IS

4.  a number := 100;

5.  Begin

6.    num := a*num;

7.  End;

8.

9.  在sql*plus中执行该过程

10.declare

11.  a number := 12;

12.begin

13.  pro_4(a);

14.  dbms_output.put_line(a);

15.end;

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:11.0pt;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}

Oracle存储过程的调用和执行的更多相关文章

  1. oracle存储过程递归调用

    oracle存储过程递归调用,如果where子句使用的是传入的参数, 在以后的递归调用中参数就是第一次调用的参数值,解决办法是定义变量,使用自定义的变量问题可以解决.

  2. oracle 存储过程中调用存储过程

    create procedure sp_name() begin ……… end 比如: create procedure pro_showdbs() show datebase; end //用ex ...

  3. Oracle存储过程的调用(返回参数)

    CREATE OR REPLACE PROCEDURE test_in_out_exception (v_empno VARCHAR2,v_guess_sal NUMBER,v_true_sal OU ...

  4. oracle存储过程jdbc调用

    package com.jckb.procedure; import java.sql.CallableStatement; import java.sql.Connection; import ja ...

  5. ORACLE存储过程的创建和执行的简单示例和一些注意点

    此示例的主要目的主要是为了了解在PL/SQL环境下怎么创建和执行存储过程. 存储过程所涉及的DataTable: 第一步:创建游标变量 游标是ORACLE系统在内存中开辟的一个工作区,主要用来存储SE ...

  6. Oracle存储过程中调用DBLink同义词出现错误:PLS-00201: 必须声明标识符

    前几天编写一个存储过程,需要访问远程数据库的字段,于是建立一个dbLink并建了同义词: CREATE PUBLIC DATABASE LINK orcl@dbc CONNECT TO orcl ID ...

  7. Oracle存储过程java 调用

    1.nest表组合成结果集,然后以游标变量的形式返回 --创建类型 create or replace package mytest is -- Author  : ADMINISTRATOR  -- ...

  8. oracle 存储过程调用 执行

    oracle 存储过程调用 博客分类: 数据库相关   oracle存储过程 2011年02月11日 星期五 14:47 SQL中调用存储过程语句: call procedure_name(); 调用 ...

  9. Oracle存储过程创建及调用(转)

    在大型数据库系统中,有两个很重要作用的功能,那就是存储过程和触发器.在数据库系统中无论是存储过程还是触发器,都是通过SQL 语句和控制流程语句的集合来完成的.相对来说,数据库系统中的触发器也是一种存储 ...

随机推荐

  1. c#入门系列——基础篇

    c#与VB的区别 刚接触c#发现c#与vb还是有所不同的--它可以在控制台显示.它比vb多出来了一些东西.代码规范上跟VB也稍有不同.....暂时就发现这么多,正在努力发现中. c#的代码结构     ...

  2. margin:0 auto;不居中?

    1.没有设置宽度 <div style="margin:0 auto;"></div> 看看上面的代码,根本没有设置DIV的宽度,如何根据宽度自适应呢?新手 ...

  3. MySQL架构由小变大的演变过程

    假设一个网站(discuz)从最开始访问量很小做到日pv千万,我们来推测一下它的mysql服务器架构演变过程. 第一阶段网站访问量日pv量级在1w以下.单台机器跑web和db,不需要做架构层调优(比如 ...

  4. HBase介绍

    欢迎和大家交流技术相关问题:邮箱: jiangxinnju@163.com博客园地址: http://www.cnblogs.com/jiangxinnjuGitHub地址: https://gith ...

  5. Matlab中plot函数全功能解析

    Matlab中plot函数全功能解析 功能 二维曲线绘图 语法 plot(Y)plot(X1,Y1,...)plot(X1,Y1,LineSpec,...)plot(...,'PropertyName ...

  6. Android项目实战(三十一):异步下载apk文件并安装(非静默安装)

    前言: 实现异步下载apk文件 并 安装.(进度条对话框显示下载进度的展现方式) 涉及技术点: 1.ProgressDialog   进度条对话框  用于显示下载进度 2.AsyncTask     ...

  7. Unity3d的序列帧动画

    马上这星期就要过去了,为了完成每星期写一篇博客的目标,熬夜也要写完. 最近项目中用到了很多序列帧动画,之前看教程也接触过序列帧动画,但当时没用到,就没仔细研究,这次就借着这个机会好好总结一下序列帧动画 ...

  8. Eclipse通过jdbc连接数据库制作简单登陆界面

    一.前言: 做网站开发,要求有多种搭配方式,前台技术可以使用PHP.ASP.JSP.ASP.NET.CGI等任何一种: 需要用到的基础语言用的最多的就是HTML/CSS.JS.JAVA.XML这些了, ...

  9. 如何垂直居中<img>?

    方法1: 父元素设置height=line-height,子元素设置vertical-align:middle; 方法2: 父元素display:table-cell;vertical-align:m ...

  10. C#中函数的功能和类型

    函数  就是方法是独立完成某项功能的一个个体 函数的的三个好处:1.提高代码的重用性.2.提高功能开发的效率,3.提高代码的可维护性(主要功能). 函数也分为     固定功能函数(这类函数具有可封闭 ...