이것은 바보 같은 질문처럼 보일지 모르지만 저는 거의 SQL을 사용하지 않습니다.두 날짜 간의 행?
테이블 Empl_Transactions
에 DATETIME_INS라는 datetime 열이 있습니다. 이 열의 값은 11/28/2016 2:23:00
입니다.
DATETIME_INS 열이 어제 날짜 인 모든 행을 반환하고 싶습니다. 그래서 다음과 같은 쿼리를 시도했지만, 내가 찾고있는 것을 반환하지는 않습니다. 처음 두 쿼리는 오늘 날짜가있는 행을 반환한다고 생각했습니다.
-- This returns rows inserted today
select * from Empl_Transactions WHERE
DATETIME_INS >= SYSDATE-1 and DATETIME_INS < SYSDATE
-- This also returns rows inserted today
select * from Empl_Transactions WHERE
DATETIME_INS >= CURRENT_DATE-1 and DATETIME_INS < CURRENT_DATE
-- This returns 0 rows
select * from Empl_Transactions WHERE
DATETIME_INS >= to_date(CURRENT_DATE-1,'DD-MM-YYYY')
and DATETIME_INS < to_date(CURRENT_DATE,'DD-MM-YYYY')
-- works correctly, but I'm using a static value as date
select * from Empl_Transactions WHERE
DATETIME_INS >= to_date('11/27/2016','MM-DD-YYYY')
DATETIME_INS < to_date('11/28/2016','MM-DD-YYYY')
order by DATETIME_INS asc
-- I get error "Not a valid month"
select * from Empl_Transactions WHERE
DATETIME_INS >= to_date(CURRENT_DATE-1,'MM-DD-YYYY')
and DATETIME_INS < to_date(CURRENT_DATE,'MM-DD-YYYY')
날짜 시간 데이터 유형이 포함되어 시간 부분뿐만 아니라, 그래서 만약 당신이 날짜 porti 필요 trunc (DATETIME_INS) = trunc (sysdate) - 1 –
TRUNC를 사용할 때의 문제점은 결과를 표시하는 데 2 분 이상 걸리므로, 시도해 보니 데이터가 거의 즉시 반환됩니다 (잘못된 경우에도). – rbhat
btw 여기에 PL/SQL이 없습니다. –