Solved

How to insert values for BLOB, CLOB ..etc?

Posted on 2011-03-24
7
895 Views
Last Modified: 2012-05-11
How to insert/update values for BLOB, CLOB ..etc
also need to know the usage for blob/clob,
need more examples for this.
How to check characters inside blob?
0
Comment
Question by:sakthikumar
  • 3
  • 2
  • 2
7 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35206098
Insert them from what tool/language/???

You will need to convert the BLOB back into a clob to check for strings/characters.
0
 

Expert Comment

by:BSSForests
ID: 35208135
The following code is how I update a file into a Oracle Blob using Java:
As for insert a new blob, you need insert a new record, blob field with value "empty_blob()", then update this blob field using code below.


import oracle.sql.BLOB;


            //
            // update the contents of the file into the blob.
            //
            // Note: We must use ORACLE specific classes to do this for now (not
            // supported by JDBC).
            // Select the blob for update (locking it).
            //
            File file = new File(tmpPdf);
            if (file != null && file.exists() && file.canRead()) { // Select the blob for update (locking it).
                        String query = "select blob_field from table_name where id = 3" + " for update";
                  //System.out.println("query = " + query);
                  Connection conn =
                        ((JDBCDataObjectManager) objectMgr).getConnection();
                  //Get data connection using your way.

                  Statement stmt = conn.createStatement();
                  FileInputStream fis = new FileInputStream(file);
                  InputStream in = new BufferedInputStream(fis);
                  OutputStream out = null;
                  try {
                        ResultSet result = stmt.executeQuery(query);
                        if (result.next()) { //
                              // Use ORACLE specific classes to get the blob output stream.
                              //
                              oracle.sql.BLOB blob = (oracle.sql.BLOB) result.getBlob(1);
                              out =
                                    new BufferedOutputStream(blob.getBinaryOutputStream());
                              byte[] buf = new byte[blob.getBufferSize()];
                              int len;
                              while ((len = in.read(buf)) != -1) {
                                    out.write(buf, 0, len);
                              }
                              out.flush();
                        }
                  } finally {
                        in.close();
                        if (out != null) {
                              out.close();
                        }
                        stmt.close();
                  }
            
                  file.delete();
            }
0
 

Expert Comment

by:BSSForests
ID: 35208148
Replace the query with your own,

 String query = "select blob_field from table_name where id = 3"
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:sakthikumar
ID: 35348117
Inserting from oracle plsql?
0
 

Author Comment

by:sakthikumar
ID: 35348132
normally we have a table in oracle, which has a clob column, when we are inserting the data by
writing a procedure, how do we insert a value for a clob column.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 35348141
You originally asked several questions in the original post.  Then the followup post didn't add much information.

Inserting LOBS from pl/sql is easy.  The online docs have many examples.

If the LOB is on the database server it's a simple dbms_lob.loadClobfrom file or dbms_lob.loadBlobfromfile

If the LOB is coming from some app and passed to a stored procedure as input, still easy.  Just declare the input parameter as a clob or blob.

For searching a blob, need $ore about the requirements.  You might be able to index them with Oracle Text and search for 'strings'. But I need to know the complete requirements.
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35348152
I was typing when you posted the second post:  Clob or blob? Two different requirements.

Inserting to a clob is simple:

Insert into clob_column values('hello');
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle query help 29 77
oracle query help 36 84
Bash Script to Analyze Oracle Schemas 11 85
Why  don't I see Below columns in my  Stored Procedure  under TMP_RS? 8 18
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now