---
title: "在oracle中创建一个exception"
author: "danielhjd"
date: "2011-05-24T19:24:44Z"
tags: ["Oracle"]
categories: ["数据库"]
slug: "oracle-exception"
draft: false
lastmod: "2011-05-24T19:24:44Z"
id: 1056944
url: "https://danielhjd.iteye.com/blog/1056944"
---

**Gramma:**

 

1:声明一个exceptin:

 declare

 exception\_name exception;

 

2:触发一个exception;

 raise exception\_name;

 

3:捕获一个exception

when exception\_name1 then statements;

when exception\_name2 then statements

 

代码：

```
declare
a exception;
t_salary employee.salary%type;
begin
select salary into t_salary from employee where employee.empid=13;
if t_salary>2000 then
raise a;
end if;
exception
when a then
dbms_output.put_line('薪水超出范围');
end;
```

 

output:

```
薪水超出范围
```

 

主要注意语法的问题