Thank you johnsone.
Can you comment on why you used column - new value verses the define statement? I am somewhat new to SQLPlus and until this issue the define statement always worked for me.
Thanks.
Main Topics
Browse All TopicsI am trying to declare a variable in SQL plus using the SQL Plus tool, not create a package but using the user interface tool. Then set the variable using a value from a SQL statement. Then finally use that value as a filter to several other queries. Here is what I have so far but I am having trouble assigning the SYSDATE less one hour to my variable "StartTime". The value comes through as the character string SQL not the SYSDATE less an hour.
undefine StartTime;
define StartTime = SELECT SYSDATE - 60/1440 FROM DUAL;
SELECT '&StartTime' FROM DUAL;
SELECT * FROM TABLE1 WHERE CREATE_DATE > '&StartTime';
SELECT * FROM TABLE2 WHERE UPDATE_DATE > '&StartTime';
SELECT * FROM TABLE3 WHERE RECEIVED_DATE > '&StartTime';
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
That is always the way I have done it since Oracle 7. The define is not necessary.
By no means is this the only way to do what you want. My preferred way would be declaring a variable and using it in a bind, but it sounded like you wanted to avoid that.
variable StartTime varchar2(100);
begin
select to_char(sysdate - 60/1440, 'mmddyyyyhh24miss')
into :StartTime
from dual;
end;
/
select :StartTime from dual;
SELECT * FROM TABLE1 WHERE CREATE_DATE > to_date(:StartTime, 'mmddyyyyhh24mis');
SELECT * FROM TABLE2 WHERE UPDATE_DATE > to_date(:StartTime, 'mmddyyyyhh24mis');
SELECT * FROM TABLE3 WHERE RECEIVED_DATE > to_date(:StartTime, 'mmddyyyyhh24mis');
Business Accounts
Answer for Membership
by: johnsonePosted on 2007-09-19 at 10:52:33ID: 19922852
This should do what you are looking for:
column StartTime new_value StartTime;
select sysdate - 60/1440 StartTime from dual;
SELECT '&StartTime' FROM DUAL;
SELECT * FROM TABLE1 WHERE CREATE_DATE > '&StartTime';
SELECT * FROM TABLE2 WHERE UPDATE_DATE > '&StartTime';
SELECT * FROM TABLE3 WHERE RECEIVED_DATE > '&StartTime';