这是我的桌子。我需要匹配这个值。我怎么能这样做?
我将LAST_ACCESS_TIME
保存为php {/ p>中的time()
$time = time();
TS_SESSION
数据:
USER_ID |HASH_VALUE |LAST_ACCESS_TIME
--------|---------------------------------|-----------------
1 |31feefaba85e4e8dbb8ef9d5ae9bfda9 |1414754384
3 |90ad8c64a2034b4a139ef595b3627d8d |1414769029
2 |9f12581e0dfce0d7f40c0df77d1f1fd7 |1414782017
尝试查询:
SELECT *
FROM TS_SESSION
where LAST_ACCESS_TIME BETWEEN timestamp '1456790400' AND timestamp '1459382400';
答案 0 :(得分:1)
PHP time()返回unix时间戳(1970年1月1日起的秒数)。 因此,如果您需要将其转换为Oracle日期,您可能会发现这样的主题 https://dba.stackexchange.com/questions/16461/convert-a-unix-timestamp-to-a-datetime-in-a-view
所以这个简单的解决方案应该有所帮助:
WITH ts_session AS
(SELECT
1414754384 LAST_ACCESS_TIME
FROM DUAL)
SELECT
to_date('1970-01-01','YYYY-MM-DD')+
numtodsinterval(LAST_ACCESS_TIME,'SECOND')) AS date_value
FROM ts_session
如果您需要格式化字符串值,请使用to_char:
WITH ts_session AS
(SELECT
1414754384 LAST_ACCESS_TIME
FROM DUAL)
SELECT
to_char(to_date('1970-01-01','YYYY-MM-DD')+
numtodsinterval(LAST_ACCESS_TIME,'SECOND')),
'MM/DD/YYYY HH24:MI:SS') AS char_value
FROM ts_session