首批通过分布式安全可靠测评,为关键业务系统打造
如何转换 SQL_AUDIT 表内的 request_time 时间
更新时间:2025-12-08 09:21
在 SQL_AUDIT 中 request_time 表示开始执行时间点,单位:微秒,实际查询结果展示不太友好,如何转换成方便观察的结果。
解决方法
MySQL 租户
使用
USEC_TO_TIME函数将微秒数(usec)转换为 TIMESTAMP 类型的值。具体示例如下:
obclient> select request_id,usec_to_time(request_time),ELAPSED_TIME,QUEUE_TIME,EXECUTE_TIME,query_sql from v$OB_SQL_AUDIT where ELAPSED_TIME >100000 limit 10;Oracle 租户
Oracle 租户没有特定的函数可以转换,需要使用自定义函数,可以使用
to_timestamp('1970-01-01 08:00:00.000','yyyy-mm-dd hh24:mi:ss:ff3') + NUMTODSINTERVAL( request_time/1000000, 'SECOND')方式转换。具体示例如下:
obclient> select request_id,(to_timestamp('1970-01-01 08:00:00.000','yyyy-mm-dd hh24:mi:ss:ff3') + NUMTODSINTERVAL(request_time/1000000, 'SECOND')),ELAPSED_TIME,QUEUE_TIME,EXECUTE_TIME,query_sql from Gv$OB_SQL_AUDIT where ELAPSED_TIME >100000 and rownum < 10;
适用版本
OceanBase 数据库所有版本。