|
|
|
|
|
|
|
|
Re: Error while casting to VARBINARY, Casting to VARBINARY Causes Error - "missing right parenthesis" [message #638258 is a reply to message #638256] |
Mon, 08 June 2015 07:23 ![Go to previous message Go to previous message](/forum/theme/orafaq/images/up.png) |
![](/forum/images/custom_avatars/72104.gif) |
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
DISTINCT, on a BLOB column, won't work (as you already noticed):
SQL> DESC a1_test;
Name Null? Type
----------------------------------------- -------- ----------------------------
ID NUMBER(2)
BLOB_CONTENT BLOB
BLOB_HASH RAW(40)
SQL> SELECT DISTINCT blob_content FROM a1_test;
SELECT DISTINCT blob_content FROM a1_test
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got BLOB
If it suits your needs, calculate its hash value and select distinct hashes instead. For example:
SQL> DECLARE
2 l_hash RAW (40);
3 BEGIN
4 FOR cur_r IN (SELECT id, blob_content FROM a1_test)
5 LOOP
6 l_hash := DBMS_CRYPTO.hash (cur_r.blob_content, DBMS_CRYPTO.hash_sh1);
7
8 UPDATE a1_test
9 SET blob_hash = l_hash
10 WHERE id = cur_r.id;
11 END LOOP;
12 END;
13 /
PL/SQL procedure successfully completed.
SQL> COL blob_hash FORMAT a40;
SQL>
SQL> SELECT DISTINCT blob_hash FROM a1_test;
BLOB_HASH
----------------------------------------
14D0966C40D7A3FEF653361EC2D6776DB5A4673F
2DBF1AA0F0C68215156AFEB35E5FA42516285434
F4C8AD2C6F67CA585AD17ED70EE8167BCD6C4B68
B144A1FCADF95C98DDA27E537A4D0EF4C8453EC9
27DD799F685856627C0BFCB2B131E66B55D691A4
B77E6C247AD8CBDFCCC59FC66AC148235166ABCF
C0F44FE2DCC3B71238EF44F0E349A5765EB7C8E5
6DA0114E7BDCB0EA0191132DCBB8E27F3D0C25A6
8 rows selected.
SQL>
|
|
|