Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在Oracle投影列表中测试Alien_Body_Part(NCLOB)的值?_Sql_Oracle_Oracle11g_Ora 00932 - Fatal编程技术网

Sql 如何在Oracle投影列表中测试Alien_Body_Part(NCLOB)的值?

Sql 如何在Oracle投影列表中测试Alien_Body_Part(NCLOB)的值?,sql,oracle,oracle11g,ora-00932,Sql,Oracle,Oracle11g,Ora 00932,我有一个带有三个NCLOB列的表。对于每个NCLOB,我需要计算有多少不是“TC”或“NC”。当。。。end方法适用于NVARCHAR2列,但不适用于NCLOB。如何在“投影”列表中测试NCLOB的值 Oracle Database 11g 11.1.0.6.0版 这个最小的示例演示了根本问题 create table t ( alien_body_part nclob ); insert into t(alien_body_part) values(null); insert into

我有一个带有三个NCLOB列的表。对于每个NCLOB,我需要计算有多少不是“TC”或“NC”。当。。。end方法适用于NVARCHAR2列,但不适用于NCLOB。如何在“投影”列表中测试NCLOB的值

Oracle Database 11g 11.1.0.6.0版

这个最小的示例演示了根本问题

create table t (
  alien_body_part nclob
);

insert into t(alien_body_part) values(null);
insert into t(alien_body_part) values('TC');
insert into t(alien_body_part) values('NC');
insert into t(alien_body_part) values('Extended Mandible');

select case when alien_body_part in ('TC', 'NC') then 0 else 1 end from t
                 *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got NCLOB

仅比较第一个字符:

SQL> SELECT dbms_lob.substr(alien_body_part, 4000, 1) body_part,
  2         CASE
  3            WHEN dbms_lob.substr(alien_body_part, 4000, 1)
  4                 IN ('TC', 'NC') THEN
  5             0
  6            ELSE
  7             1
  8         END is_nc_or_tc
  9    FROM t;

BODY_PART              IS_NC_OR_TC
---------------------- -----------
                                 1
TC                               0
NC                               0
Extended Mandible                1
在这种情况下,由于比较的一侧只有2个字符长,因此比较前3个字符就足够了(因为只有当NCLOB的长度为2个字符且这些字符明显等于“TC”时,NCLOB才会等于“TC”)

此外,案例和IN都不是此处错误的原因(您无法直接比较SQL中的CLOB/NCLOB),请考虑:

SQL> select * from t where alien_body_part = 'TC';

select * from t where alien_body_part = 'TC'

ORA-00932: inconsistent datatypes: expected - got NCLOB

+1为有趣的列名。