在oracle中的以下代码中获取无效列错误。但是当我分别执行分配给游标的查询时,它工作得很好。请让我知道我在做什么错误:
CREATE OR REPLACE PROCEDURE etl_mergeEmployeeAttendee
(
v_EmployeeNumber IN VARCHAR2 DEFAULT NULL ,
v_AttendeeName OUT NVARCHAR2,
v_EmployeeAttendeeId OUT NUMBER,
v_AttendeeTitle OUT NVARCHAR2,
v_Company OUT NVARCHAR2,
v_Relationship OUT NVARCHAR2,
v_Operation OUT NUMBER,
v_Error OUT NUMBER
)
AS
v_Employee_AttendeeId NUMBER(10,0);
v_Employee_Id NUMBER(10,0);
v_Attendee_Name NVARCHAR2(50);
v_Attendee_Title NVARCHAR2(50);
v_Com_pany NVARCHAR2(50);
v_Relation_ship NVARCHAR2(50);
CURSOR sel_prod_attendee_csr
IS SELECT a.EmployeeAttendeeId ,
a.EmployeeId ,
a.AttendeeName ,
a.AttendeeTitle ,
a.Company ,
a.Relationship
FROM EmployeeAttendee a,
Employee b
WHERE b.EmployeeNumber = v_EmployeeNumber
AND a.EmployeeId = b.EmployeeId;
BEGIN
OPEN sel_prod_attendee_csr;
FETCH sel_prod_attendee_csr INTO
v_Employee_AttendeeId, v_Employee_Id,v_Attendee_Name,v_Attendee_Title,v_Com_pany,v_Relation_ship;
IF sel_prod_attendee_csr%FOUND= true THEN
/* found */
BEGIN
v_Operation := 1 ;
v_AttendeeTitle := v_Attendee_Title ;
v_Company := v_Com_pany ;
v_Relationship := v_Relation_ship ;
v_AttendeeName :=v_Attendee_Name;
END;
ELSE
v_Operation := 2 ;-- Insert
END IF;
CLOSE sel_prod_attendee_csr;
END;
答案 0 :(得分:1)
您可以获得的最佳建议 - 当您可以使用隐式游标时,请不要使用显式游标。它们通常更快,需要更少的代码,更易于维护,并且您不太可能遇到这样的错误。
将其改写为表格:
For sel_prod_attendee_csr in
select a.EmployeeAttendeeId ,
...
from ...
loop
etl_mergeEmployeeAttendee.EmployeeAttendeeId = a.EmployeeAttendeeId;
...
如您所见,您可以转储丑陋的“v_”前缀,并使用过程名称命名变量。
如果您只想要一行,那么只需使用SQL语句:
select a.EmployeeAttendeeId ,
...
into etl_mergeEmployeeAttendee.EmployeeAttendeeId
from ...
考虑到程序的名称,我怀疑你完全倾销PL / SQL游标代码并且只是运行一个直接的SQL语句会好得多。