Here is a select statement that demonstrates the following:
- Use of CASE to do a “between” logic.
- Use of DECODE with SIGN to do a “between” logic.
- How easy and clear to use CASE as compared to using DECODE.
CREATE TABLE t
(activity_date date, date_from date, date_to DATE)
/
INSERT INTO t
VALUES (SYSDATE, SYSDATE - 1, SYSDATE + 1)
/
INSERT INTO t
VALUES (SYSDATE, SYSDATE - 10, SYSDATE - 5)
/
INSERT INTO t
VALUES (SYSDATE, SYSDATE + 1, SYSDATE + 5)
/
SELECT
activity_date,
date_from,
date_to,
CASE WHEN activity_date
BETWEEN date_from AND date_to
THEN 'between'
ELSE 'not between' END
AS case_result,
DECODE(SIGN(activity_date - date_from), -1,
'not between',
DECODE(SIGN(date_to - activity_date), -1,
'not between',
'between' ) )
AS decode_result
FROM t
/
DROP TABLE t
/
Related articles:
Tagged case, decode, function, sign | Comments Closed | Trackbacks Closed

















Home > About This Post
This entry was posted by Eddie Awad on Wednesday, June 22nd, 2005, at 12:08 pm, and was filed in Oracle.
Subscribe to the
RSS 2.0 feed for all comments to this post.
Comments Closed
Sorry, but comments have been closed.