Decode function not working in SQL*Loader - oracle

I am using SQL*Loader to import data from CSV to an Oracle table. My data has multiple date fields and i need to replace null values with '0001-01-01-00-00-00' and other values need to follow date format.
I used decode option like
decode(:QUOTE_CREATE_DT,NULL,'0001-01-01-00.00.00',
TO_DATE(:QUOTE_CREATE_DT,'MM/DD/YYYY HH24:MI:SS'))
which is not working when null values occur.
SQL*Loader error:
Record 2: Rejected - Error on table EX_QUOTE_MO_SAMPLE, column QUOTE_CREATE_DT.
ORA-01847: day of month must be between 1 and last day of month

Your version is relying on implicit conversion using the SQL*Loader session's NLS settings.
You could use decode or coalesce or nvl to provide a date string in the format you're converting, but inside the to_date() call:
QUOTE_CREATE_DT "TO_DATE(NVL(:QUOTE_CREATE_DT, '01/01/0001'), 'MM/DD/YYYY')"

Related

Getting Oracle Error While trying to convert varchar2 column and retrieve data using BIP report

We have column (field) attribute14 in the oracle table which is of data type VARCHAR2 and is storing date in format '20-MAY-22' (DD-MON-YY).
We have a requirement to develop a BIP report in oracle fusion and get output based on the parameter date passed & if no parameter is based then all the records.
But as we all know any date parameter in the oracle Data set or BIP report will be in the below format.
Date Parameter: '2021-12-05T19:00:00.000-05:00'
And upon trying the below query when the parameter is passed the following error.
select *
from ab cet
where 1=1
AND TO_DATE(cet. attribute14, DD-MON-YY NLS_date_language=AMERICAN")
IN ( nvl(:void_date.TO_DATE(cet.attribute14, DD-MON-YY.NLS_date_language=AMERICAN")))
The below error comes when the parameter value is passed.
Error: ORA-01847: day of the month must be between 1 and the last day of the month.
You need to use single quotes around the date format. Seems your language is also incorrect. Details can be read in the Oracle documentation. Here is a simple example.
SELECT TO_DATE(
'20-MAY-22',
'DD-MON-YY',
'NLS_DATE_LANGUAGE = American')
FROM DUAL;
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm

Azure Data Factory. Lookup date in Azure SQL DWH, use in Oracle Query

I have an Oracle database and I have to load dat from this database to Azure SQL DWH. This is done once every day. At the beginning of the pipeline I first do a lookup on SQL DWH to look for the latest date. The result for that is something like '2015-10-25'.
I want to use this date to query the Oracle database. But I allready found out, by trying the query on Oracle that the following code does not work:
Select * from Table 1 where day = '2015-10-25'
The date in the day column looks like 25-OCT-15 (DD-MON-YY).
I treid the following where clause:
where day = TO_DATE('2015-10-25','DD-MON-YY')
But then I get the error: "literal does not match format string"
I realy don't know how to make Oracle understand this T-SQL date format.
Your Oracle column is of date datatype. When you connect to an Oracle database and write a query against that date column, you will see its default format DD-MON-YY as per this reference.
You can override this setting by running an ALTER SESSION command, eg
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY MM DD';
but this is just in that local session. The data is still stored in Oracle in the same manner and it's simply the way you view it that is changing.
In Azure Data Factory (ADF v2) and your example, you are dealing with strings. So you must make sure any parameters you pass in are in the correct format or set to the correct datatype. The Oracle function TO_DATE converts strings to the date datatype. Therefore when passing in a string of format YYYY-MM-DD then that is the format you must use, to let the TO_DATE function know what you are passing in:
TO_DATE('2015-10-25','YYYY-MM-DD')
The function then successfully converts your parameter to a date datetype for correct comparison against the main date column.
You can try this query:
Select * from Table 1 where day = to_char (to_date('2015-10-25','YYYY-MM-DD'), 'DD-Mon-YY')
Reference this blog: how to convert YYYYMMDD to DD-Mon-YYYY in oracle?
Hope this helps.

Hive - Convert string like 'yyyy-MM-dd' to date as Datatype 'yyyy-MM-dd

I have a external table in hive, which has report_dt as column and datatype is string and has value like 2018-09-02 2018-09-03
And i want to create managed table from the query written on this external table with report_dt_1 as column with datatype as date
i have gone through some threads and i was able to query like
create table manag_newtable as select to_date(from_unixtime(unix_timestamp(report_dt,'yyyy-MM-dd'),'yyyy-MM-dd')) as report_dt_1 from exter_table;
so the above query creates a new table, but when i desc manag_newtable ,still that report_dt_1 shows as string datatype
Prior to Hive 2.1.0, TO_DATE returns a string.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
Perhaps you want to try a CAST.
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-date
Otherwise, I suggest leaving the column as epoch time because 1) with your current format you lose timezone information, although you never had it so you are assuming UTC? 2) Hive requires less deserialization time for numbers, making queries faster. If you have to format the epoch, do that at the reporting layer, not the storage layer

Pentaho with Oracle data masking - Timestamp issue

I'm using Pentaho to datamask some of the information on the oracle DB
I have several transformations of the form:
SELECT -> data mask -> UPDATE rows based on primary key
I have tables where a timestamp is part of the primary key in the update step. Even though I am not masking or updating this field in any way, I get the error ORA-01843: not a valid month when performing the update.
I believe this is because when Pentaho takes in the timestamp from Step 1 it doesn’t actually keep it as a timestamp until I try the update and hence the primary key check. Outputting to excel, I see pentaho giving timestamps in the format
2014-07-30 15:44:31.869033 Europe/London (Pentaho)
But in DB the format is
30-JAN-15 09.21.38.109145000 AM (Oracle - TIMESTAMP(6) WITH LOCAL TIME ZONE)
I have tried to convert the pentaho field to a Timestamp (format: yyyy-MM-dd HH:mm:ss.SSSSSS) before the update step but receive errors if I try and use milliseconds.
2017/03/14 13:19:25 - Select values.0 - AUDIT_CREATE_TS Timestamp : couldn't convert string [2015-01-30 09:21:38.109145 Europe/London] to a timestamp, expecting format [yyyy-mm-dd hh:mm:ss.ffffff]
2017/03/14 13:19:25 - Select values.0 - Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
If I replace my formatting to the one suggested by Pentaho I get "Illegal character 'f'" and then I am stuck in a loop.
Ignoring milliseconds seems to succeed but won’t give me any matches because it isn’t precise enough and returns no results from db..
Any help would be appreciated!
Not sure about Pentaho, but if you're looking for a conversion from this string:
'2015-01-30 09:21:38.109145 Europe/London'
to a timestamp with timezone in Oracle, it would be:
select to_timestamp_tz('2015-01-30 09:21:38.109145 Europe/London', 'YYYY-MM-DD HH24:MI:SS.FF6 TZR') from dual;
See Oracle Datetime Format Models document for more.

How do I extract a timestamp column in a SQL transform using Data Services Designer?

I'm a Business Intelligence intern and am trying to write a simple ETL batch job to bring one table into our warehouse using SAP Data Services Designer. The source table has a timestamp column, which halts the job's execution, saying:
You cannot select directly from timestamp column . Using
a timestamp column in SQL transform may cause this error. See
documentation or notify Customer Support.
From the technical manual, this limitation is confirmed in the timestamp section, which reads:
You cannot use timestamp columns in the SQL transform or in an Oracle
stored procedure. To use a timestamp column in the SQL transform,
convert the timestamp column in the select list of the SQL transform
to a character format using the to_char function and convert it back
to timestamp using the to_date function."
I've tried remedying the problem by changing the output schema's column to a datetime type, and converting the timestamp in the SQL transform with
TO_DATE(TO_CHAR(SQL.DATETIME_STAMP, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')
I'm missing a key concept as it still fails with error 54003 no matter what I try. Thoughts, anyone?

Resources