Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use date variable in sql developer's "Enter Binds" dialog?

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

like image 239
vermap Avatar asked Mar 28 '14 15:03

vermap


People also ask

How do I pass a date value in SQLDeveloper?

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) & "' ..."

How do I declare a date variable in Oracle SQLDeveloper?

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');

How do you bind variables in SQL query?

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.

How do you pass a bind variable in SQL Server?

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.


4 Answers

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 is DD-MON-YYYY, you can enter 24-jan-2011 for today's date.

Worked for me.

like image 54
AntonLosev Avatar answered Oct 22 '22 06:10

AntonLosev


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

like image 33
atavio Avatar answered Oct 22 '22 06:10

atavio


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'.

like image 11
Mark J. Bobak Avatar answered Oct 22 '22 06:10

Mark J. Bobak


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).

like image 2
tbone Avatar answered Oct 22 '22 07:10

tbone