Oracle 执行存储过程不返回所有列和结果

Oracle executing stored procedure not returning all the columns and result

我在 Oracle 中有这个存储过程:

create or replace PROCEDURE "SP_ATTENDANCE_DETAILS_SELECT" 
(
  employeeid IN tblemployees.empid%type,
  parmonth IN integer,
  paryear IN integer,
  p_rec  OUT SYS_REFCURSOR
)
AS 
BEGIN
---------------------------------------------------------------------
--  Revisions:
--  20150623      cschua       Added AWOL when checking leavetype
---------------------------------------------------------------------
  OPEN p_rec
       FOR
SELECT emp.EmpID,to_char(att.AttendanceDate, 'YYYY-MM-DD') AS AttendanceDate,
              CASE WHEN (upper(att.leavetype) = 'LEAVE W/O PAY' OR upper(att.leavetype) = 'HL' OR upper(att.leavetype) = 'AWOL')
                  THEN att.LeaveType
                  WHEN att.tardiness != 0
                  THEN 'Late'
                   END AS Description
    FROM tblemployees emp
 LEFT JOIN tblattendancedtl att
        ON emp.EmpID = att.EmpID
         AND (att.Month = parmonth OR parmonth = 0)
         AND (att.Year = parYear  OR parYear = 0)
         --modified by kim ivan 2020-11-18
         --AND (upper(att.leavetype) IN ('LEAVE W/O PAY', 'SICK LEAVE', 'AWOL')
         AND (upper(att.leavetype) IN ('NPL', 'HL', 'AWOL')
              OR att.tardiness != 0)
        WHERE emp.EmpID = employeeid
      ORDER BY att.AttendanceDate ASC;
        
END SP_ATTENDANCE_DETAILS_SELECT;

问题是如果我只执行存储过程中的 select,它会按预期工作:

SELECT 
    emp.EmpID,
    to_char(att.AttendanceDate, 'YYYY-MM-DD') AS AttendanceDate,
    --modified by kim ivan 2020-11-18
    -- (CASE WHEN (upper(att.leavetype) = 'LEAVE W/O PAY' OR upper(att.leavetype) = 'SICK LEAVE' OR upper(att.leavetype) = 'AWOL')
    (CASE WHEN (upper(att.leavetype) = 'LEAVE W/O PAY' OR upper(att.leavetype) = 'HL' OR upper(att.leavetype) = 'AWOL')
                  THEN att.LeaveType
                  WHEN att.tardiness != 0
                  THEN 'Late'
                   END) AS Description
FROM 
    tblemployees emp
LEFT JOIN 
    tblattendancedtl att ON emp.EmpID = '13001495'
                         AND (att.Month = 7 OR 7 = 0 )
                         AND (att.Year = 2020 OR 2020=0 )
                         --modified by kim ivan 2020-11-18
                         --AND (upper(att.leavetype) IN ('LEAVE W/O PAY', 'SICK LEAVE', 'AWOL')
                         AND (upper(att.leavetype) IN ('NPL', 'HL', 'AWOL')
                              OR att.tardiness != 0)
WHERE 
    emp.EmpID = '13001495'
ORDER BY 
    att.AttendanceDate ASC;
      

的结果
EmpID     AttendanceDate   Description
--------------------------------------
13001495    2020-07-04      Late
13001495    2020-07-13      Late
13001495    2020-07-13      Late

但是当我尝试使用这个来执行整个过程时

var r refcursor;
exec SP_ATTENDANCE_DETAILS_SELECT('13001495',7,2020,:r);
print r;

只有 returns 1 行只有员工 ID

EmpID     AttendanceDate   Description
---------------------------------------
13001495    

怎么了?看起来很正确,我卡在了这一点上。

我希望有人能帮我解决这个问题。

谢谢

我可以在此处的 JOIN 条件下看到您的 procedurequery 的明显区别:

程序中:

ON emp.EmpID = att.EmpID

在查询中:

ON emp.EmpID = '13001495' --> It should be ON emp.EmpID = att.EmpID

在查询中更改相同的内容,看看它给您的结果。