如何转换十六进制“YMD”日期到可读日期?

发布于 2024-10-01 10:20:10 字数 127 浏览 4 评论 0原文

我收到了一个文件,里面有一堆日期。它们是十六进制格式,我被告知是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

胡渣熟男 2024-10-08 10:20:10

Oracle 和 Java 可以很好地配合,如果您喜欢冒险,这可能是一个新想法。 Java 很容易做到这一点,但我远离预言机,无法测试。这真的让我很伤心,因为我现在不在预言机前。为了确保我记得正确,我使用了这里的步骤
http://www.dba-oracle.com/tips_oracle_sqlj_loadjava.htm

然后我用谷歌搜索这几乎是我们下面要做的事情:
http://docstore.mik.ua/orelly/oracle/guide8i/ch09_03.htm

/****
*java and oracle playing together.
 */
import java.util.Date;
public class hex2Date{
   //this is if you want to call the java function from a command line outside of oracle
     public static void main (String args[]) {
         System.out.println ( convert (args[0]) );    
    }

     public static Date convert(String inHexString){
       try{
        Date dateResult = new Date(Long.parseLong(inHexString,16));
       }catch (NumberFormatException e){
       // do something with the exception if you want, recommend at least throwing it.
    //throw(e,'some extra message');

       }

        return dateResult;
   }
}

将该文件另存为“yourJava”目录中的 Hex2Date.java,然后从该目录中的命令行输入:

javac Hex2Date.java

现在输入:

java Hex2Date.java 0x4A273F

如果您获得正确的日期和结果,让我们告诉 oracle 我们的小功能。
您首先需要一些用户权限:
在此将 JAVAUSERPRIV 授予您的用户;
输入:
loadjava -user scott/tiger -resolve Hex2Date.class

现在将其包装在 pl/sql 中,因此您可以在 pl/sql 中调用它。:

/* java function plsql wrapper: hex2Date.sf */ 
CREATE OR REPLACE FUNCTION hex2Date (    inHexString IN VARCHAR2)     RETURN DATE AS LANGUAGE JAVA    NAME 'Hex2Date.convert(java.lang.String)              return Date'; /

现在,从 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

/****
*java and oracle playing together.
 */
import java.util.Date;
public class hex2Date{
   //this is if you want to call the java function from a command line outside of oracle
     public static void main (String args[]) {
         System.out.println ( convert (args[0]) );    
    }

     public static Date convert(String inHexString){
       try{
        Date dateResult = new Date(Long.parseLong(inHexString,16));
       }catch (NumberFormatException e){
       // do something with the exception if you want, recommend at least throwing it.
    //throw(e,'some extra message');

       }

        return dateResult;
   }
}

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.:

/* java function plsql wrapper: hex2Date.sf */ 
CREATE OR REPLACE FUNCTION hex2Date (    inHexString IN VARCHAR2)     RETURN DATE AS LANGUAGE JAVA    NAME 'Hex2Date.convert(java.lang.String)              return Date'; /

now, run it from a sql prompt:
SQL> exec DBMS_OUTPUT.PUT_LINE ( hex2Date('0x4A273F'))

末骤雨初歇 2024-10-08 10:20:10

我猜它们是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?

蓝海似她心 2024-10-08 10:20:10

如果“十六进制”值来自大型机,那么它们可能是 EBCDIC(扩展二进制编码十进制交换代码)而不是十六进制?我现在没有时间推理出来,但请尝试此页面以获取想法/线索? http://www.simotime.com/asc2ebc1.htm 当然,我可能会咆哮错误的树:)

假设 50 34 2E 是 2009 年 4 月 27 日

EBCDIC HEX DEC
5      F5  245
0      F0  240
3      F3  243
4      F4  244
2      F2  242
E      C5  197

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

EBCDIC HEX DEC
5      F5  245
0      F0  240
3      F3  243
4      F4  244
2      F2  242
E      C5  197
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文