i am having problems with converting a varchar(yyyymmdd) to date(yyyymmdd).
i have a procedure with a parameter (pdate varchar2, yyyymmdd format) which needed to be converted to date type in yyyymmdd format as well. so far i tried.
vdate date;
vdate := (to_date(SUBSTR(pdate,1,4)+SUBSTR(pdate,5,2)+SUBSTR(pdate,7,2), 'yyyymmdd'));
this threw a error of ORA-01840: input value not long enough for date format.
any help would be appreciated.
+to||Consider:SELECT (SUBSTR('20170101',1,4)||SUBSTR('20170101',5,2)||SUBSTR('20170101',7,2)) , to_date(SUBSTR('20170101',1,4)||SUBSTR('20170101',5,2)||SUBSTR('20170101',7,2),'YYYYMMDD') , To_date('20170101','YYYYDDMM') from dual;to_date(pdate, 'yyyymmdd'), assuming that your pdate contains the full set of information. In fact, I'm pretty sure you can get rid of your procedure and just use theto_date()function!||in Oracle, not with+. What you are doing is that you are extracting the year, month and date, as strings (four digits, two digits, two digits). Then you add them. Behind the scenes, Oracle converts them toNUMBERand adds them. Then you applyto_date()which takes avarchar2input, so Oracle - again behind the scenes - converts the result of the addition to a four-character string. Which is not long enough to become a date (and it would be a wrong one anyway!)