Created
November 6, 2017 22:46
-
-
Save randyburden/08c1698bc180e98b9247a165dead7d2e to your computer and use it in GitHub Desktop.
Oracle PL/SQL example of a query with an optional date range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Oracle PL/SQL example of a query with an optional date range */ | |
SET SERVEROUTPUT ON; | |
DECLARE | |
StartDate DATE := NULL; | |
EndDate DATE := NULL; | |
--StartDate DATE := TO_DATE ('01/01/2017', 'mm/dd/yyyy'); | |
--EndDate DATE := TO_DATE ('02/01/2017', 'mm/dd/yyyy'); | |
RecordCount NUMBER; | |
BEGIN | |
SELECT COUNT(*) | |
INTO RecordCount | |
FROM TABLE_NAME t | |
WHERE (StartDate IS NULL OR t.DATE_COLUMN >= StartDate) | |
AND (EndDate IS NULL OR t.DATE_COLUMN <= EndDate); | |
DBMS_OUTPUT.PUT_LINE(RecordCount); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment