oracle 10g的long类型处理bug

因为分区表监控的脚本不想频繁访问dba_tab_subpartitions视图,需要创建临时表T1,偶然间发现oracle 10g的一个bug,在metalink上也没能找到该问题的解决方案。
1.创建临时表T1:
SQL> create table T1 as select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions;
Table created.
2.查询有没有数据:
SQL> select * from t1 where rownum < 3;
no rows selected
3.显式插入数据时报错 ORA-00932:
SQL> insert into t1 select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions;
insert into t1 select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions
                                                                  *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got LONG
NOTE:这是一个非常常见的long类型处理错误,官方说法:通过to_lob把long类型转换为clob可以解决这个报错。那么就看一下是不是呢?
SQL> desc t1
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 TABLE_NAME                                NOT NULL VARCHAR2(30)
 PARTITION_NAME                                     VARCHAR2(30)
 SUBPARTITION_NAME                                  VARCHAR2(30)
 HIGH_VALUE                                         CLOB
4.HIGH_VALUE列明明是clob类型,但是转换却不成功,trace10053看看insert语句内部是怎么执行的:
SQL> alter session set events '10053 trace name context forever, level 1';
Session altered.

SQL> insert into t1 select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions;
insert into t1 select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions
                                                                  *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got LONG
yuyan_ora_27952.trc显示内部执行语句:
SELECT "PO"."NAME" "TABLE_NAME","PO"."SUBNAME" "PARTITION_NAME","SO"."SUBNAME" "SUBPARTITION_NAME",TO_LOB("TSP"."HIBOUNDVAL") "HIGH_VALUE" FROM "SYS"."OBJ$" "SO","SYS"."OBJ$" "PO", (SELECT "TABCOMPART$"."OBJ#" "OBJ#","TABCOMPART$"."DATAOBJ#" "DATAOBJ#","TABCOMPART$"."BO#" "BO#",ROW_NUMBER() OVER ( PARTITION BY "TABCOMPART$"."BO#" ORDER BY "TABCOMPART$"."PART#") "PART#","TABCOMPART$"."HIBOUNDLEN" "HIBOUNDLEN","TABCOMPART$"."HIBOUNDVAL" "HIBOUNDVAL","TABCOMPART$"."SUBPARTCNT" "SUBPARTCNT","TABCOMPART$"."FLAGS" "FLAGS","TABCOMPART$"."DEFTS#" "DEFTS#","TABCOMPART$"."DEFPCTFREE" "DEFPCTFREE","TABCOMPART$"."DEFPCTUSED" "DEFPCTUSED","TABCOMPART$"."DEFINITRANS" "DEFINITRANS","TABCOMPART$"."DEFMAXTRANS" "DEFMAXTRANS","TABCOMPART$"."DEFINIEXTS" "DEFINIEXTS","TABCOMPART$"."DEFEXTSIZE" "DEFEXTSIZE","TABCOMPART$"."DEFMINEXTS" "DEFMINEXTS","TABCOMPART$"."DEFMAXEXTS" "DEFMAXEXTS","TABCOMPART$"."DEFEXTPCT" "DEFEXTPCT","TABCOMPART$"."DEFLISTS" "DEFLISTS","TABCOMPART$"."DEFGROUPS" "DEFGROUPS","TABCOMPART$"."DEFLOGGING" "DEFLOGGING","TABCOMPART$"."DEFBUFPOOL" "DEFBUFPOOL","TABCOMPART$"."ANALYZETIME" "ANALYZETIME","TABCOMPART$"."SAMPLESIZE" "SAMPLESIZE","TABCOMPART$"."ROWCNT" "ROWCNT","TABCOMPART$"."BLKCNT" "BLKCNT","TABCOMPART$"."EMPCNT" "EMPCNT","TABCOMPART$"."AVGSPC" "AVGSPC","TABCOMPART$"."CHNCNT" "CHNCNT","TABCOMPART$"."AVGRLN" "AVGRLN","TABCOMPART$"."SPARE1" "SPARE1","TABCOMPART$"."SPARE2" "SPARE2","TABCOMPART$"."SPARE3" "SPARE3","TABCOMPART$"."PART#" "PHYPART#" FROM SYS."TABCOMPART$" "TABCOMPART$") "TCP", (SELECT "TABSUBPART$"."OBJ#" "OBJ#","TABSUBPART$"."DATAOBJ#" "DATAOBJ#","TABSUBPART$"."POBJ#" "POBJ#",ROW_NUMBER() OVER ( PARTITION BY "TABSUBPART$"."POBJ#" ORDER BY "TABSUBPART$"."SUBPART#") "SUBPART#","TABSUBPART$"."FLAGS" "FLAGS","TABSUBPART$"."TS#" "TS#","TABSUBPART$"."FILE#" "FILE#","TABSUBPART$"."BLOCK#" "BLOCK#","TABSUBPART$"."PCTFREE$" "PCTFREE$","TABSUBPART$"."PCTUSED$" "PCTUSED$","TABSUBPART$"."INITRANS" "INITRANS","TABSUBPART$"."MAXTRANS" "MAXTRANS","TABSUBPART$"."ANALYZETIME" "ANALYZETIME","TABSUBPART$"."SAMPLESIZE" "SAMPLESIZE","TABSUBPART$"."ROWCNT" "ROWCNT","TABSUBPART$"."BLKCNT" "BLKCNT","TABSUBPART$"."EMPCNT" "EMPCNT","TABSUBPART$"."AVGSPC" "AVGSPC","TABSUBPART$"."CHNCNT" "CHNCNT","TABSUBPART$"."AVGRLN" "AVGRLN","TABSUBPART$"."SPARE1" "SPARE1","TABSUBPART$"."SPARE2" "SPARE2","TABSUBPART$"."SPARE3" "SPARE3","TABSUBPART$"."HIBOUNDLEN" "HIBOUNDLEN","TABSUBPART$"."HIBOUNDVAL" "HIBOUNDVAL","TABSUBPART$"."SUBPART#" "PHYSUBPART#" FROM SYS."TABSUBPART$" "TABSUBPART$") "TSP","SYS"."TAB$" "T","SYS"."TS$" "TS","SYS"."SEG$" "S","SYS"."USER$" "U" WHERE "SO"."OBJ#"="TSP"."OBJ#" AND "PO"."OBJ#"="TSP"."POBJ#" AND "TCP"."OBJ#"="TSP"."POBJ#" AND "TCP"."BO#"="T"."OBJ#" AND BITAND("T"."TRIGFLAG",1073741824)<>1073741824 AND "TSP"."TS#"="TS"."TS#" AND "U"."USER#"="PO"."OWNER#" AND "TSP"."FILE#"="S"."FILE#" AND "TSP"."BLOCK#"="S"."BLOCK#" AND "TSP"."TS#"="S"."TS#" AND "PO"."NAMESPACE"=1 AND "PO"."REMOTEOWNER" IS NULL AND "PO"."LINKNAME" IS NULL AND "SO"."NAMESPACE"=1 AND "SO"."REMOTEOWNER" IS NULL AND "SO"."LINKNAME" IS NULL

显然语法是不符合规则的!
SQL> alter session set events '10053 trace name  context off';
Session altered.
5.然后查看metalink上没有相关的内容,oracle不推荐用long类型,然而他自己却总喜欢在一些系统表里用long类型。那么11g会不会也出现这个问题呢?
在11g上执行相同的语句,并记录trace:
SQL> alter session set events '10053 trace name context forever, level 1';
Session altered.

SQL> create table T1 as select table_name,partition_name,subpartition_name,to_lob(high_value) HIGH_VALUE from dba_tab_subpartitions;
Table created.

SQL> desc t1;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 TABLE_NAME                                NOT NULL VARCHAR2(30)
 PARTITION_NAME                                     VARCHAR2(30)
 SUBPARTITION_NAME                                  VARCHAR2(30)
 HIGH_VALUE                                         CLOB

SQL> select * from t1 where rownum < 3;
TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
SUBPARTITION_NAME
------------------------------
HIGH_VALUE
--------------------------------------------------------------------------------
WRI$_OPTSTAT_SYNOPSIS$         P0
SYS_SUBP1

WRI$_OPTSTAT_SYNOPSIS$         P0
SYS_SUBP2

TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
SUBPARTITION_NAME
------------------------------
HIGH_VALUE
--------------------------------------------------------------------------------

SQL> alter session set events '10053 trace name  context off';

yuyan_ora_30822.trc显示内部执行语句:
SELECT "PO"."NAME" "TABLE_NAME","PO"."SUBNAME" "PARTITION_NAME","SO"."SUBNAME" "SUBPARTITION_NAME",TO_LOB("TSP"."HIBOUNDVAL") "HIGH_VALUE" FROM "SYS"."OBJ$" "SO","SYS"."OBJ$" "PO",SYS."TABCOMPART$" "TCP","SYS"."TABSUBPART$" "TSP","SYS"."TAB$" "T","SYS"."TS$" "TS","SYS"."SEG$" "S","SYS"."USER$" "U","SYS"."DEFERRED_STG$" "DS" WHERE "SO"."OBJ#"="TSP"."OBJ#" AND "PO"."OBJ#"="TSP"."POBJ#" AND "TCP"."OBJ#"="TSP"."POBJ#" AND "TCP"."BO#"="T"."OBJ#" AND BITAND("T"."TRIGFLAG",1073741824)<>1073741824 AND "TSP"."TS#"="TS"."TS#" AND "U"."USER#"="PO"."OWNER#" AND "TSP"."OBJ#"="DS"."OBJ#"(+) AND "TSP"."FILE#"="S"."FILE#"(+) AND "TSP"."BLOCK#"="S"."BLOCK#"(+) AND "TSP"."TS#"="S"."TS#"(+) AND "PO"."NAMESPACE"=1 AND "PO"."REMOTEOWNER" IS NULL AND "PO"."LINKNAME" IS NULL AND "SO"."NAMESPACE"=1 AND "SO"."REMOTEOWNER" IS NULL AND "SO"."LINKNAME" IS NULL

在11g中是可以执行成功的,看来oracle在11g对这个bug做了修改!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30025058/viewspace-1792278/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30025058/viewspace-1792278/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值