---
title: "(oracle)如何通过函数去调用procedure的注意事项"
author: "danielhjd"
date: "2011-05-25T12:06:27Z"
tags: ["Oracle"]
categories: ["数据库"]
slug: "oracle-procedure"
draft: false
lastmod: "2011-05-25T12:06:27Z"
id: 1058036
url: "https://danielhjd.iteye.com/blog/1058036"
---

**创建一个带参数的procedure temp\_pr():**

```
create or replace procedure temp_pr(temp_no in employee.empid%type,temp_name out employee.empname%type)as
begin
select employee.empname into temp_name from employee where employee.empid=temp_no;
end;
```

在上一篇关于procedure的日志中提到 as 在这里的功能相当于 declare的作用 用来声明变量，此处没有变量所以as后面接代码；

 

**创建一个function get\_temp()，用函数来调用procedure temp\_pr();**

```
create or replace function get_temp(temp_no in employee.empid%type,temp_name out employee.empname%type)return employee.empname%type is 
begin 
temp_pr(temp_no,temp_name);
return temp_name;
end;
```

 

值得注意的是get\_temp()中的参数的类型必须和procedure temp\_pr()的参数类型一致；

 

**创建一个DML statement:**

```
declare
temp_name employee.empname%type;
begin
dbms_output.put_line('姓名是'||get_temp('4',temp_name));
end;
```

 

提醒的是 out 的数据要在declare中声明；

 

output:

```
姓名是dgy
```

 

疑问：

如何将 记录型数组 作为out的部分输出了？