oracle - 从时间中提取小时并添加转换为小时的分钟并从时间中提取分钟并找到提醒(模数)
问题描述
我正在尝试从时间中提取小时并将分钟转换为小时,并从时间中提取分钟并在 Oracle SQL 中找到提醒(模)。到目前为止,我检查了几个链接并尝试用谷歌搜索,但找不到任何解决方案。到目前为止,这是我尝试做的
SELECT
CONCAT(
-- extract hours from time and add minutes converted to hours
(SUM(SUBSTR(m.Time, ':', 1)) + TRUNCATE((SUM(SUBSTR(m.Time, ':', -1)) / 60),0)),
':',
-- extract minutes from time and find reminder (modulo)
LPAD((SUM(SUBSTR(m.Time, ':', -1)) MOD 60), 2, 0)) hours,
CONCAT(CONCAT(u.Surname, ' '),u.Lastname) AS Username,
u.UserID AS UserId,
ut.Date_,
m.MomentID
FROM
moments m
LEFT JOIN
user_timesheets ut
ON
ut.UserTimesheetsID = m.UserTimesheetsID
LEFT JOIN
users u
ON
ut.user_id = u.UserID
WHERE
EXTRACT (MONTH FROM TO_DATE(ut.Date_,'YYYY-MM-DD')) = '2020-01-21'
-- EXTRACT (MONTH FROM TO_DATE(ut.Date_)) = '2020-07-30'
AND
EXTRACT (YEAR FROM TO_DATE(ut.Date_,'YYYY-MM-DD')) = '2020-01-21'
-- EXTRACT (YEAR FROM TO_DATE(ut.Date_)) = '2020-07-30'
AND
ut.user_id = 1
AND
(SELECT MAX(MomentID) FROM moments WHERE m.parent = m.MomentID) IS NULL
AND
m.AtestStatus = 1
这里的问题是当我运行这个查询时出现错误
The identifier name started with an ASCII character other than a
letter or a number. After the first character of the identifier
name, ASCII characters are allowed including "$", "#" and "_".
Identifiers enclosed in double quotation marks may contain any
character other than a double quotation. Alternate quotation
marks (q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action: Check the Oracle identifier naming convention. If you are
attempting to provide a password in the IDENTIFIED BY clause of
a CREATE USER or ALTER USER statement, then it is recommended to
always enclose the password in double quotation marks because
characters other than the double quotation are then allowed.
如果这个问题对你来说很愚蠢,我很抱歉,但我完全是 PL/SQL 的初学者,我只是在寻求帮助。干杯:)
更新
由于我将 % 更改为MOD
现在,我得到了错误
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 7 Column: 64
解决方案
这是错误的:
LPAD((SUM(SUBSTR(m.Time, ':', -1)) % 60), 2, 0)
-
this!
标题说你需要使用模数;如果是这样,Oracle 函数名称是MOD
. 请参阅文档。
推荐阅读
- css - CSS 转换在 Mozilla 浏览器中不起作用
- kivy - 如何创建高度可调的 KivyMD 卡
- java - 带有 WebClient 的 Cron 调度程序
- php - PHP替换特定字符串后的值
- laravel - 在 laravel 中使用多对多关系同步:PostgreSQL 数据透视表不更新
- c++ - 无法编译包括文件系统的 C++ 程序
- eclipse - Tomcat 9/Eclipse 2020-12:HTTP 状态 404
- python-3.x - 当我使用 linux penguin 在 chromebook 上安装 python 3.9 时,我仍然看到旧版本
- react-native - 在 react native 中单击按钮上的 json 对象生成 CSV 文件
- c++ - 无限循环的编译器优化