I'm using an External Table in Oracle 11g. I have a date field in the last column of the file. I parse that in into a TIMESTAMP column in my table definition:
CREATE TABLE e_tbl_one
(
FOPV_KEY INTEGER,
FACILITY VARCHAR2(50),
QTY_6HR NUMBER,
SECURITY_CODE NUMBER,
LOAD_DATE TIMESTAMP(0) WITH LOCAL TIME ZONE
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY MYDB_EXTERNAL_TABLE_DATA
ACCESS PARAMETERS
( records delimited by newline SKIP 1
NOBADFILE
NOLOGFILE
fields terminated by '|'
missing field values are null
(
FOPV_KEY,
FACILITY,
QTY_6HR,
SECURITY_CODE,
LOAD_DATE date 'mm/dd/yyyy hh:mi:ss am'
)
)
LOCATION (MYDB_EXTERNAL_TABLE_DATA:'e_tbl_one.txt')
)
REJECT LIMIT UNLIMITED
NOPARALLEL
NOMONITORING;
This will parse the date 11/10/2015 1:59:37 PM but not 11/10/2015 01:59:37 PM or 11/10/2015 12:45:12 PM
The log file shows:
KUP-04021: field formatting error for field LOAD_DATE
KUP-04026: field too long for datatype
KUP-04101: record 2 rejected in file /dbfs_direct/FS1/MYDB_EXTERNAL_TABLE/e_tbl_one.txt
The data for LOAD_DATE at this time was: 11/11/2015 07:28:36 am. The record in the text file is:
70581692|WS3|308|2048|11/11/2015 07:41:00 am[CRLF]
Why can't this be parsed as LOAD_DATE date 'mm/dd/yyyy hh:mi:ss am'?
Related
Attempting to cast a string (formatted as YYYY-MM-DD) as ISO date. It's already in the right format but it is erroring out.
SELECT
*
FROM TABLE1
WHERE CHAR(VARCHAR((SUBSTRING(PARAMETER_VALUE,8,4)||
CASE SUBSTRING(PARAMETER_VALUE,4,3)
WHEN 'Jan' THEN '-01-'
WHEN 'Feb' THEN '-02-'
WHEN 'Mar' THEN '-03-'
WHEN 'Apr' THEN '-04-'
WHEN 'May' THEN '-05-'
WHEN 'Jun' THEN '-06-'
WHEN 'Jul' THEN '-07-'
WHEN 'Aug' THEN '-08-'
WHEN 'Sep' THEN '-09-'
WHEN 'Oct' THEN '-10-'
WHEN 'Nov' THEN '-11-'
WHEN 'Dec' THEN '-12-' END||
SUBSTRING(PARAMETER_VALUE,1,2))
),ISO) > CURRENT DATE;
I receive the following error: The statement was not processed because the data type, length or value of the argument for the parameter in position "1" of routine "SYSIBM.CHAR" is incorrect. Parameter name: "".. SQLCODE=-171, SQLSTATE=42815, DRIVER=4.19.56
I am using IBM Data Studio to run this.
PARAMETER_VALUE looks like it's DDMonYYYY if you wanted to use TO_DATE similar to:
SELECT
*
FROM TABLE1
WHERE TO_DATE(PARAMETER_VALUE, 'DDMonYYYY') > CURRENT DATE;
If that's not the correct format of that column then you can put together the correct string from here: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0007107.html
This is my value in the table : FY20 JAN
And i am looking for 'FY20 (M01) JAN'. How can convert like this in Oracle 11g SQL query ?
First you convert your string to a value of DATE type. Anything enclosed in double quotes is somewhat hard coded and TO_DATE function ignores them as long as they match the characters in the input in their specific locations. Here FY are in location (index) 1 and 2.
alter session set nls_date_format = 'yyyy-mm-dd';
select to_date('FY20 JAN', '"FY"yy MON') d from dual;
D
----------
2020-01-01
Then, you apply another function TO_CHAR to the date value we got above to get the desired output.
select to_char(
to_date('FY20 JAN', '"FY"YY MON')
, '"FY"yy "(M"mm")" MON'
) c from dual;
C
-----------------------
FY20 (M01) JAN
why it is not the same result with command line type directly on the oracle server apres logging
/u01/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus
*vis/passwd#10.252.41.123:1521/AA*
SQL> select count(*) from dispo where period = to_date('2017-10-01','YYYY-MM-DD') ;
result : 0
and when i use the software Oracle sql developper with a connection with the same vis/passwdv#10.252.41.123:1521/AA?
select count(*) from dispo where period = to_date('2017-10-01','YYYY-MM-DD')
result : 20000
enter image description here
Your SQL*Plus and SQL Developer sessions are in, or think they are in, different time zones.
The static date you're using for the filter is being implicitly converted to the local time zone. When that happens in your SQL*Plus session/time zone it still matches the timestamps you have stored. When you do it in the SQL Developer session/time zone it doesn't match.
You can demonstrate this in a single session by altering the session settings, with a single dummy row created in a UTC session:
create table dispo (id number, period timestamp(6) with local time zone);
alter session set time_zone = 'UTC';
insert into dispo (id, period) values (1, timestamp '2017-10-01 00:00:00');
then querying in the same time zone sees that data:
alter session set time_zone = 'UTC';
select cast(date '2017-01-01' as timestamp with local time zone) as local_time from dual;
LOCAL_TIME
-------------------
2017-01-01 00:00:00
select * from dispo where period = date '2017-10-01';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
but querying in a different time zone does not:
alter session set time_zone = 'Europe/London';
select cast(date '2017-01-01' as timestamp with local time zone) as local_time from dual;
LOCAL_TIME
-------------------
2017-01-01 00:00:00
select * from dispo where period = date '2017-10-01';
no rows selected
You can avoid this by specifying which time zone the fixed value is in:
alter session set time_zone = 'UTC';
select * from dispo where period = timestamp '2017-10-01 00:00:00 UTC';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
alter session set time_zone = 'Europe/London';
select * from dispo where period = timestamp '2017-10-01 00:00:00 UTC';
ID PERIOD
---------- -------------------
1 2017-10-01 00:00:00
Obviously use whichever time zone the data was actually created in...
I have a teradata table ABC . I have a column in the table which is of PERIOD data type ( Name of the column is ef_dtm) . I need to update the starting bound of the period column(subtract it by 1 day) whenever starting bound of the period column is '12/31/9999'.
I am using the below query . But it is saying
INVALID Interval Literal.
Can you suggest me an update query?
Nonsequenced validtime
update ABC
set ef_dtm = PERIOD(CAST(end(ef_dtm) as Date) -INTERVAL '-1' DAY , end(ef_dtm))
where begin(ef_dtm) = '12/31/9999'
The error is because of part INTERVAL '-1' DAY
It should be INTERVAL -'1' DAY i.e. minus - outside the '1'
Your query has 2 more problems.
No need to cast period begin to DATE as INTERVAL arithmetic works on TIMESTAMP
DATE literals are wrong. It should be YYYY-MM-DD; Moreover it should be TIMESTAMP corresponding to period column datatype.
Correct query is as below.
nonsequenced validtime
UPDATE ABC
SET ef_dtm = PERIOD(begin(ef_dtm) + INTERVAL -'1' DAY, end(ef_dtm))
WHERE begin(ef_dtm) = TIMESTAMP '1999-12-31 00:00:00.000000';
OR
nonsequenced validtime
UPDATE ABC
SET ef_dtm = PERIOD(begin(ef_dtm) - INTERVAL '1' DAY, end(ef_dtm))
WHERE begin(ef_dtm) = TIMESTAMP '1999-12-31 00:00:00.000000';
DEMO
Create Table:
CREATE TABLE ABC ( ef_dtm period(timestamp(6)) AS validtime ) NO PRIMARY INDEX;
Insert Data:
INSERT INTO abc(period (TIMESTAMP '1999-12-31 00:00:00.000000', TIMESTAMP '1999-12-31 23:59:00.000000'));
After select
ef_dtm
------------------------------------------------------------
('1999-12-31 00:00:00.000000', '1999-12-31 23:59:00.000000')
Update Data:
nonsequenced validtime
UPDATE ABC
SET ef_dtm = PERIOD(begin(ef_dtm) + INTERVAL -'1' DAY, end(ef_dtm))
WHERE begin(ef_dtm) = TIMESTAMP '1999-12-31 00:00:00.000000';
After SELECT
ef_dtm
------------------------------------------------------------
('1999-12-30 00:00:00.000000', '1999-12-31 23:59:00.000000')
When I try to insert datetime value 12:58 AM into the oracle table it gets inserted as 00:58. How can I insert datetime value as 12 in my oracle db? I've set my Oracle time format as 24 hr time. Any suggestions would help.
Insert statement :
INSERT INTO TABLE
(
DATE_CREATED,
PLANNED_START,
PLANNED_COMPLETION
)
VALUES
(
sysdate,
TO_CHAR(p_planned_Start_Date, 'DD-MM-YYYY HH24:MI:SS'),
TO_CHAR(end_date_, 'DD-MM-YYYY HH24:MI:SS')
);
For the 24-hour time, you need to use HH24 instead of HH.
For the 12-hour time, the AM/PM indicator is written as A.M. (if you want periods in the result) or AM (if you don't). For example:
INSERT INTO TEST (LD_DATE) Values (TO_DATE('08/30/2016', 'MM/DD/YYYY '));
And select it as below:
SELECT LD_DATE,
TO_CHAR(LD_DATE, 'DD-MM-YYYY HH24:MI:SS') "Date 24Hr",
TO_CHAR(LD_DATE, 'DD-MM-YYYY HH:MI:SS AM') "Date 12Hr"
FROM test
;