Search a string in a blob

I need urgent help
regarding blobs in Oracle8i
database on SuSe-Linux.
I'm trying to make a procedure
searching for patterns in a blob.
The procedure is allways invalid
with errors regarding hextoraw or raw.
I'm making this procedure based on an example of technet.oracle.com
(EXAMPLE_13A).
Up to now I'm doing it by saving
the blobs as clobs
and searching in the clobs (it doesn't
works with pdf).
But this is no acceptable solution.
Can somebody give me an example or advice how to proceed?
Additionally I'd like to know how a string can be converted
into raw- or hextoraw format.
For your information: We have interMedia but we can not make it
run on Linux.
null

If the BLOB is smaller than 32767 in length, you can simply:
DECLARE
   p_blob   BLOB := UTL_RAW.cast_to_raw (RPAD ('X', 32767));
BEGIN
   p_blob :=
      UTL_RAW.cast_to_raw (REPLACE (UTL_RAW.cast_to_varchar2 (p_blob),
                                    'X',
                                    'Y'
END;

Similar Messages

  • Searching a string in a pdf blob

    Hi,
    My requirement is finding a string in a blob data. I am using
    dbms_lob.INSTR(FILE_DATA, utl_raw.cast_to_raw('Tag Switch'),1,1) > 0 approach.
    It is working properly for doc htm, text formats. But when we try to search in pdf blobs, it isn't working.
    Can someone suggest a solution for this issue?

    You can use Oracle Text to search your words in pdf files.
    SQL> SELECT * FROM v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL> /* Creating my demo table */
    SQL> CREATE TABLE pdm(id_pk INTEGER,fname VARCHAR2(30),pdf_file BLOB);
    Table created.
    SQL> /* Creating the directory object for latter use */
    SQL> CREATE OR REPLACE DIRECTORY TEMP AS 'c:\';
    Directory created.
    SQL> /* Creating a procedure which will load the BLOBs (pdf files) into the table */
    SQL> CREATE OR REPLACE PROCEDURE load_file(pi_id IN INTEGER, pfname IN VARCHAR2) IS
      2    src_file BFILE;
      3    dst_file BLOB;
      4    lgh_file BINARY_INTEGER;
      5  BEGIN
      6    src_file := bfilename('TEMP', pfname);
      7 
      8    INSERT INTO pdm
      9      (id_pk, fname, pdf_file)
    10    VALUES
    11      (pi_id, pfname, EMPTY_BLOB())
    12    RETURNING pdf_file INTO dst_file;
    13 
    14    DBMS_LOB.OPEN(src_file, dbms_lob.file_readonly);
    15    lgh_file := dbms_lob.getlength(src_file);
    16    DBMS_LOB.LOADFROMFILE(dst_file, src_file, lgh_file);
    17    dbms_lob.close(src_file);
    18    COMMIT;
    19  END load_file;
    20  /
    Procedure created.
    SQL> EXECUTE load_file(1,'plsql_new_in_11gr1.pdf');
    PL/SQL procedure successfully completed.
    SQL> EXECUTE load_file(2,'Model clause.pdf');
    PL/SQL procedure successfully completed.
    SQL>
    SQL> SELECT id_pk,fname,DBMS_LOB.getlength(pdf_file)
      2  FROM pdm;
         ID_PK FNAME                          DBMS_LOB.GETLENGTH(PDF_FILE)
             1 plsql_new_in_11gr1.pdf                               170264
             2 Model clause.pdf                                    4288164
    SQL> /* Creating the index */
    SQL> CREATE INDEX pdm_pdf_idx ON pdm(pdf_file) INDEXTYPE IS CTXSYS.CONTEXT;
    Index created.
    SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'PDM', cascade=>TRUE);
    PL/SQL procedure successfully completed.
    SQL> SELECT id_pk,fname
      2  FROM pdm
      3  WHERE CONTAINS(pdf_file,'PL/SQL')>0;
         ID_PK FNAME
             1 plsql_new_in_11gr1.pdf
    SQL> SELECT id_pk,fname
      2  FROM pdm
      3  WHERE CONTAINS(pdf_file,'Fine-grained access control')>0;
         ID_PK FNAME
             1 plsql_new_in_11gr1.pdf
    SQL> SELECT id_pk,fname,DBMS_LOB.getlength(pdf_file)
      2  FROM pdm;
         ID_PK FNAME                          DBMS_LOB.GETLENGTH(PDF_FILE)
             1 plsql_new_in_11gr1.pdf                               170264
             2 Model clause.pdf                                    4288164
    SQL> SELECT id_pk,fname
      2  FROM pdm
      3  WHERE CONTAINS(pdf_file,'Saubhik')>0;
    no rows selected
    SQL> EXECUTE load_file(3,'plsql_conditional_compilation.pdf');
    BEGIN load_file(3,'plsql_conditional_compilation.pdf'); END;
    ERROR at line 1:
    ORA-12899: value too large for column "SCOTT"."PDM"."FNAME" (actual: 33,
    maximum: 30)
    ORA-06512: at "SCOTT.LOAD_FILE", line 8
    ORA-06512: at line 1
    SQL> EXECUTE load_file(3,'conditional_compilation.pdf');
    PL/SQL procedure successfully completed.
    SQL> SELECT id_pk,fname,DBMS_LOB.getlength(pdf_file)
      2  FROM pdm;
         ID_PK FNAME                          DBMS_LOB.GETLENGTH(PDF_FILE)
             1 plsql_new_in_11gr1.pdf                               170264
             2 Model clause.pdf                                    4288164
             3 conditional_compilation.pdf                          540594
    SQL> EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'PDM', cascade=>TRUE);
    PL/SQL procedure successfully completed.
    SQL> SELECT id_pk,fname
      2  FROM pdm
      3  WHERE CONTAINS(pdf_file,'conditional')>0;
         ID_PK FNAME
             1 plsql_new_in_11gr1.pdf
             3 conditional_compilation.pdf
    SQL> SELECT id_pk,fname
      2  FROM pdm
      3  WHERE CONTAINS(pdf_file,'The Catch 22')>0;
         ID_PK FNAME
             3 conditional_compilation.pdf
    SQL>

  • How to serch a character string in a BLOB (case insensitive)

    Hi
    Could somebody help me with this please.
    I need to search for the existance of a character string in a BLOB column of a table.
    I can do it in the below way.
    PROCEDURE search (in_search VARCHAR2) IS
    lob_doc BLOB;
    Pattern VARCHAR2(30);
    Position INTEGER := 0;
    Offset INTEGER := 1;
    Occurrence INTEGER := 1;
    BEGIN
    Pattern := utl_raw.cast_to_raw(in_search);
    SELECT BLOB_CONTENT INTO lob_doc
    FROM documents WHERE ein = '702265981';
    DBMS_LOB.OPEN (lob_doc, DBMS_LOB.LOB_READONLY);
    Position := DBMS_LOB.INSTR(lob_doc, Pattern, Offset, Occurrence);
    IF Position = 0 THEN
    DBMS_OUTPUT.PUT_LINE('Pattern not found');
    ELSE
    DBMS_OUTPUT.PUT_LINE('The pattern occurs at '|| position);
    END IF;
    DBMS_LOB.CLOSE (lob_doc);
    END search;
    But the problem is, it does a case sensitive search.
    I need a case-insensitive search
    Thanks in Advance

    The best way would be to use Oracle Text.
    However, if you want a quick and dirty solution, I would convert to CLOB, and (assuming 9i) you can use LOWER on the CLOB.
    Click on this link for a blob_to_clob function.
    Re: BLOB to CLOB?

  • Inserting String data to BLOB column

    Hi All
    I want to insert String data into BLOB column using DBAdapter - through database procedure.
    anybody can help?
    Regards
    Albin Issac

    I have used utl_raw.cast_to_raw('this is only a test')).But for bigger string I get the error as "string literal too long" do we have any similar function for longer string.
    Thanks,
    -R

  • Help required- Searching Particular string in column

    Hi,
    I have a table by name temp and 2 values in the table. I'm using LIKE caluse to search a string. I'm getting output for some particular string. Please correct the below query for me.
    I have given a table/data reference for you:
    Create table temp(col1 varchar2(255));
    insert into temp values ('Test_Scale_High');
    1 row inserted
    insert into temp values ('Test_Scale_High');
    1 row inserted
    commit;
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_H%';
    No Row Selected
    Thanks,
    Santhosh.S

    santhosh.shivaram wrote:
    select * from temp;
    col1
    Test_Scale_High
    Test_Scale High
    select * from temp where upper(col1) like '%TEST_SCALE%';
    COL1
    Test_Scale_High
    Test_Scale High
    select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
    COL1
    Test_Scale_High
    Test_Scale High
    If I understand your requirement correctly you need to escape the Wild Card '_'
    Hope the following code helps:
    SQL> set feedback on;
    SQL> SELECT * FROM TEMP
      2  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE_H%'
      4  /
    COL1
    Test_Scale_High
    Test_Scale High
    2 rows selected.
    SQL> SELECT *
      2    FROM temp
      3   WHERE UPPER (col1) LIKE '%TEST_SCALE\_H%' ESCAPE '\'
      4  /
    COL1
    Test_Scale_High
    1 row selected.
    SQL>Regards,
    Jo
    Edited by: Joice John : Added 2 Sample Codes

  • How to search a string in some folder.

    Hi ,
    In my application users will upload some pdf,xls files to server. files will be saved in server. From the front end can search on all files with some specific string. If that string is there in any of the file, user has to get link to download that file and the text just before and after that user string. Its like how we get in google. This type of search we need to implement, Could any one please let me know how to implement, any free API are there in java. Please its urgent, help on this.
    Thanks
    Mohan

    user594301 wrote:
    I have 2 columns in a table. entry_no and msg_txt. entry_no is number(12) and msg_txt is LONG. I want to search one string in msg_txt. How can I write a query for this ?You can't write a query for this. The only thinks you can do with a long in a query is put something in and take it out again - with diffiuclty, usually.
    You can write a PL/SQL function to do this for you if necessary. The function will have to perform the search directly if the long < 32760 bytes or use DBMS_SQL to break the LONG up into 32760 byte segments that can then be manually searched. If you are lucky someone has done this already and posted the code online. Either way the solution will be slow and probably painful to implement.
    If possible convert your data to a CLOB and use DBMS_CLOB to find the data you need.

  • Search a string with in some file and get the name of file

    i want to search a string in some files that are in a given directory and return the name of file having searched string.I am doing this with grep command as given below
    import java.io.*;
    public class linux_java {
    public static void main(String[] args) {
    try {
    String command = "find . | xargs grep -l Resolv /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG/*.txt";
    final Process process = Runtime.getRuntime().exec(command);
    OutputStream os= process.getOutputStream();
    System.out.println("out put stream= " +os);
    PrintStream stdIn = new PrintStream(new BufferedOutputStream(process.getOutputStream()), true);
    System.out.println("Return code = " + stdIn);
    } catch (Exception e) {
    e.printStackTrace();
    i dont know how to get the name of file that are return by the execution of command through process object. Please send the code for the same

    thanks for your suggestion....
    i change the code but now it is giving error as /usr/bin/find incomplete syntax....but i am giving the right syntax....
    please confirm whether the syntax is correct...
    import java.io.*;
    import java.util.*;
    public class linux_java {
    public static void main(String[] args) {
    try {
    //String command = "ls -alt";
    String command = "find /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG -type f -exec grep -sl 'Aggarwal' {} \\; 2>/dev/null";
    ///grep -l System test/*java
    System.out.println(" the command is"+command);
    final Process process = Runtime.getRuntime().exec(command);
    InputStream is = process.getErrorStream();
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line="";
    System.out.println(" the BufferedReader is"+br.readLine());
    while ((line = br.readLine()) != null) {
    System.out.println(" the files are"+line);
    } catch (Exception e) {
    e.printStackTrace();
    }

  • How to search a string from the database?

    how to search a string from the database? starting with some character

    If you're trying to do this in a SELECT, you can use the LIKE verb in your WHERE clause.
    Here's an Example
      SELECT obj_name FROM tadir
        INTO prog
        WHERE pgmid = 'R3TR'
          AND object = 'PROG'
          AND obj_name LIKE 'Z%'.
    In this case it will select every row that obj_name starts with Z. 
    If you wanted to find every row that the field obj_name contains say... 'WIN'  you use LIKE '%WIN%'.
    Edited by: Paul Chapman on Apr 22, 2008 12:32 PM

  • Increasing the speed of searching a string in a file

    I have to search a String in a big ASCII-file and have to delete it. Now I wrote a program which opens the source file and a target file. I am reading each line from the source file, check it and write it into the target file. It is working fine but it is very slowly.
    I check each line with:
    if (line.equalsIgnoreCase("xxxxx")) { }
    How can I make it much faster.
    Thank you for your help!
    Arthur

    IO is an issue, but I've noticed that changing the case of strings is very slow, probably because in unicode is harder than in ASCII.
    If you could replace the equalsIgnoreCase method by one or more equals, you'll get benefits. If you can, I would try something like the following to minimize the equalsIgnoreCase invocations:
    // Supose you are looking for "abcd"
    if (line.charAt(0) == 'a' || line.charAt(0) == 'A') {
       if (line.equals("xxxxx")) { }
    }Try it and let us know if it worth the effort.

  • Is it possible to search for strings containing spaces and special characters?

    In our RoboHelp project, there are figures with text labels such as Figure 1, Figure 3-2, etc.
    When I search for "Figure 3" I get all pages containing "Figure" and "3", even if I surround it in quotes.  Similarly, searching for "3-2" treats the '-' character as a space and searches for all pages containing '3' or '2'.
    Is there a way to search for strings containing spaces and special characters?

    In that case I think the answer is no if you are using the standard search engine. However I believe that Zoom Search does allow this type of searching. Check out this link for further information.
    http://www.grainge.org/pages/authoring/zoomsearch/zoomsearch.htm
      The RoboColum(n)
      @robocolumn
      Colum McAndrew

  • Searching a string in Forms V5.

    Hi all,
    My requirement is to search a string in a Form (Forms Version 5.0.6.8.0. However If I go to <Filie-Administration-Object list report), I am getting a ascii file. All the objects in the form are listed in the file. So, I do a 'Search' of my required String in the ascii file.
    However, in the <Ascii> file, I find that the program units are not converted to txt file. Only the program unit's name is present.
    Is there any other method, by which I can search my required string in the form(includding all program units, viz., triggers, program units)?
    Thanks in advance for ur help.
    null

    Maybe this will help you:
    We have FREE versions of FormDiff and FormGrep,the productivity tools for Oracle Developer, available for downloading now.
    There are NO FORMS to fill out, NO LIMIT on how long you can use them and best of all NO COST.
    Check out the latest FormDiff features and download your FREE VERSION now: http://www.aug10.com/products/FormDiff
    Using FormDiff, you can now document changes made to Forms and perform meaningful code reviews.
    Checkout the latest FormGrep features and download your FREE VERSION now: http://www.aug10.com/products/FormGrep
    Using FormGrep, you can 'Find and Replace PL/SQL code' across hundreds of FMBs at a time.
    Thank you for your time,
    Jesse Johnson - Managing Principal
    August Tenth Systems, Inc.
    PO Box 3682
    Boulder, CO 80307-3682 http://www.aug10.com/
    Helena

  • SPECIFYING THE NUMBER OF IDENTICAL CHARACTERS WHEN SEARCHING A STRING

    Hey everyone,
    The built-in function indexOf() searches for a character "." in the string "1.2.3." if the value == 1.
    It searches nothing if the value == 0 or 2 or any number greater than 2.
    var txt:String = "1.2.3.";
    var output:String = String(this);
    if (txt.indexOf(".") == 1)
    trace(output);     //[object MainTimeline]
    The must be a simple method for specifying the number of characters "." when searching the string "1.2.3.".
    For example if there is 2 characters "." in the string "1.2.", then run through a statement but if it does not contain 2 characters "." then do nothing.
    There is a built-in function called contains but it is mainly used in XML.
    indexOf() looks like unstable javascript codes, one of those framework that unixers hate.

    Why have an alternative when the built-in RegExp class does the job better than anything else?   Is it that you find them too hard to work with?  If you want a one line solution and prefer to use the older built-in methods you can do so by creating your own custom class to do what you want... searching a string character by character for the one you wish to isolate and counting them.
    In any case, you have a solution to counting the number of "." characters.
    "Many" people say what?  I doubt many people say anything like that at all.

  • Searching a String in Script

    Hi All,
    I need one help is there any provision to search for string in standard or customized scripts....for example to search a string in programs..through program RPR_ABAP_SOURCE_SCAN i can search in program...same way how can i search for a text in scripts ??
    Regards
    VEnk@

    Continue....
    FORMAT COLOR COL_NORMAL INTENSIFIED ON.
      STXL_ID-TDOBJECT = 'FORM'.
      STXL_ID-TDID = 'TXT'.
      SELECT * FROM STXL CLIENT SPECIFIED
              WHERE MANDT    = PA_MANDT
                AND RELID    EQ 'TX'
                AND TDOBJECT EQ 'FORM'
                AND TDID     EQ 'TXT'
                AND TDNAME   IN SO_NAME
                AND TDSPRAS  IN SO_SPRAS.
        MOVE-CORRESPONDING STXL TO I_STXL.
        APPEND I_STXL.
      ENDSELECT.
      SORT I_STXL.
      CLEAR HUIDIGE_TDSPRAS_TDNAME.
      CLEAR VORIGE_TDSPRAS_TDNAME.
      LOOP AT I_STXL.
        STXL_ID-TDNAME  = I_STXL-TDNAME.
        STXL_ID-TDSPRAS = I_STXL-TDSPRAS.
        STXL_ID-TDID    = I_STXL-TDID.
        CONCATENATE STXL_ID-TDSPRAS STXL_ID-TDNAME
                    INTO HUIDIGE_TDSPRAS_TDNAME.
        IF HUIDIGE_TDSPRAS_TDNAME <> VORIGE_TDSPRAS_TDNAME.
          CONCATENATE STXL_ID-TDSPRAS STXL_ID-TDNAME
                                      INTO VORIGE_TDSPRAS_TDNAME.
          REFRESH LINES.
          CLEAR H_TEL.
          IMPORT TLINE TO LINES FROM DATABASE STXL(TX)
                                     CLIENT   I_STXL-MANDT
                                     ID       STXL_ID.
          LOOP AT LINES.
            IF LINES-TDFORMAT = '/W'.
              H_WINDOW = LINES-TDLINE.
            ENDIF.
            SEARCH LINES-TDLINE FOR H_STRING1.
            IF SY-SUBRC <> 0 AND H_STRING2 <> SPACE.
              SEARCH LINES-TDLINE FOR H_STRING2.
            ENDIF.
            IF SY-SUBRC EQ 0 AND LINES-TDFORMAT NE '/*'.
              H_POS = SY-FDPOS.
              IF NOT PA_ITEM1 IS INITIAL.
                ADD 8 TO H_POS.
              ENDIF.
              IF NOT PA_ITEM4 IS INITIAL.
                ADD 11 TO H_POS.
              ENDIF.
              H_LEN = STRLEN( PA_STR ).
              H_STRING = LINES-TDLINE+H_POS(H_LEN).
              IF H_TEL EQ 0.
                HIDE I_STXL-MANDT.
                HIDE STXL-TDNAME.
                HIDE I_STXL-TDSPRAS.
                WRITE: /001 I_STXL-MANDT,
                        005 STXL-TDNAME HOTSPOT ON,
                        036 I_STXL-TDSPRAS,
                        041 H_WINDOW(30).

  • Searching TEXT String in a document stored in BLOB Column

    Hi,
    I fairly new to this concept of Oracle iText. I would like to get the atmost procedural approach to meet the following scenario.
    I have a table with 3 columns (viz. id,name, content) of which content is a BLOB datatype. I have stored a simple .doc file in this column. (Just one row has been stored into this table ). I am aware that this document contains my search word say 'TOPIC'.
    These are the following steps i did to get my soln but didnt meet my expected result.
    1. Inserted the row into the table ..... successful
    2. Tried to do a simple select (using contains)after creating context index....no rows selected
    3. Tried to create preference (DIRECT_PREFERENCE) and create an index using this PREFERENCE and do the select for the search string......no rows selected
    It would b great if u would let me know, how can i retrive the doc info ie. atleast the id,name from the database if i get a matched search string in the table.
    Regards
    Kevin

    When you index BLOBs (or RAW, or file) the product assumes that you have some kind of
    binary data -- like Microsoft Word or something like that. It then automatically
    engages the INSO filter.
    In your case, if I understand correctly, you have text data stored in a blob.
    So INSO filtering is not appropriate. So you will want to tell the product not to
    use INSO:
    create index ...
    parameters ('filter ctxsys.null_filter');
    try that...

  • A better way to search a string in a 3GB txt file

    I am looking for a string(12 characters) in a 3GB txt file. I use the file reader to go though each line and use the startwith() (that 12 characters are from the beginning of each line) to check if that line contain the string I am searching for. Is there a faster way to do it? Thank's.

    I would avoid using java to parse/search a 3 GB text file at all costs. Any java solution is going to have terrible performance and you may run into memory problems. I would recomend that you either a) develop a native method for resolving this search and just invoke it from your current java class or b) use Runtime.exec to invoke a native OS command for searching the file (like grep or find) and parse the results. ....
    I'm not even sure how I would complete that task with java exclusivly ... maybe break the file into smaller parts, then iterate through each smaller, temporary file ... I would really recomend storing your data in a different format if possible. A 3 GB text file just isn't very partical or secure.
    ... oh, to answer your original question (which I'm not sure if I all ready did), the fatest way to load the file is to wrap it into some BufferedReader. The fatest way to perform String searches is through the java.util.regex package if you have access to the 1.4 API. Other wise, just use basic String searches, as you all ready are.

Maybe you are looking for

  • Safari won't open, claims webcore plugin issue?

    Hello, for some reason, the safari on my macbook won't open. Claims it is some sort of webcore plugin issue. I'll post the problem details here in case it helps. Thank you in advance! Process:     Safari [751] Path:        /Applications/Safari.app/Co

  • Coexistance of Acrobat 6.0 professional and Reader 7.0

    Hi, I have acrobat professional 6.0 installed on my computer. Later I installed acrobat reader 7.0 with the latest updates. Now I cannot open a PDF file for editing. Even if I open it using Open with, I always get Acrobat reader 7.0 and not the 6.0 p

  • Session between WAR files

    hello, I am asking a question, however I still did not try it out (just being onest). Would a session variable work between two WAR files? For-example: Imagine I have WAR file A, that have a link to page WAR file B. Will the page in WAR file B have a

  • After updating firefox now I can't access any websites other than gmail and youtube

    today I upgraded firefox now i can't open any windows on my computer except for google and youtube. can't go back to EI either.

  • Cannot get Extensions with iFrames to work under Windows

    Currently we are unable to add an iFrame to the main HTML panel without the Windows version of Adobe InDesign closing the extension automatically.  This works correctly on the MAC.