【问题标题】:Oracle executing stored procedure not returning all the columns and resultOracle 执行存储过程不返回所有列和结果
【发布时间】:2020-11-20 12:57:27
【问题描述】:

我在 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 
    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;

它只返回 1 行,仅包含员工 ID

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

怎么了?这似乎是正确的,我被困在这一点上。

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

谢谢

【问题讨论】:

    标签: oracle oracle11g oracle-sqldeveloper


    【解决方案1】:

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

    在程序中:

    ON emp.EmpID = att.EmpID
    

    在查询中:

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

    在查询中更改相同的内容,看看它会给你什么结果。

    【讨论】:

      猜你喜欢
      • 2018-06-21
      • 2018-11-07
      • 2016-02-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      相关资源
      最近更新 更多