HSQLDB - 从HEX VARCHAR MAC地址转换为BIGINT

时间:2010-11-08 09:54:03

标签: java hsqldb

我有一个HSQLDB表,其中MAC地址存储为varchar,效率不高。我想将它转换为BIGINT,但我没有发现从VARCHAR hex到BIGINT / INTEGER的转换函数。我尝试使用这样的转换:convert(client_mac,BIGINT),但遇到第一个非数字失败。有人有任何想法吗?

谢谢,

1 个答案:

答案 0 :(得分:0)

我发现自己是一个解决方案:

SELECT  "java.lang.Long.decode"(concat('0x',replace(client_mac,'-',''))),
FROM    user_accounting_sessions_table

这是一种解决方法,因为我想到的第一种方法是:

SELECT  "java.lang.Long.parseLong"(replace(client_mac,'-',''),16)
FROM    user_accounting_sessions_table

但这引发了这个错误:

java.lang.ArrayIndexOutOfBoundsException: 1
    at org.hsqldb.Function.setArgument(Unknown Source)
    at org.hsqldb.Parser.readTerm(Unknown Source)
    at org.hsqldb.Parser.readFactor(Unknown Source)
    at org.hsqldb.Parser.readSum(Unknown Source)
    at org.hsqldb.Parser.readConcat(Unknown Source)
    at org.hsqldb.Parser.readCondition(Unknown Source)
    at org.hsqldb.Parser.readAnd(Unknown Source)
    at org.hsqldb.Parser.readOr(Unknown Source)
    at org.hsqldb.Parser.parseExpression(Unknown Source)
    at org.hsqldb.Parser.parseSelect(Unknown Source)
    at org.hsqldb.Parser.compileSelectStatement(Unknown Source)
    at org.hsqldb.DatabaseCommandInterpreter.executePart(Unknown Source)
    at org.hsqldb.DatabaseCommandInterpreter.execute(Unknown Source)
    at org.hsqldb.Session.sqlExecuteDirectNoPreChecks(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.onseven.dbvis.b.B.B.?(Z:2256)
    at com.onseven.dbvis.b.B.F$A.call(Z:2838)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

似乎问题出在第二个参数上。 但是,第一个工作正常。