简体   繁体   中英

PL SQL set a date variable

I am using regular SQL within PL SQL developer on Oracle 11 and would like to add a date variable to my current query that I can set for each block finding that month's EOM. I can't seem to find a good example on how to do this. Can someone provide an example of how to create, set and call a variable in SQL ?

As a very simple example:

Select employee_number, supervisor_number from T1 where effective_date = v_date.

V_date would be set elsewhere. Is this possible?

Use a colon to identify a parameter:

Select 
    employee_number, 
    supervisor_number 
from T1 
where effective_date = :v_date

I haven't used SQL Developer in a while but it seems like it would prompt you for a value, or you could set the value of the parameter in the script

variable v_date datetime;
exec :v_date := to_date('01/01/2014','mm/dd/yyyy');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM