DATE queries using BETWEEN on oracle view
up vote
0
down vote
favorite
i have a problem with a date parameter query using 'between' operator in oracle view, when i do this query :
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN to_date(sysdate - 1, 'DD-MON-YY') AND to_date(sysdate, 'DD-MON-YY');
it does not give me the records (actualy i have any record on that date).
I try using 'in' operator, but still not give me the records.
Please throw some information for this.
*checker_date defined as date
oracle
add a comment |
up vote
0
down vote
favorite
i have a problem with a date parameter query using 'between' operator in oracle view, when i do this query :
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN to_date(sysdate - 1, 'DD-MON-YY') AND to_date(sysdate, 'DD-MON-YY');
it does not give me the records (actualy i have any record on that date).
I try using 'in' operator, but still not give me the records.
Please throw some information for this.
*checker_date defined as date
oracle
What is yourMY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.
– Do Nhu Vy
14 hours ago
3
NEVER, ever callto_date()
on a value that is already a date. That will first convert thedate
value to avarchar
just to convert thatvarchar
back to adate
which it was to begin with.
– a_horse_with_no_name
14 hours ago
2
You probably needtrunc(sysdate-1)
– Marmite Bomber
14 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have a problem with a date parameter query using 'between' operator in oracle view, when i do this query :
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN to_date(sysdate - 1, 'DD-MON-YY') AND to_date(sysdate, 'DD-MON-YY');
it does not give me the records (actualy i have any record on that date).
I try using 'in' operator, but still not give me the records.
Please throw some information for this.
*checker_date defined as date
oracle
i have a problem with a date parameter query using 'between' operator in oracle view, when i do this query :
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN to_date(sysdate - 1, 'DD-MON-YY') AND to_date(sysdate, 'DD-MON-YY');
it does not give me the records (actualy i have any record on that date).
I try using 'in' operator, but still not give me the records.
Please throw some information for this.
*checker_date defined as date
oracle
oracle
edited 14 hours ago
asked 14 hours ago
Majesty Eksa Permana
443
443
What is yourMY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.
– Do Nhu Vy
14 hours ago
3
NEVER, ever callto_date()
on a value that is already a date. That will first convert thedate
value to avarchar
just to convert thatvarchar
back to adate
which it was to begin with.
– a_horse_with_no_name
14 hours ago
2
You probably needtrunc(sysdate-1)
– Marmite Bomber
14 hours ago
add a comment |
What is yourMY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.
– Do Nhu Vy
14 hours ago
3
NEVER, ever callto_date()
on a value that is already a date. That will first convert thedate
value to avarchar
just to convert thatvarchar
back to adate
which it was to begin with.
– a_horse_with_no_name
14 hours ago
2
You probably needtrunc(sysdate-1)
– Marmite Bomber
14 hours ago
What is your
MY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.– Do Nhu Vy
14 hours ago
What is your
MY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.– Do Nhu Vy
14 hours ago
3
3
NEVER, ever call
to_date()
on a value that is already a date. That will first convert the date
value to a varchar
just to convert that varchar
back to a date
which it was to begin with.– a_horse_with_no_name
14 hours ago
NEVER, ever call
to_date()
on a value that is already a date. That will first convert the date
value to a varchar
just to convert that varchar
back to a date
which it was to begin with.– a_horse_with_no_name
14 hours ago
2
2
You probably need
trunc(sysdate-1)
– Marmite Bomber
14 hours ago
You probably need
trunc(sysdate-1)
– Marmite Bomber
14 hours ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
Your first error is to call to_date() on a value that is already a DATE. to_date()
expects a VARCHAR value, so sysdate
will be first converted to VARCHAR and will then immediately be converted back to a DATE value which it was to begin with.
You probably want
AND CHECKER_DATE BETWEEN trunc(sysdate) - 1 AND trunc(sysdate)
Most probably this will still not give you want you want as that would not include rows from "today". trunc(sysdate)
means "today at midnight" and any row that was created today after midnight will not be included. With date/time values (and Oracle's DATE type does contain a time, despite the name) it's better to not use BETWEEN, but explicit range operators instead:
AND CHECKER_DATE >= trunc(sysdate) - 1
AND CHECKER_DATE < trunc(sysdate) + 1
trunc(sysdate) + 1
is tomorrow at midnight, so any value that is (strictly) smaller than that is "today".
All the above assumes that CHECKER_DATE
is defined as DATE
or TIMESTAMP
add a comment |
up vote
0
down vote
You can try:
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN trunc(sysdate - 1) AND trunc(sysdate);
Oracle advises against using to_date for date. Also trunc is here because Trunc removes the time component.
Updated. Thanks
– Gauravsa
14 hours ago
add a comment |
up vote
0
down vote
may be records are not 'Active' or 'Active' a not-existing value in one of the reference tables if any and trunc(sysdate -1) and trunc(sysdate) would help
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
Your first error is to call to_date() on a value that is already a DATE. to_date()
expects a VARCHAR value, so sysdate
will be first converted to VARCHAR and will then immediately be converted back to a DATE value which it was to begin with.
You probably want
AND CHECKER_DATE BETWEEN trunc(sysdate) - 1 AND trunc(sysdate)
Most probably this will still not give you want you want as that would not include rows from "today". trunc(sysdate)
means "today at midnight" and any row that was created today after midnight will not be included. With date/time values (and Oracle's DATE type does contain a time, despite the name) it's better to not use BETWEEN, but explicit range operators instead:
AND CHECKER_DATE >= trunc(sysdate) - 1
AND CHECKER_DATE < trunc(sysdate) + 1
trunc(sysdate) + 1
is tomorrow at midnight, so any value that is (strictly) smaller than that is "today".
All the above assumes that CHECKER_DATE
is defined as DATE
or TIMESTAMP
add a comment |
up vote
3
down vote
Your first error is to call to_date() on a value that is already a DATE. to_date()
expects a VARCHAR value, so sysdate
will be first converted to VARCHAR and will then immediately be converted back to a DATE value which it was to begin with.
You probably want
AND CHECKER_DATE BETWEEN trunc(sysdate) - 1 AND trunc(sysdate)
Most probably this will still not give you want you want as that would not include rows from "today". trunc(sysdate)
means "today at midnight" and any row that was created today after midnight will not be included. With date/time values (and Oracle's DATE type does contain a time, despite the name) it's better to not use BETWEEN, but explicit range operators instead:
AND CHECKER_DATE >= trunc(sysdate) - 1
AND CHECKER_DATE < trunc(sysdate) + 1
trunc(sysdate) + 1
is tomorrow at midnight, so any value that is (strictly) smaller than that is "today".
All the above assumes that CHECKER_DATE
is defined as DATE
or TIMESTAMP
add a comment |
up vote
3
down vote
up vote
3
down vote
Your first error is to call to_date() on a value that is already a DATE. to_date()
expects a VARCHAR value, so sysdate
will be first converted to VARCHAR and will then immediately be converted back to a DATE value which it was to begin with.
You probably want
AND CHECKER_DATE BETWEEN trunc(sysdate) - 1 AND trunc(sysdate)
Most probably this will still not give you want you want as that would not include rows from "today". trunc(sysdate)
means "today at midnight" and any row that was created today after midnight will not be included. With date/time values (and Oracle's DATE type does contain a time, despite the name) it's better to not use BETWEEN, but explicit range operators instead:
AND CHECKER_DATE >= trunc(sysdate) - 1
AND CHECKER_DATE < trunc(sysdate) + 1
trunc(sysdate) + 1
is tomorrow at midnight, so any value that is (strictly) smaller than that is "today".
All the above assumes that CHECKER_DATE
is defined as DATE
or TIMESTAMP
Your first error is to call to_date() on a value that is already a DATE. to_date()
expects a VARCHAR value, so sysdate
will be first converted to VARCHAR and will then immediately be converted back to a DATE value which it was to begin with.
You probably want
AND CHECKER_DATE BETWEEN trunc(sysdate) - 1 AND trunc(sysdate)
Most probably this will still not give you want you want as that would not include rows from "today". trunc(sysdate)
means "today at midnight" and any row that was created today after midnight will not be included. With date/time values (and Oracle's DATE type does contain a time, despite the name) it's better to not use BETWEEN, but explicit range operators instead:
AND CHECKER_DATE >= trunc(sysdate) - 1
AND CHECKER_DATE < trunc(sysdate) + 1
trunc(sysdate) + 1
is tomorrow at midnight, so any value that is (strictly) smaller than that is "today".
All the above assumes that CHECKER_DATE
is defined as DATE
or TIMESTAMP
answered 14 hours ago
a_horse_with_no_name
286k45429526
286k45429526
add a comment |
add a comment |
up vote
0
down vote
You can try:
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN trunc(sysdate - 1) AND trunc(sysdate);
Oracle advises against using to_date for date. Also trunc is here because Trunc removes the time component.
Updated. Thanks
– Gauravsa
14 hours ago
add a comment |
up vote
0
down vote
You can try:
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN trunc(sysdate - 1) AND trunc(sysdate);
Oracle advises against using to_date for date. Also trunc is here because Trunc removes the time component.
Updated. Thanks
– Gauravsa
14 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
You can try:
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN trunc(sysdate - 1) AND trunc(sysdate);
Oracle advises against using to_date for date. Also trunc is here because Trunc removes the time component.
You can try:
SELECT *
FROM MY_VIEW
WHERE STATUS = 'Active'
AND CHECKER_DATE BETWEEN trunc(sysdate - 1) AND trunc(sysdate);
Oracle advises against using to_date for date. Also trunc is here because Trunc removes the time component.
edited 14 hours ago
answered 14 hours ago
Gauravsa
1,4261816
1,4261816
Updated. Thanks
– Gauravsa
14 hours ago
add a comment |
Updated. Thanks
– Gauravsa
14 hours ago
Updated. Thanks
– Gauravsa
14 hours ago
Updated. Thanks
– Gauravsa
14 hours ago
add a comment |
up vote
0
down vote
may be records are not 'Active' or 'Active' a not-existing value in one of the reference tables if any and trunc(sysdate -1) and trunc(sysdate) would help
add a comment |
up vote
0
down vote
may be records are not 'Active' or 'Active' a not-existing value in one of the reference tables if any and trunc(sysdate -1) and trunc(sysdate) would help
add a comment |
up vote
0
down vote
up vote
0
down vote
may be records are not 'Active' or 'Active' a not-existing value in one of the reference tables if any and trunc(sysdate -1) and trunc(sysdate) would help
may be records are not 'Active' or 'Active' a not-existing value in one of the reference tables if any and trunc(sysdate -1) and trunc(sysdate) would help
answered 8 hours ago
user3439907
111
111
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371930%2fdate-queries-using-between-on-oracle-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is your
MY_VIEW
and your original database tables? Everyone cannot answer if don't know about it.– Do Nhu Vy
14 hours ago
3
NEVER, ever call
to_date()
on a value that is already a date. That will first convert thedate
value to avarchar
just to convert thatvarchar
back to adate
which it was to begin with.– a_horse_with_no_name
14 hours ago
2
You probably need
trunc(sysdate-1)
– Marmite Bomber
14 hours ago