os: centos 7.4
db: oracle 11.2.0.4
查看 v$sql_monitor
select (sysdate-v.SQL_EXEC_START) * 3600*24 as exec_sec,
v.sql_id,
v.sql_text,
v.binds_xml
from v$sql_monitor v
where 1=1
order by 1 desc
;
查看 binds_xml 字段有时会发现时间变量时为 hexdump 之类的看不懂的字符串,在mos上查找后发现这是 oarcle 的一个 bug,可以通过如下语句换算得到具体的时间值。
对 hexdump 值换算
select
to_char(to_number(substr(p_str,1,2),'xx')-100,'fm00') ||
to_char(to_number(substr(p_str,3,2),'xx')-100,'fm00') ||
to_char(to_number(substr(p_str,5,2),'xx'),'fm00') ||
to_char(to_number(substr(p_str,7,2),'xx'),'fm00') ||
to_char(to_number(substr(p_str,9,2),'xx')-1,'fm00') ||
to_char(to_number(substr(p_str,11,2),'xx')-1,'fm00') ||
to_char(to_number(substr(p_str,13,2),'xx')-1,'fm00')
from (
select '78770C1B090101' as p_str from dual
union all
select '78770C1B0A010101036640' as pg_str from dual
)
mos
TIMESTAMP Data Type Bind Variables Are Incorrectly Reported as Hex Number in SQL MONITOR (Doc ID 2111950.1)
In this Document
Symptoms
Cause
Solution
References
APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.3 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Information in this document applies to any platform.
SYMPTOMS
TIMESTAMP data type bind variables are reported wrongly as hex number in SQL MONITOR:
format=“hexdump”>78710A02101F211A0AB7B0
Run following example script which shows the output:
-- begin script
declare
a number;
t timestamp;
begin
t := systimestamp;
select /*+ monitor */ /* tstamp1 */ count(*) into a from user_tables where
t = systimestamp;
end;
/
select sql_id into :sqlid from v$sql_monitor where sql_text like '%tstamp1%';
select extract(dbms_sqltune.report_sql_monitor_xml(sql_id => :sqlid),
'/report/sql_monitor_report/binds') from dual;
- end script
Output is something like following:
EXTRACT(DBMS_SQLTUNE.REPORT_SQL_MONITOR_XML(SQL_ID=>:SQLID),'/REPORT/SQL_MONIT
OR
------------------------------------------------------------------------------
<binds><bind name=":B1" pos="1" dty="180" dtystr="TIMESTAMP" maxlen="11"
scale="6" len="11" format="hexdump">78710A02101F211A0AB7B0</bind></binds>
CAUSE
This is due to following bug:
Bug 17551174 : SQL MONITOR SHOWS HEX DUMP INSTEAD OF ACTUAL BIND VALUE FOR CERTAIN BIND TYPES
SOLUTION
-
The bug is fixed in 12.2
-
Run following sql which will convert the hex number to readable format:
SQL> undef raw_timestamp
SQL> select to_timestamp(
to_char( to_number( substr( p_str, 1, 2 ), 'xx' ) - 100, 'fm00' ) ||
to_char( to_number( substr( p_str, 3, 2 ), 'xx' ) - 100, 'fm00' ) ||
to_char( to_number( substr( p_str, 5, 2 ), 'xx' ), 'fm00' ) ||
to_char( to_number( substr( p_str, 7, 2 ), 'xx' ), 'fm00' ) ||
to_char( to_number( substr( p_str,9, 2 ), 'xx' )-1, 'fm00' ) ||
to_char( to_number( substr( p_str,11, 2 ), 'xx' )-1, 'fm00' ) ||
to_char( to_number( substr( p_str,13, 2 ), 'xx' )-1, 'fm00' ), 'yyyym mddhh24miss' )
from (select '&raw_timestamp' p_str from dual);
Enter value for raw_timestamp: 78710A02101F211A0AB7B0
old 9: from (select '&raw_timestamp' p_str from dual)
new 9: from (select '78710A02101F211A0AB7B0' p_str from dual)
TO_TIMESTAMP(TO_CHAR(TO_NUMBER(SUBSTR(P_STR,1,2),'XX')-100,'FM00')||TO_CHAR
---------------------------------------------------------------------------
02-OCT-13 03.30.32.000000000 PM
参考:
<<TIMESTAMP Data Type Bind Variables Are Incorrectly Reported as Hex Number in SQL MONITOR (Doc ID 2111950.1)>>