ORA-01830: date format picture ends before converting entire input string / Select sum where date query

后端 未结 6 1581
梦谈多话
梦谈多话 2020-12-04 22:17

I am trying to execute my query through Java like this:

public ResultSet execSumStatment2() throws SQLException{
String query = \"Select SUM(A) as NCCSeptemb         


        
相关标签:
6条回答
  • 2020-12-04 22:29

    In SQL Developer ..Go to Preferences-->NLS-->and change your date format accordingly

    0 讨论(0)
  • 2020-12-04 22:34

    You can try this:

    Select To_date ('15/2/2007 00:00:00', 'DD/MM/YYYY HH24:MI:SS'),
           To_date ('28/2/2007 10:12', 'DD/MM/YYYY HH24:MI:SS')
      From DUAL;
    

    Source: http://notsyncing.org/2008/02/manipulando-fechas-con-horas-en-plsql-y-sql/

    0 讨论(0)
  • 2020-12-04 22:36

    You can use

    Select to_date('08/15/2017 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM') from dual;

    If you are using it in an SP then your variable datatype should be Varchar2

    and also in your ado.net code the datatype of your input parameter should be

    OracleDbType.Varchar2

    Basically I had to put a DateFrom and DateTo filter in my SP so I passed dates as String in it.

    Note: This is one of the solution which worked for me, there could be more solutions to this problem.

    0 讨论(0)
  • 2020-12-04 22:37

    What you have written in your sql string is a Timestamp not Date. You must convert it to Date or change type of database field to Timestamp for it to be seen correctly.

    0 讨论(0)
  • 2020-12-04 22:48

    You can try as follows it works for me

    select * from nm_admission where trunc(entry_timestamp) = to_date('09-SEP-2018','DD-MM-YY');
    

    OR

    select * from nm_admission where trunc(entry_timestamp) = '09-SEP-2018';
    

    You can also try using to_char but remember to_char is too expensive

    select * from nm_admission where to_char(entry_timestamp) = to_date('09-SEP-2018','DD-MM-YY');
    

    The TRUNC(17-SEP-2018 08:30:11) will give 17-SEP-2018 00:00:00 as a result, you can compare the only date portion independently and time portion will skip.

    0 讨论(0)
  • 2020-12-04 22:49

    I think you should not rely on the implicit conversion. It is a bad practice.

    Instead you should try like this:

    datenum >= to_date('11/26/2013','mm/dd/yyyy')
    

    or like

    datenum >= date '2013-09-01'
    
    0 讨论(0)
提交回复
热议问题