-1

How do I write this?

DECLARE 
STARTDATE DATE;
ENDDATE DATE;

BEGIN
STARTDATE='&&STRTDTE';
ENDDATE='&&ENDATE';
...
...
WHERE AAA_BBB.TR_DATE BETWEEN 'STARTDATE' AND 'ENDDATE';
TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

I'm guessing that you intend the script to prompt the user for the STRTDTE and ENDATE values (why "DTE" in one and "DATE" in the other, btw?).

Assuming that the user enters both dates in the current default format, then all you need is to change your where statement:

WHERE AAA_BBB.TR_DATE BETWEEN STARTDATE AND ENDDATE;

It might be safer, however, not to assume what the current format is, and actually prompt for the date in a specific format, then store the responses as dates using that specific format:

STARTDATE := TO_DATE( '&&STRTDTE', 'YYYY/MM/DD' );
ENDDATE := TO_DATE( '&&ENDATE', 'YYYY/MM/DD' );

or whatever format you wish.

Also note the := rather than =

The SE I loved is dead
  • 1,517
  • 4
  • 23
  • 27
  • I APOLOGIZE FOR BEING UNCLEAR BUT AAA_BBB IS A TABLE AND TR_DATE IS COLUMN SO WHILE AM RUNNING THIS SCRIPT I WANT TO SEARCH INSIDE A RANGE OF DATES FROM TABLE AAA_BBB – kareem elwakil May 17 '16 at 15:30
  • Yes, I understood that. You have several syntax issues in your PL/SQL, not including the assumption about the date formats: 1) don't surround your column references with quotes like you did, 2) PL/SQL assignment statements use ":=" rather than "=". – Bill Koster May 17 '16 at 15:32
  • 1
    @kareemelwakil Look to the left of your A key. There should be a button, named Caps Lock. Please turn it off. – ArtOfCode May 17 '16 at 16:23