1

我想从函数中检索多个值,这是我的代码:

CREATE OR REPLACE TYPE user_data_type AS OBJECT(val1 NUMBER(15), val2 NUMBER(15))


CREATE OR REPLACE FUNCTION GET_EMPLOYEE_AND_USER(in_login IN fnd_user.user_name%TYPE)
RETURN user_data_type AS
out_var user_data_type;

CURSOR buffer_cur IS
SELECT f.user_id, f.employee_id FROM Fnd_User f WHERE f.user_name=in_login;
BEGIN 
OPEN buffer_cur;
FETCH buffer_cur INTO out_var;

CLOSE buffer_cur;
RETURN out_var;
END GET_EMPLOYEE_AND_USER;

当我执行:

select * from table(get_employee_and_user('user1'))

它说: 包或函数 get_employee_and_user 处于无效状态
我是 ORACLE 的新手,所以我可能不了解基本的东西,但是当我返回一个值时它工作正常。不幸的是,当我尝试返回 rowtype 或记录它时,会显示我上面提到的错误。

4

1 回答 1

3

您必须将这些值选择到对象类型的字段中,看看:

CREATE OR REPLACE TYPE user_data_type AS OBJECT(val1 NUMBER(15), val2 NUMBER(15));
/

CREATE OR REPLACE FUNCTION GET_EMPLOYEE_AND_USER(in_login IN fnd_user.user_name%TYPE)
  RETURN user_data_type AS

  out_var user_data_type;

  CURSOR buffer_cur IS
    SELECT f.user_id, f.employee_id FROM Fnd_User f WHERE f.user_name = in_login;

BEGIN 
  OPEN buffer_cur;
  FETCH buffer_cur INTO out_var.val1, out_var.val2;

  CLOSE buffer_cur;
  RETURN out_var;
END GET_EMPLOYEE_AND_USER;
于 2013-11-05T11:25:02.673 回答