Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
Oracle 从表中选择不同的CLOB_列;_Oracle_Plsql_Ora 00932 - Fatal编程技术网

Oracle 从表中选择不同的CLOB_列;

Oracle 从表中选择不同的CLOB_列;,oracle,plsql,ora-00932,Oracle,Plsql,Ora 00932,我想找到不同的CLOB值,这些值可以假定COPIA表中包含的CLOB类型的CLOB_列 我选择了一种过程方法来解决这个问题,但我更愿意给出一个简单的选择,如下所示:从表中选择不同的CLOB_列,避免错误ORA-00932:不一致的数据类型:预期的-得到的CLOB 我怎样才能做到这一点 提前感谢您的友好合作。这是我认为的程序性方式: -- Find the distinct CLOB values that can assume the column called CLOB_COLUMN (of

我想找到不同的CLOB值,这些值可以假定COPIA表中包含的CLOB类型的CLOB_列

我选择了一种过程方法来解决这个问题,但我更愿意给出一个简单的选择,如下所示:从表中选择不同的CLOB_列,避免错误ORA-00932:不一致的数据类型:预期的-得到的CLOB

我怎样才能做到这一点

提前感谢您的友好合作。这是我认为的程序性方式:

-- Find the distinct CLOB values that can assume the column called CLOB_COLUMN (of type CLOB)
-- contained in the table called COPIA
-- Before the execution of the following PL/SQL script, the CLOB values (including duplicates) 
-- are contained in the source table, called S1
-- At the end of the excecution of the PL/SQL script, the distinct values of the column called CLOB_COLUMN
-- can be find in the target table called S2

BEGIN
   EXECUTE IMMEDIATE 'TRUNCATE TABLE S1 DROP STORAGE';

   EXECUTE IMMEDIATE 'DROP TABLE S1 CASCADE CONSTRAINTS PURGE';
EXCEPTION
   WHEN OTHERS
   THEN
      BEGIN
         NULL;
      END;
END;

BEGIN
   EXECUTE IMMEDIATE 'TRUNCATE TABLE S2 DROP STORAGE';

   EXECUTE IMMEDIATE 'DROP TABLE S2 CASCADE CONSTRAINTS PURGE';
EXCEPTION
   WHEN OTHERS
   THEN
      BEGIN
         NULL;
      END;
END;

CREATE GLOBAL TEMPORARY TABLE S1
ON COMMIT PRESERVE ROWS
AS
   SELECT CLOB_COLUMN FROM COPIA;

CREATE GLOBAL TEMPORARY TABLE S2
ON COMMIT PRESERVE ROWS
AS
   SELECT *
     FROM S1
    WHERE 3 = 9;

BEGIN
   DECLARE
      CONTEGGIO   NUMBER;

      CURSOR C1
      IS
         SELECT CLOB_COLUMN FROM S1;

      C1_REC      C1%ROWTYPE;
   BEGIN
      FOR C1_REC IN C1
      LOOP
         -- How many records, in S2 table, are equal to c1_rec.clob_column?
         SELECT COUNT (*)
           INTO CONTEGGIO
           FROM S2 BETA
          WHERE DBMS_LOB.
                 COMPARE (BETA.CLOB_COLUMN,
                          C1_REC.CLOB_COLUMN) = 0;

         -- If it does not exist, in S2, a record equal to c1_rec.clob_column, 
         -- insert c1_rec.clob_column in the table called S2
         IF CONTEGGIO = 0
         THEN
            BEGIN
               INSERT INTO S2
                    VALUES (C1_REC.CLOB_COLUMN);

               COMMIT;
            END;
         END IF;
      END LOOP;
   END;
END;

使用这种方法。表中的“纵断面”列内容是NCLOB。我添加了where子句以减少运行所需的时间

with
  r as (select rownum i, content from profile where package = 'intl'),
  s as (select distinct (select min(i) from r where dbms_lob.compare(r.content, t.content) = 0) min_i from profile t where t.package = 'intl')
select (select content from r where r.i = s.min_i) content from s
;

它不会因为效率而赢得任何奖项,但应该会起作用。

您可以比较CLOB的哈希值,以确定它们是否不同:

SELECT your_clob
  FROM your_table
 WHERE ROWID IN (SELECT MIN(ROWID) 
                   FROM your_table
                  GROUP BY dbms_crypto.HASH(your_clob, dbms_crypto.HASH_SH1))
编辑:
哈希函数不能保证不会发生冲突。然而,按照设计,你不太可能遇到任何碰撞。但是,如果冲突风险要绕过oracle错误,您必须执行以下操作:

从表COPIA C1中选择CLOB_列
其中C1.ID从COPIA C2中选择不同的C2.ID,其中….

如果可以将字段截断为32767个字符,则此操作有效:

select distinct dbms_lob.substr(FIELD_CLOB,32767) from Table1

从表_name中选择distinct DBMS_LOB.substrcolumn_name,3000

如果将clob截断为varchar2大小不起作用,并且您担心哈希冲突,那么您可以:

为每行添加一个行号; 在不存在子查询中使用DBMS_lob.compare。排除重复项这意味着:将=0与更高的rownum进行比较。 例如:

create table t (
  c1 clob
);

insert into t values ( 'xxx' );
insert into t values ( 'xxx' );
insert into t values ( 'yyy' );

commit;

with rws as (
   select row_number () over ( order by rowid ) rn,
          t.*
   from   t
)
  select c1 from rws r1
  where  not exists (
    select * from rws r2
    where  dbms_lob.compare ( r1.c1, r2.c1 ) = 0
    and    r1.rn > r2.rn
  );

C1    
xxx   
yyy  
在distinct关键字后添加到_CHAR以将CLOB转换为CHAR

SELECT DISTINCT TO_CHAR(CLOB_FIELD) from table1;   //This will return distinct values in CLOB_FIELD

有100张唱片,效果很好,但有5500张唱片,速度太慢了。现在我尝试使用ROWID而不是ROWNUM:ROWID更有效。问题不会是ROWNUM对ROWID。问题将是^2或^3上的仅是猜测运行时特征。哈希值不保证对不同的输入不同。@Janek Bogucki:鉴于SHA1哈希冲突的概率极低,您可以安全地假设两个自然出现的字符串(即未为此目的进行反向工程的字符串)具有相同的SHA1哈希值,它们是相等的:@厨房里的鸡:请求使用此包的权利?请注意dbms_crypto.HASHx的空参数,3+1用于哈希冲突概率观察。您说:此用户需要使用DBMS_CRYPTO,否则您的问题将无法解决。赠款没有真正的安全风险。通常只根据需要授予特权。在这里,您有一个需要它的案例,所以他们应该授予它。如果截断是可以容忍的,这个解决方案比公认的解决方案更易于管理。