How to Compare Current date year with Previous date year in Oracle

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;

About mohan

This is Mohan Jayapalan author of TechPages Blog.I am a part time blogger and Currently working for private Software Concern.

© Copyright 2010-2016 www.techpages.org · All Rights Reserved · Powered by WordPress ·