oracle 每当我编译这两个查询它显示错误请帮助我解决

vdzxcuhz  于 2023-11-17  发布在  Oracle
关注(0)|答案(2)|浏览(124)

下面提到的查询在Oracle SQL中没有编译,查询有什么问题

SELECT AttendanceId, E.FIRSTNAME || ' ' || E.LASTNAME AS FullName, E.EmpID, E.JobCode, E.Address as Location,  E.VSMS_Id, A.LoginId,upper(ShiftName) ShiftName,To_char(AttendanceDate, 'dd-MMM-yy') AttendanceDate, to_char(AttendanceDate, 'ddd') as dayName1,  
      TO_CHAR(ShiftStartTime,'hh:mm tt') ShiftStartTime, TO_CHAR(ShiftEndTime,'hh:mm tt') ShiftEndTime, 
      TO_CHAR((SignOut,SignIn)/60 )|| ' Hrs' || ':'|| SUBSTR('0' + TO_CHAR( (SignOut,SignIn)%60)(2)), 
      GREATEST(-LENGTH('0' + TO_CHAR(DATEDIFF(SignOutMinute -SignIn, SignOut)%60 AS VARCHAR2(2))), -2))||' Min' as  Duration,  SignIn, SignOut, Remark FROM T_ATTENDANCE_ATTENDANCE A  
      LEFT JOIN USERMASTER U  ON U.LOGINID = A.LOGINID  
      LEFT JOIN EMPLOYEEMASTER E ON E.EMPID = U.EMPID    
      WHERE EXTRACT(YEAR FROM ATTENDANCEDATE) = V_YEAR AND EXTRACT(MONTH FROM ATTENDANCEDATE) = V_MONTH  AND A.active = 1  
      And a.LoginId = case when nvl(V_LoginId,'') = '' then a.LoginId else V_LoginId end  
      order by A.AttendanceDate ASC



--------------------------------------------------------------------------------------------------------------------------------------

SELECT E.FIRSTNAME || ' ' || E.LASTNAME AS FullName, E.EmpID, E.JobCode, E.Address as Location, 
        E.VSMS_Id, A.LoginId,upper(ShiftName) ShiftName, To_char(AttendanceDate, 'dd-MMM-yy') AttendanceDate, 
        to_char(AttendanceDate, 'ddd') as dayName1,  SignIn, SignOut, 
        TO_CHAR( (SignOut -SignIn) * 1440/60 (5))|| ' Hrs' || ':'|| SUBSTR('0' + TO_CHAR( (SignOut -SignIn) * 1440%60 (2)), GREATEST(-LENGTH('0' + TO_CHAR( DATEDIFF(SignOutMinute -SignIn, SignOut) * 1440%60 AS VARCHAR2(2))), -2))||' Min' as  Duration,
        case When upper(ShiftName) = 'MORNING' then 1 
             When upper(ShiftName) = 'GENERAL1' then 2 
             When upper(ShiftName) = 'GENERAL2' then 3 
             when upper(ShiftName) = 'AFTERNOON1' then 4 
             when upper(ShiftName) = 'AFTERNOON2' then 5 
             When upper(ShiftName) = 'NIGHT' then 6
             else 7 end ShiftOrder
         FROM T_ATTENDANCE_ATTENDANCE A
        LEFT JOIN T_ATTENDANCE_USER_MASTER U  ON U.LOGINID = A.LOGINID
        LEFT JOIN T_ATTENDANCE_EMPLOYEE_MASTER E ON E.EMPID = U.EMPID       
        Join T_ATTENDANCE_USER_ATTENDANCE_TEAM uat on uat.LoginId = U.LoginID and uat.isActive = 'Y' and uat.TowerPK =
        case when nvl(V_Tower,'') = '' then '' else V_Tower end  
        and A.Active = 1
        AND ATTENDANCEDATE= V_AttendanceDate

字符串

u0sqgete

u0sqgete1#

简单地说,这不是Oracle。
我注解了部分代码,这些代码肯定不会工作,

  • 无效的日期格式掩码(有关有效选项,请参阅文档)
  • 串联运算符是双管道,而不是加号
  • 没有datediff函数
  • %60也是错误的;我不知道它在你使用的语言中是什么
  • Oracle中的空字符串等于NULL

我尽我所能去解决它,我理解。

SELECT attendanceid,
         e.firstname || ' ' || e.lastname AS fullname,
         e.empid,
         e.jobcode,
         e.address AS location,
         e.vsms_id,
         a.loginid,
         UPPER (shiftname) shiftname,
         --
         TO_CHAR (attendancedate, 'dd-mon-yy') attendancedate,
         -- TO_CHAR (attendancedate, 'dd-MMM-yy') attendancedate,
         --
         TO_CHAR (attendancedate, 'ddd') AS dayname1,
         --
         TO_CHAR (shiftstarttime, 'hh:mi') shiftstarttime,
         -- TO_CHAR (ShiftStartTime, 'hh:mm tt') ShiftStartTime,
         --
         TO_CHAR (shiftendtime, 'hh:mi') shiftendtime,
         -- TO_CHAR (ShiftEndTime, 'hh:mm tt') ShiftEndTime,
         /*
         TO_CHAR((SignOut,SignIn)/60 )|| ' Hrs' || ':' || SUBSTR('0' || TO_CHAR( (SignOut,SignIn)%60)(2)),
         GREATEST(-LENGTH('0' + TO_CHAR(DATEDIFF(SignOutMinute -SignIn, SignOut)%60 AS VARCHAR2(2))), -2))||' Min' as Duration,
         */
         signin,
         signout,
         Remark
    FROM t_attendance_attendance a
         LEFT JOIN usermaster u ON u.loginid = a.loginid
         LEFT JOIN employeemaster e ON e.empid = u.empid
   WHERE     EXTRACT (YEAR FROM attendancedate) = v_year
         AND EXTRACT (MONTH FROM attendancedate) = v_month
         AND a.active = 1
         AND a.loginid = NVL (v_loginid, a.loginid)
             -- CASE WHEN NVL (v_loginid, '') = '' THEN a.loginid ELSE v_loginid END
ORDER BY a.attendancedate ASC;

字符串

s6fujrry

s6fujrry2#

您的日期格式模型错误:MMM应该是MONhh:mm tt应该是HH24:MIHH12:MI AM,如果您想要日期名称,则ddd应该是day(或fmday)。
您还需要修复持续时间代码,因为DATEDIFF应该只是减法,而Oracle有MOD函数(而不是%运算符);但是,您可以使用EXTRACT简化该问题:

SELECT AttendanceId,
       E.FIRSTNAME || ' ' || E.LASTNAME AS FullName,
       E.EmpID,
       E.JobCode,
       E.Address as Location,
       E.VSMS_Id,
       A.LoginId,
       upper(ShiftName) AS ShiftName,
       To_char(AttendanceDate, 'dd-mon-yy') AS AttendanceDate, 
       to_char(AttendanceDate, 'day') AS dayName1,  
       TO_CHAR(ShiftStartTime,'hh24:mi') AS ShiftStartTime, 
       TO_CHAR(ShiftEndTime,'hh24:mi') AS ShiftEndTime,
       EXTRACT(HOUR FROM (signout - signin) DAY TO SECOND) || ' Hrs'
       || ':'
       || LPAD(EXTRACT(MINUTE FROM (signout - signin) DAY TO SECOND), 2, '0') ||' Min'
         as Duration,
       SignIn,
       SignOut,
       Remark
FROM   T_ATTENDANCE_ATTENDANCE A  
       LEFT JOIN USERMASTER U
       ON U.LOGINID = A.LOGINID  
       LEFT JOIN EMPLOYEEMASTER E
       ON E.EMPID = U.EMPID    
WHERE  ATTENDANCEDATE >= TO_DATE(V_YEAR||'-'||V_MONTH||'-01', 'YYYY-MM-DD')
AND    ATTENDANCEDATE <  TO_DATE((V_YEAR+1)||'-'||V_MONTH||'-01', 'YYYY-MM-DD')
AND    A.active = 1  
And    (a.LoginId = V_LoginId OR v_loginid IS NULL) 
order by A.AttendanceDate ASC

字符串

相关问题