to-date

to_char and to_date are returning different output

旧街凉风 提交于 2019-12-12 02:55:46
问题 I am using below queries. select sysdate from dual where to_char(sysdate,'DD-MM-YY')='28-MAY-13'; and the output is null. But for below query, output is current date. select sysdate from dual where to_date(sysdate,'DD-MM-YY')= to_date('28-MAY-13','DD-MM-YY'); Why the to_char function can not return the sysdate? Shouln't we use to_char to compare date? 回答1: Try 'DD-MON-YY' format to map to '28-MAY-13' 'MM' maps to the month number. EDIT: SQL can figure out to use the correct format in to_date;

Oracle SQL to_date & to_timestamp ORA-01858: a non-numeric character was found where a numeric was expected & ORA-01850: hour must be between 0 and 23

烂漫一生 提交于 2019-12-12 02:18:04
问题 I have a small bit of code: Code SELECT to_date(it.DSTAMP, 'DD/MM/YYYY') AS "Date", to_timestamp(it.DSTAMP, 'HH24:MI:SS') AS Time FROM itable it Errors ORA-01858: a non-numeric character was found where a numeric was expected 01858. 00000 - "a non-numeric character was found where a numeric was expected" *Cause: The input data to be converted using a date format model was incorrect. The input data did not contain a number where a number was required by the format model. *Action: Fix the input

ORACLE 10g : To_date() Not a valid month

拜拜、爱过 提交于 2019-12-11 06:14:34
问题 So I have this little script : set serveroutput on; DECLARE val DATE; BEGIN val := TO_DATE('27-Jan-2001','DD-Mon-YYYY'); dbms_output.put_line(val); END; The mask match with the date I'm inputing but it displays ORA-01843: not a valid month every time... Thanks 回答1: Most likely your current session NLS_DATE_LANGUAGE is set to a value where January is not abbreviated as "Jan". Try this: DECLARE val DATE; BEGIN val := TO_DATE('27-Jan-2001','DD-Mon-YYYY', 'NLS_DATE_LANGUAGE = american'); dbms

What exact exception to be caugth while calling TO_DATE in pl/sql code

痞子三分冷 提交于 2019-12-11 01:34:11
问题 I have below code to_date('1311313', 'yymmdd') which actually throws exception with saying invalid month . Which is can manage as exception when others then sop('date format is wrong'); Here the problem is everything will get caught which I do not want to do as if some other error will occur then also it will pass the message date format is wrong . I also do not want to create a user defined exception. Just want to know which exception is being thrwon out so that I can use in my code like

Literal does not match format string for Oracle SQL to_date on a string column

假如想象 提交于 2019-12-10 17:18:44
问题 Dear SQL Gurus from Stack Overflow: Environment: Oracle I'm trying to understand why I can't do a to_date selection on a table column that contains strings. Note tableZ with a column of name Value in the example below contains a bunch of strings, some of which are the correct format, for example 6/20/2010 00:00:00. tableZ | Value | | __________________ | | 6/21/2010 00:00:00 | | Somestring | | Some Other strings | | 6/21/2010 00:00:00 | | 6/22/2010 00:00:00 | The following works SELECT To

Oracle: Avoiding NULL value in to_date

柔情痞子 提交于 2019-12-10 14:55:10
问题 I have a functional select statement that has a where clause, in the where clause there is a statement like so... to_date(camp.start_date, 'MM/DD/YYYY') >= to_date(:from_date, 'YYYY-MM-DD HH24:MI:SS') However, if camp.start_date is NULL or has no rows then it is throwing an exception - ORA-01858: a non-numeric character was found where a numeric was expected camp.start_date is actually a VARCHAR2 that I need to convert into a date, (yes I know it probably should be a date field but I don't

Oracle SQL convert date format from DD-Mon-YY to YYYYMM

99封情书 提交于 2019-12-07 10:20:30
问题 I have a to compare dates in 2 tables but the problem is that one table has the date in DD-Mon-YY format and the other in YYYYMM format. I need to make both of them YYYYMM for the comparison. I need to create something like this: SELECT * FROM offers WHERE offer_date = (SELECT to_date(create_date, 'YYYYMM') FROM customers where id = '12345678') AND offer_rate > 0 where create_date is something like 12-Mar-2006 and offer_date is something like 200605 Any ideas where I need to adapt this query?

Oracle SQL convert date format from DD-Mon-YY to YYYYMM

雨燕双飞 提交于 2019-12-05 17:42:13
I have a to compare dates in 2 tables but the problem is that one table has the date in DD-Mon-YY format and the other in YYYYMM format. I need to make both of them YYYYMM for the comparison. I need to create something like this: SELECT * FROM offers WHERE offer_date = (SELECT to_date(create_date, 'YYYYMM') FROM customers where id = '12345678') AND offer_rate > 0 where create_date is something like 12-Mar-2006 and offer_date is something like 200605 Any ideas where I need to adapt this query?? As offer_date is an number, and is of lower accuracy than your real dates, this may work... - Convert

Oracle uses or ignores indexed column depending on the format of to_date(literal)

空扰寡人 提交于 2019-12-03 07:50:24
问题 I'm using an indexed column used as a filter by putting it 'between' two literal values. (The column is in the second position of the index and actually makes execution slower; I will deal with that later). What's confusing me is that Oracle (11.2.0.3.0) uses or ignores said index depending on the format of the value and format strings supplied to to_date: This ignores the index: SQL> SELECT * 2 FROM gprs_history_import gh 3 WHERE start_call_date_time BETWEEN 4 to_date('20140610 000000',

Oracle to_date with p.m./a.m

给你一囗甜甜゛ 提交于 2019-12-02 07:28:11
问题 I need to convert a string into a Date in oracle. The format of the string is like this: '08/11/1999 05:45:00 p.m.' But the last position can change p.m or a.m. I tried to do some like: to_date('08/11/1999 05:45:00 p.m.', 'dd/mm/yyyy hh:mi:ss a.m./p.m.') to_date('08/11/1999 05:45:00 p.m.', 'dd/mm/yyyy hh:mi:ss am/pm') But return me an error ORA-01855 : AM/A.M. or PM/P.M. required... any idea ? 回答1: Try this: to_date ( '08/11/1999 05:45:00 p.m.' , 'dd/mm/yyyy hh:mi:ss a.m.' , 'nls_date