Pl/SQL Procedure to compare current year with previous year in oracle.
By default, SQL*PLUS doesn't read what a PL/SQL program has written with dbms_output. With set serveroutput on, this behaviour is changed.
It is advised to run this command before executing PL/SQL program
set serveroutput on
Declare
currentYear number;
previousYear number;
begin
select TO_CHAR(sysdate, 'YYYY') into currentYear from dual;
select TO_CHAR(sysdate-1, 'YYYY') into previousYear from dual;
dbms_output.put_line('CurrentYear --' currentYear);
dbms_output.put_line('PreviousYear --'previousYear);
if currentyear= previousyear then
dbms_output.put_line('Both Year are same'); --print statement
-- if you want to use this value in your table, write a insert statement
else
dbms_output.put_line('Both Year are different'); -- print statement
-- if you want to use this value in your table, write a insert statement
end if;
end;



0 comments:
Post a Comment