PLS-00302:必须声明组件“ EXISTS”

时间:2018-08-18 16:34:40

标签: plsql oracle11g

我的以下功能确实存在问题,不断出现错误

  

PLS-00302:必须声明组件'EXISTS'

在测试我的功能时。如果我删除了if语句,他也会给出FIRST错误,必须声明。

如果有人可以帮助我,这将意味着世界!

CREATE OR REPLACE PACKAGE hr_package IS    

TYPE seniority_type_rec IS RECORD (f_name employees.first_name%TYPE, l_name 
employees.last_name%TYPE, seniority NUMBER);
TYPE seniority_table_type IS TABLE OF seniority_type_rec INDEX BY 
PLS_INTEGER;
FUNCTION calc_seniorities (p_seniority PLS_INTEGER) RETURN 
seniority_table_type ;        

END hr_package;   
/

/*  DEEL 2: PACKAGE BODY */

CREATE OR REPLACE PACKAGE BODY hr_package IS 


/* needs to return a list of employees with seniority over the parameter 
p_seniority using bulk sql, return type seniority_table_type with first 
name, last name and seniority*/

FUNCTION calc_seniorities (p_seniority PLS_INTEGER) 
RETURN seniority_table_type IS 
emp_table seniority_table_type;

BEGIN 
SELECT first_name, last_name, p_seniority BULK COLLECT INTO emp_table FROM 
job_history h join employees e on h.employee_id = e.employee_id WHERE 
FLOOR((MONTHS_BETWEEN(start_date,end_date))/12) >= p_seniority;
return emp_table;
END; 

END hr_package;
/

/*  DEEL 3: TESTCODE */

DECLARE
query_result hr_package.seniority_table_type;
BEGIN query_result := hr_package.calc_seniorities(5);
FOR i IN 1..query_result.COUNT LOOP
if query_result(i).exists then 
DBMS_OUTPUT.PUT_LINE(query_result(i).first_name);
end if;
END LOOP;
END;
/ 

1 个答案:

答案 0 :(得分:1)

我猜想(i)移到了错误的位置,实际上应该是exists的参数吗?再次将其移到正确的位置。

...
if query_result.exists(i) then
...