Skip to Main Content

SQL Developer

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Declare, Set, and Use a variable in a SQL Developer Query

748464Jan 22 2010 — edited Jan 25 2010
I come from the SQL Server world and am trying to do something very simple: Declare, set, and use a variable in a query. For example:

Declare @lastPeriod date;
Set @lastPeriod = (select max(payperiod) from table 1 where payperiod < current_date);

Select field 1,
Field2
From table2
Where payperiod = @lastPeriod

The variable is going to be used in more areas in the query which is why I am simply not using a Sub-query in the where clause. I appreciate any assistance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 22 2010
Added on Jan 22 2010
3 comments
14,233 views