scn_to_timestamp ORA-00904
Oracle中scn與時間之間可以進行相互轉換,朋友的資料庫是10.2.0.5,之前通過scn_to_timestamp將scn轉換為相對應的時間時一切正常,但今天執行卻報錯了。
SQL>select to_char(scn_to_timestamp(3111823),'yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(scn_to_timestamp(3111823),'yyyy-mm-dd hh24:mi:ss') from dual;
*
ERROR at line 1:
ORA-00904: "SCN_TO_TIMESTAMP": invalid identifier
很奇怪,scn_to_timestamp函數的狀態通過下面的查詢語句來查詢
SQL> select owner,object_name,object_type,last_ddl_time,status from dba_objects where object_name='SCN_TO_TIMESTAMP';
OWNER OBJECT_NAME OBJECT_TYPE LAST_DDL_TIME STATUS
------------ --------------------- ------------------- ------------- -------
SYS SCN_TO_TIMESTAMP FUNCTION 2014/11/26 12 VALID
PUBLIC SCN_TO_TIMESTAMP SYNONYM 2014/11/26 12 VALID
後來我把scn_to_timestamp函數的建立語句重新執行一次。
create or replace function scn_to_timestamp(query_scn IN NUMBER)
return TIMESTAMP
IS EXTERNAL
NAME "ktfexscntot"
WITH CONTEXT
PARAMETERS(context,
query_scn OCINUMBER,
RETURN)
LIBRARY DBMS_TRAN_LIB;
在執行完後執行對scn_to_timestamp函數的查詢
SQL> select to_char(scn_to_timestamp(3111823),'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SCN_TO_TIMESTAMP(31118
------------------------------
2015-02-03 16:26:27
但是卻新建立了一個scn_to_timestamp函數並沒有替換掉原來的
SQL> select owner,object_name,object_type,last_ddl_time,status from dba_objects where object_name='SCN_TO_TIMESTAMP';
OWNER OBJECT_NAME OBJECT_TYPE LAST_DDL_TIME STATUS
----------- ------------------------ ------------------- ------------- -------
SYS SCN_TO_TIMESTAMP FUNCTION 2014/11/26 12 VALID
PUBLIC SCN_TO_TIMESTAMP SYNONYM 2014/11/26 12 VALID
SYS SCN_TO_TIMESTAMP FUNCTION 2015/2/3 16:5 VALID
這個問題還沒找到原因,也許是oracle的bug,因為我在oracle 10.2.0.4中重新建立scn_to_timestamp函數後,查詢dba_objects並沒有顯示產生的scn_to_timestamp函數
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as SYS
SQL>
SQL> create or replace function scn_to_timestamp(query_scn IN NUMBER)
2 return TIMESTAMP
3 IS EXTERNAL
4 NAME "ktfexscntot"
5 WITH CONTEXT
6 PARAMETERS(context,
7 query_scn OCINUMBER,
8 RETURN)
9 LIBRARY DBMS_TRAN_LIB;
10 /
Function created
SQL> select owner,object_name,object_type,last_ddl_time,status from dba_objects where object_name='SCN_TO_TIMESTAMP';
OWNER OBJECT_NAME OBJECT_TYPE LAST_DDL_TIME STATUS
---------- ------------------------ ------------------- ------------- -------
SYS SCN_TO_TIMESTAMP FUNCTION 2015/2/3 21:2 VALID
PUBLIC SCN_TO_TIMESTAMP SYNONYM 2008/4/23 12: INVALID
並且在10.2.0.4中重建scn_to_timestamp函數後,對應的同義字失效了,這才是正確而在10.2.0.5中重建scn_to_timestamp函數後,卻產生了一個新的同名對象,且對應的同義仍然為有效狀態。