Convert input to date with oracle

Asked

Viewed 966 times

1

I’m having trouble returning the results of the following query, where I put the variable &mes, if I put '01-Sep-2017' would bring the results I need, but in the dialog box wanted the user to type himself with the patterns used for date, with the correct '01/09/2017', however when entering this date is presented the error ORA-01858: the non-numeric Haracter was found Where a Numeric was expected

Select a.pro_st_alternativo,
   a.pro_st_descricao,
   mgadm.adm_pck_estoque.F_SALDO_QTDE(20,21,a.pro_pad_in_codigo,a.pro_in_codigo,1,null,null,to_char(to_date(&mes), 'dd/mm/yyyy'),'AN')Saldo_mes,

   a.uni_st_unidade,
   a.pro_bo_controlalotes,
   a.pro_st_cestoque,
   a.pro_st_defitem,
   A.PRO_CH_DEFFISCALITEM,
   A.PRO_ST_ORIGEM

From mgadm.est_produtos a
Where A.PRO_PAD_IN_CODIGO = 4;
  • If the date is already being received in the parameter in the format you want is only to use this way to convert it to date: to_date(&mes, 'DD/MM/YYYY').

1 answer

0


There is a function in PL/SQL called to_date. She is responsible for carrying out this conversion, thus:

to_date(&mes, 'DD/MM/YYYY')

Some example of masks:

TO_DATE('2003/07/09', 'yyyy/mm/dd')
retorna: July 9, 2003

TO_DATE('070903', 'MMDDYY')
Retorna: July 9, 2003

TO_DATE('20020315', 'yyyymmdd')
Retorna: Mar 15, 2002

You can find the complete list of masks here.

  • Thanks Luiz, to stay the way I wanted I needed to add '&mes' in the variable, asism in the same way I put up there the user just needs to type the date without putting '01/01/2017'

  • Great :) Good that it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.