I have year as a parameter in proc which can be 2017,2018,etc.
I want get 1 Jan of that year in Date Format in oracle server.
Is there any way to do that ?
I have year as a parameter in proc which can be 2017,2018,etc.
I want get 1 Jan of that year in Date Format in oracle server.
Is there any way to do that ?
Assuming your parameter is P_year...
TO_DATE('01/01/'||P_year,'DD/MM/YYYY')
You may need something like:
create or replace procedure checkDate ( pYear IN number) is
vNum number;
begin
select count(1)
into vNum
from ( select sysdate as dateColumn from dual) someTable
where dateColumn > to_date('01-01-' || pYear, 'dd-mm-yyyy');
--
dbms_output.put_line(vNum);
end;
Simply converting a year to a date will do the trick
SQL> select to_date('2017','YYYY') from dual;
TO_DATE('2017','YYY
-------------------
01/01/2017 00:00:00
but if you are concerned that at some stage this default might change, you can also truncate the data down to the year to be absolutely sure
SQL> select trunc(to_date('2017','YYYY'),'YYYY') from dual;
TRUNC(TO_DATE('2017
-------------------
01/01/2017 00:00:00
As metioned above TRUNC will be best suited in this case.
SET define ON;
SET serveroutput ON;
DECLARE
lv_var VARCHAR2(100):='&Enter_year';
lv_date DATE;
begin
SELECT TRUNC(to_date(lv_var,'YYYY')) INTO lv_date FROM dual;
dbms_output.put_line(lv_date||' --> Req date');
END;