Question

I am trying to get the user to input a code and a date. The user will first be prompted to enter the code and then the date. This will display specific information to the user.

I am able to comment out the bottom two lines of code and successfully prompt the user for the code and receive the correct output. When I uncomment out the bottom two lines of code, it successfully prompts the user for input(which the user would enter the date), but I get a compile error.

Here is my error I receive: ORA-00932: inconsistent datatypes: expected DATE got NUMBER 00932. 00000 - "inconsistent datatypes: expected %s got %s" *Cause: *Action:Error at Line: 22 Column: 44.

Here is my code:

       WHERE END_CODE.SP_CODE = '&Enter_Code'
       AND
       DATECHART.US_DATE = &Enter_Date;
Was it helpful?

Solution

Change it like this:

   WHERE END_CODE.SP_CODE = '&Enter_Code'
   AND
   DATECHART.US_DATE = to_date('&Enter_Date','mm/dd/yyyy');

Of course if user enters date in a format other than the one specified, it will fail.

For other input formats you can use to convert an input string into a date you can read this.

OTHER TIPS

Using & to get user input does not treat it as a bind variable - it performs a simple text substitution. So, consider, e.g., you're inputing a date like 1/2/2014:

WHERE END_CODE.SP_CODE = 'someCode'
AND
DATECHART.US_DATE = 1/2/2014;

The slashes are interpreted as division operators (i.e. one divided by two divided by two thousand and fourteen, which is 0.00024826216). Since 0.00024826216 is not a date, you get an error.

One way around this is to input the date as a string, and explicitly handle its conversion:

WHERE END_CODE.SP_CODE = '&Enter_Code'
AND
DATECHART.US_DATE = TO_DATE('&Enter_Date', 'DD/MM/YYYY');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top