In SQL Server we can declare a variable and set the date to that variable in query like this:
GETDATE() AS currentDate
How is this accomplished in Oracle?
In SQL Server we can declare a variable and set the date to that variable in query like this:
GETDATE() AS currentDate
How is this accomplished in Oracle?
GETDATE() AS currentDate
is a column alias:
SELECT SYSDATE AS currentDate FROM dual
Variable declaration inside anonymous block:
DECLARE
currentDate DATE;
BEGIN
currentDate := SYSDATE;
END;
You can use INTO
in a query in PL/SQL block and in your case, even you can assign it directly in PL/SQL block.
Declare
lv_date1 date;
lv_date2 date;
begin
select sysdate into lv_date1 from dual; --method 1
lv_date2 := sysdate; -- method 2
end;
Cheers!!