Oracle:在函数中返回多个值 [英] Oracle: Return multiple values in a function

查看:972
本文介绍了Oracle:在函数中返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用两个表(员工和部门)从一个函数中返回一个%rowtype中的多个值,但它不适合我。

I'm trying to return a multiple values in a %rowtype from a function using two table(employees and departments), but it not working for me.

create or replace function get_employee
 (loc in number)
return mv_emp%rowtype
as  
   emp_record mv_emp%rowtype;
begin
   select a.first_name, a.last_name, b.department_name into emp_record 
   from employees a, departments b 
   where a.department_id=b.department_id and location_id=loc;

   return(emp_record);  
end;


推荐答案

上面的函数编译没有任何错误?什么是 MV_EMP 的类型?

The above function compiled without any error? What is the type of MV_EMP? Ideally, it should be something like below.

create or replace type emp_type
(
first_name varchar2(20)
, last_name varchar2(20)
, depart_name varchar2(20)
)
/
create or replace function get_employee
 (loc in number)
return emp_type
as  
   emp_record emp_type;
begin
   select a.first_name, a.last_name, b.department_name into emp_record 
   from employees a, departments b 
   where a.department_id=b.department_id and location_id=loc;

   return(emp_record);  
end;

这篇关于Oracle:在函数中返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆