How to compare Blob datatype in a Trigger?

Let's say I've the following trigger to log changes of "Document", which is in Blob type:
create or replace TRIGGER audit_file AFTER INSERT OR UPDATE OR DELETE ON MyFileTable FOR EACH ROW
BEGIN
BEGIN
IF updating('Document') AND(:OLD.Document != :NEW.Document) THEN
Log_This ('Document', :OLD.Document, :NEW.Document);
END IF;
end;
end;
Can ":OLD.Document != :NEW.Document" actually compare the content of those two docs, or do they just compare their locators/pointes? If yes, is there a built-in function I can use to do comparison of their actual content?

For BLOBs you can use
<p/>
  FUNCTION DBMS_LOB.compare(lob_1    IN BLOB,
                              lob_2    IN BLOB,
                              amount   IN INTEGER := 4294967295,
                              offset_1 IN INTEGER := 1,
                              offset_2 IN INTEGER := 1)
    RETURN INTEGER;

Similar Messages

  • Comparing BLOB Datatypes

    In SQL Plus 8, I created a table with 2 fields of each datatype BLOB. Now with FORM6, I wanted to compare those two field if data of each row are same? I gtried the ususal way :blockname.itemname, but the message bad bind occurs. Now how can I compare such data types? Actually I wanted to compare two photos in database if they are same? Please give me the solutions if any.

    Hi,
    I am giving below an annonymous block which is used to compare two images stored as blob in one of my tables. The table has a primary key column called imgname and a blob column called img which stores the images.
    DECLARE
    cursor imgcompare_cur(image_name IN varchar2)
    is
    select img from test_image
    where imgname=image_name;
    v_image1 blob;
    v_image2 blob;
    begin
    open imgcompare_cur('ABC');
    fetch imgcompare_cur into v_image1;
    close imgcompare_cur;
    open imgcompare_cur('XYZ');
    fetch imgcompare_cur into v_image2;
    close imgcompare_cur;
    if DBMS_LOB.COMPARE(v_image1,v_image2)=0
    then
    dbms_output.put_line('Images are the same');
    else
    dbms_output.put_line('Images are different');
    end if;
    end;
    You can re-structure the above code to create a stored procedure or a FORMS procedure and pass the image names which you want to compare.
    Hope this helps.
    All the Best
    Ramesh

  • How to compare BLOB data in 9i between 2 tables

    Hi
    I need to compare data between two tables (which are the same structure across two schemas) which has BLOB data.
    I am using 9i so cannot use some of the new functionality provided in 10g and 11g.
    I was hoping I could, rather primatively, use the dbms_utility.get_hash_value function and compare has values.
    Running this works:
    select
    dbms_utility.get_hash_value( to_char('1'), 0, 1073741824 )
    from dual
    DBMS_UTILITY.GET_HASH_VALUE(TO
                         201884475but this doesn't:
    select
    dbms_utility.get_hash_value( to_blob('1'), 0, 1073741824 )
    from dual
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'GET_HASH_VALUE'Is there anyway to manage this?
    Thanks

    Or
    SQL> select   dbms_utility.get_hash_value (
                utl_raw.cast_to_varchar2 (to_blob ('1')),
                0,
                1073741824
             ) hash_value
      from   dual
    HASH_VALUE
    833483443
    1 row selected.

  • How to insert BLOB datatype image using PL/SQL Procedure and SQL Loader

    Hi,
    How to insert an image into database using PL/SQL Procedure and also how to insert using SQL Loader. Please help by giving sample code and process description.
    Thanks,
    Vijay V

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:232814159006

  • How we handle CLOB and BLOB Datatypes in HANA DB

    Dear HANA Gurus,
    We have would like to build EDW using HANA base on our source system Oracle and it's supports CLOB and BLOB datatypes
    Would you please suggest how do we handle in HANA DB.
    Let not say it's oracle specific.
    Regards,
    Manoj

    Hello,
    check SAP HANA SQL Reference Guide for list of data types:
    (page 14 - Classification of Data Types)
    https://service.sap.com/~sapidb/011000358700000604922011
    For this purpose might be useful following data types:
    Large Object (LOB) Types
    LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data such as text documents and images. The maximum size of an LOB is 2 GB.
    BLOB
    The BLOB data type is used to store large binary data.
    CLOB
    The CLOB data type is used to store large ASCII character data.
    NCLOB
    The NCLOB data type is used to store a large Unicode character object.
    Tomas

  • How can i make a pl/sql function for BLOB datatype

    hi..anyone here who is very familiar about BLOB datatype. i have a COLUMN_ID, COLUMN_A in a certain TABLE_1. COLUMN_A is blob datatype that contains almost 250,000rows
    SQL>select column_A from table_1 where column_id=1234567
    column_A
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    how can i make a user-defined function to compute and convert this blob datatype into decimal length value. this hex value are points in the map.. the function must contain
    1.get the length of a blob then
    2.convert blob to variable hexadecimal characters by parsing it into 8
    3.to_number function or other function used to convert haxadecimal characters to decimal numbers
    4.phythagorean formula to compute length between two points. this is the formula i think LENGTH =
    SQRT(power((coordinate_x-prev_coordinate_x),2)+power((coordinate_y-prev_y),2));
    after this when i type this
    SQL>select user_function(column_A) from table_1 where column_id=1234567
    user_functions(column_A)
    --output length will be in decimal value already
    the function will goes like this
    step1 is to get the blob length
    00000001000000010000000606D4E833074B69EC06D4E91F074CO18406D50C58074C031E
    step2 is parsing of data by eights
    00000001 =>1
    00000001 =>1
    00000006 =>6 (number of coordinates)
    06D4E833 => X1
    074B69EC => Y1
    06D4E91F => X2
    074CO184 => Y2
    06D50C58 => X3
    074C031E => Y3
    step3 to_number function used to convert hex char to decimal
    step4 compute by phytagorean (NOTE ! when computing length the third parsed eight will tell how many coordinates are there..the number of coordinates is ranging from 2 up to E..above example shows 6 coordinates so it means
    LENGTH1 =
    SQRT(power((X2-X1),2)+power((Y2-Y1),2));
    LENGTH2=
    SQRT(power((X3-X2),2)+power((Y3-Y2),2));
    TOTAL LENGTH=LENGTH1 + LENGTH2
    thanks

    its my first time to use that.There's got to be a first tiem for anything. Be brave.
    btw if theres more easy suggestion pls feel free..Well of course the easiest solution would be if the calling program passed in the parameters as separate arguments instead of glomming them together in a string that has to be parsed. This sort of kluj really ought not to have survived into C21.
    Cheers, APC

  • How to compare, current value in :block.text_item with the database value

    Hi
    Could you please tell me
    How to compare the current value in :block.text_item with the corresponding database column value.
    I am using forms 10g
    There is block and there is an text Item in that block.
    When I run the form and query the block (tabular), the :block.text_item shows me, whatever value there in the database.
    Now I add some value in the :block.text_item to the existing value.
    now
    the :block.text_item contains old+ new added value
    whereas
    the database table contains 'old' value
    Now on a button click , I want to find out what is the value that I have added
    Could you please tell me, is it possible without writing a select query?

    Hello,
    Now on a button click , I want to find out what is the value that I have addedSo you mean always user will add value in the existing value. Because this way will fail in one case. Let say
    Value in Database is = ABCD
    User opened the form and he removed the D and write E and now value is ABCE and length is still same 4. So, there is no addition.
    Anyway you can know the database value at runtime there is one property for item called DATABASE_VALUE. It gives the value which is in database while you are running the form before save. and you can use like this..
    Trigger = WHEN-MOUSE-DOUBLE-CLICK on item level
    DECLARE
      vItemValue DATATYPE; -- Set the data type according to your desired field.
      vValueAdded DATATYPE; -- Set the data type according to your desired field.
    BEGIN
      vItemValue:=GET_ITEM_PROPERTY('ITEM_NAME',DATABASE_VALUE);  -- It will return you the database value in vItemValue variable.
      IF LENGTH(vItemValue)>LENGTH(:FORM_ITEM_NAME) THEN  -- It mean something change or added
        vValueAdded:=SUBSTR(:FORM_ITEM_NAME,LENGTH(vItemValue)+1);
        MESSAGE('Added value is : '||vValueAdded);  -- It will show you the added value.
      END IF;
      -- now suppose you want to show the old and new value in message not the added one
      -- Then no need of IF condition. You can just use message like this
      -- And i would prefer to use like this way
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
      MESSAGE('Old Value : '||vItemValue||'  New Value - '||:FORM_ITEM_NAME);
    END;Hope it is clear.
    -Ammad

  • How to Create a datatype for a storeprocedure which has got array ?

    Hi All,
    Please tell me how to create a datatype for a storeprocedure which has got an array structure ?
    Thanks,
    Sindhu.

    Hi Sindhu.
    You would have to use a JDBC Cursor for this but it's possible only Output parameters, not Input parameters.
    It's describle in a help link:
    Defining an EXECUTE Statement  http://help.sap.com/saphelp_nwpi711/helpdata/en/44/7b72b2fde93673e10000000a114a6b/frameset.htm
    The following SQL data types are supported:
    INTEGER, BIT, TINYINT, SMALLINT, BIGINT, FLOAT, REAL, DOUBLE, NUMERIC, DECIMAL, CHAR, VARCHAR, STRING, LONGVARCHAR, DATE, TIME, TIMESTAMP, BINARY, VARBINARY, LONGVARBINARY, BLOB (input and output), CLOB (input and output), CURSOR (output; only in connection with the Oracle JDBC driver)
    I think you can execute your StoreProcedure many times depends of array occurs.
    Regards.
    Bruno.

  • Problem with special chars in BLOB datatype using contains keyword

    Facing problem, when part searching with special chars in BLOB datatype. It is considering the non alpha-numeric chars as a separtor in a provided string
    EX:
    SELECT *
    FROM RESUME_TEST P,grst_candidate d
    WHERE d.candidate_id = p.candidate_id
    AND CONTAINS(P.CAND_RESUME,'%VB.NET%',1) > 0
    Strings: , VB.NET , PL/SQL AS/400 , C etc..
    Followed the below approaches
    1) created a table:
    Syntax: create table resume_Test(cand_id number(10),cand_resume blob);
    2) inserted the values into this table upto 60,000
    3) created a context index
    3.1 created preferences
    Syntax:
    BEGIN
    ctx_ddl.create_preference('try_lexer3','BASIC_LEXER');
    ctx_ddl.set_attribute('try_lexer3','printjoins','-_~!@#$%^&*(){}[],=?\;|><.+');
    END;
    3.2 created context index
    Syntax:
    CREATE INDEX CANDRESUME_CTX_IDX ON resume_test (cand_resume)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('LEXER try_lexer3 memory 500M');
    4) while executing this index, it is taking much time approx 6 hrs(plz explain why it is taking time)
    5) Problems:
    5.1 when searching with string(VB.NET , PL/SQL AS/400 , C etc..) it is considering the special char as a separator
    5.2 used escape char (\) also, but no effect
    5.3 when searching with single char, it is giving error (ORA-29902,ORA-20000,DRG-51030)
    5.4 getting the above error with wild card chars (& ,_, (),{},[])
    So, please explain the clear scenarios, why am getting this error , and how to get the proper results.

    Have you tried adding the / char to the printjoin characters?
    Indexing can take a lot of time, depending on the amount of data and your machine's power. You could try to parallelize the index creation and / or assign more memory
    CREATE INDEX CANDRESUME_CTX_IDX ON resume_test (cand_resume)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS ('LEXER try_lexer3 memory 2000M') PARALLEL 8;

  • Insert record in table having BLOB datatype

    Hi All,
    I have a table with BLOB datatype, Pls assist me how to insert a record in this table?
    CREATE TABLE document_BLOB_tab (
    doc_id_no NUMBER
    , doc_name VARCHAR2(200)
    , doc_value BLOB);
    What are the process to execute DBMS_LOB.fileOpen ?
    Rgds
    Sarfaraz

    1- Create a table that has a list of all directory, filenames combination
    SQL> create table listpic (directory varchar2(10), filename varchar2(10));
    Table created.
    2- Insert into that table all your directories and the filenames of the images within each
    directory (directory, filename) combination
    on my file system, I have
    d:\tars\samples1\lilies.jpg
    d:\tars\samples1\Sunset.jpg
    d:\tars\samples2\Blue.jpg
    d:\tars\samples1\Winter.jpg
    Here is my insert statment
    SQL> insert into listpic values('Samples1', 'lilies.jpg');
    1 row created.
    SQL> insert into listpic values('Samples1', 'Sunset.jpg');
    1 row created.
    SQL> insert into listpic values('Samples2', 'Blue.jpg');
    1 row created.
    SQL> insert into listpic values('Samples2', 'Winter.jpg');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from listpic;
    DIRECTORY FILENAME
    Samples1 lilies.jpg
    Samples1 Sunset.jpg
    Samples2 Blue.jpg
    Samples2 Winter.jpg
    3- Create the table where you are going to store your pictures
    SQL> create table pictures (id number(5), image blob);
    Table created.
    4- Create a directory pointing to the common parent Directory
    SQL> create or replace directory IMAGES as 'd:\tars';
    Directory created.
    5- Create the following procedure to insert the image
    SQL> set serveroutput on
    SQL> create or replace procedure insert_image as
    2 f_lob bfile;
    3 b_lob blob;
    4 i number := 1;
    5 cursor image_cur is select directory, filename from listpic;
    6 pic_rec image_cur%ROWTYPE;
    7 begin
    8
    9 OPEN image_cur;
    10 Loop
    11 fetch image_cur into pic_rec;
    12 EXIT WHEN image_cur%NOTFOUND;
    13 insert into pictures values ( i, empty_blob() )
    14 return image into b_lob;
    15
    16 f_lob := bfilename( 'IMAGES','\'||pic_rec.DIRECTORY||'\'||pic_rec.FILENAME);
    17 dbms_lob.fileopen(f_lob, dbms_lob.file_readonly);
    18 dbms_lob.loadfromfile( b_lob, f_lob, dbms_lob.getlength(f_lob) );
    19 dbms_lob.fileclose(f_lob);
    20 dbms_output.put_line (pic_rec.directory ||'\'||pic_rec.filename);
    21 commit;
    22 i := i+1;
    23 END LOOP;
    24 end;
    25 /
    Procedure created.
    6- execute the procedure
    SQL> exec insert_image;
    Samples1\lilies.jpg
    Samples1\Sunset.jpg
    Samples2\Blue.jpg
    Samples2\Winter.jpg
    PL/SQL procedure successfully completed.
    SQL> select count(*) from pictures;
    COUNT(*)
    4
    SQL> select length(image) from pictures;
    LENGTH(IMAGE)
    83794
    71189
    28521
    105542
    Image has been uploaded to the dataabase.

  • Can LogMiner capture DMLs against rows with Blob datatype?

    Hi,
    Can LogMiner catch DMLs against rows with Blob datatype?
    if a Blob column is 4G big each row, and you delete millions of
    rows, but your redo log files is only 600M totally, I don't know (not sure) how those before-images of data can be stored in redo logfiles (also, you may need a very large log_archive_dest to hold those before-images )
    please help to explain.
    Thanks
    Roy

    Hi,
    Can LogMiner catch DMLs against rows with Blob datatype?
    if a Blob column is 4G big each row, and you delete millions of
    rows, but your redo log files is only 600M totally, I don't know (not sure) how those before-images of data can be stored in redo logfiles (also, you may need a very large log_archive_dest to hold those before-images )
    please help to explain.
    Thanks
    Roy

  • Dbms_crypto and blob datatypes

    Hi everyone
    I've been trying to learn how to encrypt data (a file uploaded) using blob datatype. This is me first attempt at encrypting and have been doing some research on this. I need to use the BLOB as I am encrypting a file that is uploaded to the system. Does anyone have experience in this or know of a good example that I can take a look at?
    Ray

    Hello,
    check SAP HANA SQL Reference Guide for list of data types:
    (page 14 - Classification of Data Types)
    https://service.sap.com/~sapidb/011000358700000604922011
    For this purpose might be useful following data types:
    Large Object (LOB) Types
    LOB (large objects) data types, CLOB, NCLOB and BLOB, are used to store a large amount of data such as text documents and images. The maximum size of an LOB is 2 GB.
    BLOB
    The BLOB data type is used to store large binary data.
    CLOB
    The CLOB data type is used to store large ASCII character data.
    NCLOB
    The NCLOB data type is used to store a large Unicode character object.
    Tomas

  • Problem while importing table with blob datatype

    hi i am having a database 9i on windows xp and dev database 9i on AIX 5.2
    while i am taking export of normal tables and trying to import i am successful.but when i am trying to import a table with blob datatype it is throwing "tablespace <tablespace_name> doesn't exist" error
    here how i followed.
    SQL*Plus: Release 9.2.0.1.0 - Production on Mon Oct 8 14:08:29 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Enter user-name: test@test
    Enter password: ****
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    SQL> create table x(photo blob);
    Table created.
    exporting:
    D:\>exp file=x.dmp log=x.log tables='TEST.X'
    Export: Release 9.2.0.1.0 - Production on Mon Oct 8 14:09:40 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Username: pavan@test
    Password:
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    Export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    About to export specified tables via Conventional Path ...
    Current user changed to TEST
    . . exporting table X 0 rows exported
    Export terminated successfully without warnings.
    importing:
    D:\>imp file=x.dmp log=ximp.log fromuser='TEST' touser='IBT' tables='X'
    Import: Release 9.2.0.1.0 - Production on Mon Oct 8 14:10:42 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Username: system@mch
    Password:
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP and Oracle Data Mining op
    tions
    JServer Release 9.2.0.6.0 - Production
    Export file created by EXPORT:V09.02.00 via conventional path
    Warning: the objects were exported by PAVAN, not by you
    import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
    import server uses US7ASCII character set (possible charset conversion)
    . importing TEST's objects into IBT
    IMP-00017: following statement failed with ORACLE error 959:
    "CREATE TABLE "X" ("PHOTO" BLOB) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS "
    "255 STORAGE(INITIAL 65536 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "TESTTB"
    "S" LOGGING NOCOMPRESS LOB ("PHOTO") STORE AS (TABLESPACE "TESTTBS" ENABLE "
    "STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE STORAGE(INITIAL 65536 FREE"
    "LISTS 1 FREELIST GROUPS 1))"
    IMP-00003: ORACLE error 959 encountered
    ORA-00959: tablespace 'TESTTBS' does not exist
    Import terminated successfully with warnings.
    why it is happening for this table alone?plz help me
    thanks in advance

    Here is exerpt from {
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:378418239571}
    =============================================
    Hi Tom,
    I have a dump file containing blob datatypes, when i import the dump file in a schema it gives an
    error stating that the tablespace for Blob datatype does not exists. My question is how do i import
    the dump file in the default tablespace of the importing user.
    Followup March 2, 2004 - 7am US/Eastern:
    You'll have to precreate the table.
    do this:
    imp userid=u/p tables=that_table indexfile=that_table.sql
    edit that_table.sql, fix up the tablespace references to be whatever you want to be, run that sql.
    then imp with ignore=y
    for any MULTI-SEGMENT object (iot's with overflows, tables with lobs, partitioned tables, for
    example), you have to do this -- imp will not rewrite ALL of the tablespaces in that
    multi-tablespace create -- hence you either need to have the same tablespaces in place or precreate
    the object with the proper tablespaces.
    Only for single tablespace segments will imp rewrite the create to go into the default if the
    requested tablespace does not exist.
    ===================================================
    To summarize: precreate target table when importing multi-segment tables

  • How to compare two PDF files through PLSQL

    Hi,
    Can any body help that how to compare two PDF files through PLSQL programing and gives the differences as output.
    Thanks,

    Or simply apply an oracle text index on your pdf column:
    SQL>  create table t (id integer primary key, bl blob)
    Table created.
    SQL>  declare
    bf bfile := bfilename('TEMP','b32001.pdf');
    bl blob;
    begin
    dbms_lob.createtemporary(bl,true);
    dbms_lob.open(bf,dbms_lob.lob_readonly);
    DBMS_LOB.LOADFROMFILE(bl, bf,dbms_lob.getlength(bf));
    insert into t values (1,bl);
    commit;
    dbms_lob.close(bf);
    dbms_lob.freetemporary(bl);
    end;
    PL/SQL procedure successfully completed.
    SQL>  create index t_idx on t (bl) indextype is ctxsys.context parameters ('filter ctxsys.auto_filter')
    Index created.
    SQL>  declare
       mklob   clob;
    begin
       ctx_doc.filter ('t_idx', '1', mklob, true);
       dbms_output.put_line (substr (mklob, 1, 250));
       dbms_lob.freetemporary (mklob);
    end;
    Oracle® Database
    Release Notes
    11
    g
    Release 1 (11.1) for Linux
    B32001-04
    November 2007
    This document contains important information that was not included in the
    platform-specific or product-specific documentation
    PL/SQL procedure successfully completed.This generates a text only version of your pdf and standard text comparison methods can be applied ....

  • Cannot upload file to Oracle DB using blob datatype

    Hi
    I am uploading a file to Oracle DB through JAVA. I am inserting the file as
    a BLOB datatype. I am using JRUN 4 . But when I am uploading the file to the DB through my application it is not showing anything in the DB. The samp application is working fine on my QA environment on the same server . Is there some setting that needs to be done . Could this be a problem with the version of classes12.zip.
    Also when i try to view the file it is giving me this error
    ORA-06550: line 1, column 13:
    PLS-00201: identifier 'DBMS_LOB' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Please help

    Not sure afterall if you mean that you are having a pblm uploading (from what kind of file BTW?) or viewing after upload?
    Try these tutorials - I found them very helpful. Also, do you have the 'PL/SQL Programming' book from Oracle Press? That has an entire chapter devoted to LOB types.
    [url http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/blob/blob.html] How to deploy a PL/SQL function returning BLOB as Web Service
    [url http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java.html]LOBsample
    HTH

Maybe you are looking for