I am trying to run a query from sql developer and query has variables (:var
). I am having problem with the date variables.
I used all the possible combinations to format date using to_date()
function.
Every time getting below exception:
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Sorry can't post image here
You can use to_date function to convert the parameter string to a date. For example, you have "SELECT.... '" & p & "' ..." where p is the parameter value. You can just change to "SELECT....'" & to_date(p) & "' ..."
Answer: We can declare a date variable in PL/SQL with the syntax given below: DECLARE stdt DATE := to_date ('06/06/2006', 'DD/MM/YYYY');
Use a bind variable in PL/SQL to access the variable from SQL*Plus. Bind variables are variables you create in SQL*Plus and then reference in PL/SQL. If you create a bind variable in SQL*Plus, you can use the variable as you would a declared variable in your PL/SQL subprogram and then access the variable from SQL*Plus.
Bind parameters—also called dynamic parameters or bind variables—are an alternative way to pass data to the database. Instead of putting the values directly into the SQL statement, you just use a placeholder like ? , :name or @name and provide the actual values using a separate API call.
Just copying the answer from Oracle Community forum:
You should be able to enter dates which conform to your
NLS_DATE_FORMAT
setting.e.g. If
NLS_DATE_FORMAT
isDD-MON-YYYY
, you can enter24-jan-2011
for today's date.
Worked for me.
Try with:
SELECT TO_DATE(:my_var, 'dd.mm.yyyy') my_date from dual;
and then enter something like 01.02.2017
(without '
) as the value of :my_var
Try changing your query to be:
select first_name,
last_name,
dob,
org
from emp
where dob > to_date(:highDate,'DD-MON-YYYY');
then when prompted, enter '20-JAN-2010'
.
Try using a substitution variable. For example:
select (&var - 1) from dual;
sql developer will ask you to enter a substitution variable value, which you can use a date value (such as sysdate or to_date('20140328', 'YYYYMMDD') or whatever date you wish).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With