---
title: "存储过程格式"
author: "Eileenlml"
date: "2017-05-26T17:29:58Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2017-05-26T17:29:58Z"
id: 2376570
url: "https://eileenlml.iteye.com/blog/2376570"
---

存储过程的语法结构：

[]()[]()Create or replace procedure过程名as（param1 in type，param2 out type）

变量1 类型（值范围）;

变量2 类型（值范围）;

声明语句段；

begin

----执行语句段；

If (判断条件)

……

End if;

Exception

----异常处理语句段；

When others then

       Rollback;

End;

过程是有名称的程序块，as关键词代替了无名块的declare

 

注意事项：

1，  存储过程参数不带取值范围，in表示传入，out表示输出

2，  变量带取值范围，后面接分号

3，  在判断语句前最好先用count（\*）函数判断是否存在该条操作记录

4，  用select ……into……给变量赋值

5，  在代码中抛异常用 raise+异常名

 

6,   Create or replace procedure如果系统中没有此存储过程就新建一个，如果系统中有此存储过程则把原来删除掉，重新创建一个存储过程。