How to Convert EBCDIC To HEX? - oracle11g

In this image EBCDIC value "I" we want To Hex format
In Oracle I am trying to convert "I" to "C9" but I don't know how to do. so please help me out.
Exa.
EBCDIC("I") -> HEX(C9)

Thanks Fact for helping, I appreciate your support.
I used below query and it's working now Yaaaappppyyyyy.
select rawtohex(CONVERT(NVL("I", '0'), 'WE8EBCDIC500', 'US7ASCII')) from dual;
Result: C9

Related

Date conversion handling YYYY-MM-DD HH:MM:SS.SSS

My source is a file and loading into SQL Server table. I'm working on a scenario where i have to convert a string '2019-04-02T21:24:00.065' to informatica datetime format.
I tried below expression but some times its failing due to we are not receiving milliseconds from our source file in few occasions.
IIF(NOT ISNULL(DATEFIELD),TO_DATE(SUBSTR (DATEFIELD, 0, 10) || ' ' || SUBSTR(DATEFIELD, 12, 12), 'YYYY-MM-DD HH24.MI.SS.US'),NULL)
I'm looking for a permanent fix to handle all types of datetime formats regardless of what we receive in the file.
Well... I'm sorry to say, but there is no magic component that will recognize all possible date and time formats (including e.g. verbal in swahili).
You will need to detect the format for yourself. You can use a DECODE function, like e.g.:
DECODE(True,
IS_DATE(your_input_port, 'DD/MM/YYYY'), TO_DATE(your_input_port, 'DD/MM/YYYY'),
...)
If you are completely sure that only seconds/milliseconds are the missing part, you can check for length, if less than 12, use RPAD to the second part of your SUBSTR with missing format, or you can use decode as suggested by #maciejg and write code for all possible date formats.
Thanks for your inputs guys. Since we are not sure which date format we are receiving , we decided to go with a simple fix for this. I have changed the target field to varchar and simply replacing the T with ' ' value since this a staging mapping.
Again thanks for your time and inputs.

Where do I find the reference for TO_DATE format string

I need to convert a string formatted as MM/DD/YYYY HH:MI plus AM/PM, but can't find a complete reference to the format string to find how to specify the AM/PM part.
I would certainly appreciate information on how to do this, but would appreciate a link to a good source of documentation for this even more.
:EDIT
SELECT top 1
v.CalendarDateTime
,TO_TIMESTAMP(v.CalendarDateTime,'MM/DD/YYYY HH:MIAM') as CalendarDateTimeTS
--,CAST(TO_TIMESTAMP(v.CalendarDateTime,'MM/DD/YYYY HH:MIAM') AS TIMESTAMP(0) FORMAT 'MM/DD/YYYYBHH:MIBT') AS CalendarDateTimeTS2
12/03/2015 03:00AM 12/3/2015 03:00:00.000000
The commented out line produces a "DateTime field overflow" error.
You probably want TO_TIMESTAMP instead of TO_DATE.
The only bad thing about the Oracle function is the resulting datatype of TIMESTAMP(6) which can't be changed:
TO_TIMESTAMP('12/03/2015 03:00AM', 'MM/DD/YYYY HH:MIAM')
Using Teradata's FORMAT you can specify the timestamp precision, but it's less flexible than Oracle's, the string must match the format exactly:
CAST('12/03/2015 03:00AM' AS TIMESTAMP(0) FORMAT 'MM/DD/YYYYbHH:MIT')
On the Teradata site you'll find the (slow) online docu, e.g. TO_DATE formats or Teradata FORMATs. Of course you should download the full documentation CD for your release.
Please tell us at least which programming language are you using.
Normally it would be something like "MM/DD/YYYY HH:MI a" but we need to know first you language.

Acumatica Report Designer Format Decimal Points

Can anyone tell me what is the Format required to get decimal points to be displayed dynamically so that the field displays "5" if I enter "5.0" and "5.5" if I enter "5.5" automatically.
I have tried using #0.# as the format, but this is leaving the "." as in "5." if I enter "5.0". I have left the field as "#0.0" but would really like to know if there was a way of dynamically change the decimal places this way
I figured out the answer was ##.# :)
You can pull in the correct decimals for quantity and cost as specified on the Branch record by using a database field and an expression.
=Report.IntToUI('AMMTran.UnitCost',CDec([AMMTran.UnitCost]))
you can use the following formula too:
=Format('{0:0.#}', 5.5)

DB2 Cast DateTime string with "T" separator

Help me please with the next problem.
I have date time string in the next format(ISO 8601): 1999-12-31T23:59:59
and I need to cast it to TIMESTAMP value. The main problem in 'T' separator character.
I have tried next query:
SELECT TIMESTAMP_FORMAT('1999-12-31T23:59:59','YYYY-MM-DD HH24:MI:SS') FROM ROMAN.EMPLOYEE;
and use different format strings, such as, YYYY-MM-DDTHH24:MI:SS, YYYY-MM-DD"T"HH24:MI:SS.
Could you provide me correct way to cast this type of strings without any character replacement and substrings.
Thanks in advance!
There is no built-in function that can format a timestamp in ISO-8601 format in DB2 for Linux/UNIX/Windows.
As you have probably surmised, you can do this with REPLACE:
select
TIMESTAMP_FORMAT(REPLACE('1999-12-31T23:59:59','T',' '), 'YYYY-MM-DD HH24:MI:SS')
from
ROMAN.EMPLOYEE;
It's trivial to create a user defined function (UDF) to handle this formatting for you as well so you don't have to out this long string in every query.
It may also be possible to do it via XQuery with and xs:dateTime, although this would be even more code than just embedding REPLACE in the call to TIMESTAMP_FORMAT.

SAS datetime formatting as POSIX

I want SAS to format datetimes in a POSIX format. The following gives "2009-11-25 14:44:56" how can I display the milliseconds ?
proc format;
picture POSIX other='%0Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
run;
data test;
mydatetime='25nov2009 14:44:56.300'dt;
format newdt POSIX.;
newdt=mydatetime;
put mydatetime= newdt=;
run;
EDIT : I am even taker of ANY way to format datetimes to YYYY-MM-DD HH:M:SS.sss (ISO8601) amazing I can't find this in less than 1 minute
E8601DT23.3 should display your values as you wish, except for the extra "T" separator; SAS seems to require that. If you're putting to a character value you can remove the "T" easily; if you are trying to use a formatted numeric value, I think you would have to live with it.
data test;
mydatetime='25nov2009 14:44:56.356'dt;
format newdt E8601DT23.3;
newdt=mydatetime;
put mydatetime= newdt=;
run;
SAS guide on ISO8601:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm
Edit: SAS-L came through on this one ( http://listserv.uga.edu/cgi-bin/wa?A1=ind1303c&L=sas-l#8 ). If you have 9.3 this should work (not in 9.2 or earlier).
proc format;
picture POSIX other='%0Y-%0m-%0d %0H:%0M:%0s' (datatype=datetime);
run;
data test;
mydatetime='25nov2009 14:44:56.300'dt;
format newdt POSIX23.3;
newdt=mydatetime;
put mydatetime= newdt=;
run;
Little s, and include the decimal, and it should work as expected. Thanks to data null for the tip.
This solution only works for values of second from 10-59. It does not work for values of second 0-9. There is no leading zero for values of second 0-9.

Resources