Home » SQL & PL/SQL » SQL & PL/SQL » passing date value to the query from sql*plus
passing date value to the query from sql*plus [message #670740] Mon, 23 July 2018 17:06 Go to previous message
shrinika
Messages: 306
Registered: April 2008
Senior Member
Hello,

I am trying to pass the date parameter to the query
from sql*plus. It is passing the date. but not with HH:MI:SS.

SQL> var a varchar2(20);
SQL> var b varchar2(20);
SQL> exec :a:=to_date('20180723101002','yyyymmddhh24miss');

PL/SQL procedure successfully completed.

SQL> exec :b:=to_date('20180723235959','yyyymmddhh24miss');

PL/SQL procedure successfully completed.

SQL> print :a

A
--------------------------------
23-JUL-18

SQL> print :b

B
--------------------------------
23-JUL-18

SQL> select count(*) from v$active_session_history
  2  where sample_time between :a and :b;

  COUNT(*)
----------
         0

SQL> select count(*) from v$active_session_history
  2  where sample_time between
  3  to_date('20180723101002','yyyymmddhh24miss')
  4  and to_date('20180723235959','yyyymmddhh24miss');

  COUNT(*)
----------
      9712

SQL>


I can not use the date variable.

SQL> var a date;
Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                    VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                    NVARCHAR2 (n) | CLOB | NCLOB | BLOB | BFILE
                    REFCURSOR | BINARY_FLOAT | BINARY_DOUBLE ] ]
SQL>


Any help is greatly appreciated.
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PL/SQL: ORA-04053: error occurred when validating remote object
Next Topic: How to ensure uniqueness on RAISE_APPLICATION_ERROR
Goto Forum:
  


Current Time: Fri Apr 19 08:47:11 CDT 2024