如何转换十六进制“YMD”日期到可读日期?
我收到了一个文件,里面有一堆日期。它们是十六进制格式,我被告知是 YMD。
示例是:4A273F
..知道如何转换它吗?理想情况下使用 SQL/PLSQL,但我对其他想法持开放态度。
谢谢!
I've been given a file with a bunch of dates inside. They're in Hex format and I'm told it's YMD.
Example is: 4A273F
..any idea how I'd go about converting it? Idealling using SQL/PLSQL but I'm open to other ideas.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Oracle 和 Java 可以很好地配合,如果您喜欢冒险,这可能是一个新想法。 Java 很容易做到这一点,但我远离预言机,无法测试。这真的让我很伤心,因为我现在不在预言机前。为了确保我记得正确,我使用了这里的步骤
http://www.dba-oracle.com/tips_oracle_sqlj_loadjava.htm
然后我用谷歌搜索这几乎是我们下面要做的事情:
http://docstore.mik.ua/orelly/oracle/guide8i/ch09_03.htm
将该文件另存为“yourJava”目录中的 Hex2Date.java,然后从该目录中的命令行输入:
javac Hex2Date.java
现在输入:
java Hex2Date.java 0x4A273F
如果您获得正确的日期和结果,让我们告诉 oracle 我们的小功能。
您首先需要一些用户权限:
在此将 JAVAUSERPRIV 授予您的用户;
输入:
loadjava -user scott/tiger -resolve Hex2Date.class
现在将其包装在 pl/sql 中,因此您可以在 pl/sql 中调用它。:
现在,从 sql 提示符运行它:
SQL>执行 DBMS_OUTPUT.PUT_LINE ( hex2Date('0x4A273F'))
Oracle and java play fairly well with each other, and this is may be a new idea if you're feeling adventerous. Java does this pretty easily, but i'm away from an oracle box and unable to test. This really hurts i'm not in front of an oracle machine at the moment. To make sure I remembered correctly, I used steps from here
http://www.dba-oracle.com/tips_oracle_sqlj_loadjava.htm
and then I googled this, which is almost word for word what we'll do below:
http://docstore.mik.ua/orelly/oracle/guide8i/ch09_03.htm
save that file as Hex2Date.java in 'yourJava' directory, and from a cmd line in that directory type:
javac Hex2Date.java
now type:
java Hex2Date.java 0x4A273F
if you get the right dates, and the results, let's tell oracle about our little function.
you'll need some user rights first:
GRANT JAVAUSERPRIV TO your user here;
type this:
loadjava -user scott/tiger -resolve Hex2Date.class
now wrap this in pl/sql, so you can call it in pl/sql.:
now, run it from a sql prompt:
SQL> exec DBMS_OUTPUT.PUT_LINE ( hex2Date('0x4A273F'))
我猜它们是unix日期?我还猜测通过 SQL/PLSQL 您可以访问 SQL Server 和 Oracle?如果我的猜测都是正确的,我会使用 SQL Server 的转换函数:
select Convert(int, 0x4A273F)
以及它的日期添加函数(从 1970 年 1 月 1 日开始并添加秒数):
select dateadd(ss, {your_result}, '19700101')
当然,如果它们都在 csv 文件中,脚本也可以做到。您还有更多信息吗?
I'd guess they are unix dates? I'd also guess that by SQL/PLSQL you have access to SQL Server and Oracle? If my guesses are both right I'd use SQL Server's convert function:
select convert(int, 0x4A273F)
As well as its date add function (start from Jan 1, 1970 and add seconds):
select dateadd(ss, {your_result}, '19700101')
Of course if they are all in csv files, a script might do just as well. Do you have anymore information?
如果“十六进制”值来自大型机,那么它们可能是 EBCDIC(扩展二进制编码十进制交换代码)而不是十六进制?我现在没有时间推理出来,但请尝试此页面以获取想法/线索? http://www.simotime.com/asc2ebc1.htm 当然,我可能会咆哮错误的树:)
假设 50 34 2E 是 2009 年 4 月 27 日
If the 'HEX' values are from a Mainframe, then perhaps they are EBCDIC (Extended Binary Coded Decimal Interchange Code) and not HEX? I don't have time to reason it out right now but try this page for ideas/clues? http://www.simotime.com/asc2ebc1.htm Of course I may be barking up the wrong tree :)
Assume 50 34 2E is 27th April 2009