MacLochlainns Weblog

Michael McLaughlin’s Technical Blog

Site Admin

Oracle LOB Processing

with 9 comments

This page demonstrates how to upload, store, and manage CLOBs (Character Large OBjects) and BLOBs (Binary Large OBjects). It provides some instructions that supplement Chapter 8 in my Oracle Database 11g PL/SQL Programming book.

Before you begin these steps, you should have already installed Zend Server Community Edition. If you haven’t done so, please click here for instructions.

If you find any problems, please let me know. I’ll be happy to fix them.

Written by maclochlainn

June 29th, 2009 at 8:15 pm

Posted in

9 Responses to 'Oracle LOB Processing'

Subscribe to comments with RSS or TrackBack to 'Oracle LOB Processing'.

  1. how do I query to see if a blob is loaded in a column?

    michael

    30 Jun 09 at 3:53 pm

  2. I’ll put the following query in the troubleshooting section but here it is. You use the GETLENGTH function from the DBMS_LOB package, like this:

    SELECT   i.item_id
    ,        dbms_lob.getlength(i.item_clob)
    ,        dbms_lob.getlength(i.item_blob)
    FROM     item i
    WHERE    i.item_desc IS NOT NULL
    OR       i.item_blob IS NOT NULL;

    maclochlainn

    30 Jun 09 at 4:05 pm

  3. In ZEND I don’t get any errors when I should. So I fixed it by changing a line in php.ini file to say:

    display_errors = ON

    This enables it because by default it is off.

    Michael

    1 Jul 09 at 10:52 am

  4. I’m stumped.

    I followed all the instructions, I checked the credentials, changed both db connection strings to localhost/xe. There is nothing in the temp directory. When I do a describe on the item table there is a zero in the item_desc column, and nothing (null) in the item_blob column.

    Moe

    9 Jul 09 at 8:26 pm

  5. If there’s nothing in the temp directory, then the database hasn’t been touched. The process_uploaded_file() function takes the uploaded file and moves it from the temporary cache to the temp directory.

    In your environment, this appears to not be working. This happens before any database activity. Is the temp directory a subdirectory of the directory where you’ve placed the PHP code? If not, you’d get this error unless you rewrite the function provided. I did it that way so that it would work on Linux/Unix or Windows systems. Please let me know if I can help more.

      function process_uploaded_file()
      {
        // Declare a variable for file contents.
        $contents = "";
     
        // Define the upload file name for Windows or Linux.
        if (ereg("Win32",$_SERVER["SERVER_SOFTWARE"]))
          $upload_file = getcwd()."\\temp\\".$_FILES['userfile']['name'];
        else
          $upload_file = getcwd()."/temp/".$_FILES['userfile']['name'];
     
        // Check for and move uploaded file.
        if (is_uploaded_file($_FILES['userfile']['tmp_name']))
          move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_file);
     
        // Open a file handle and suppress an error for a missing file.
        if ($fp = @fopen($upload_file,"r"))
        {
          // Read until the end-of-file marker.
          while (!feof($fp))
            $contents .= fgetc($fp);
          // Close an open file handle.
          fclose($fp);
        }
        // Return file content as string.
        return $contents;
      }

    maclochlainn

    9 Jul 09 at 10:38 pm

  6. Wow, thanks.

    Moving the temp directory from being even with the folder containing the php to beneath it helped out. I now see the text after I load the text, and the text file is in the temp folder, but the image is still having trouble. It now displays this:

    phpfileread

    Moe

    9 Jul 09 at 10:58 pm

  7. You need to call the URL not a file reference, change it to http://localhost/lob/webcode/UploadItemBlobForm.htm and it should work. When you attempt to open a PHP file with:

    phpfileurl

    It should output what you got. The reason is that the URL (URI) is passed by the Apache server to the Zend Server, which then interprets the PHP. That can’t happen if you attempt to open it as a local file. Also, the code is written to use a POST method. That means you should call the form, which then calls the PHP code through a POST method operation, like:

    <form id="uploadForm"
          action="UploadItemBlob.php"
          enctype="multipart/form-data"
          method="post">

    This should fix the problem. Let’s hope. :-)

    maclochlainn

    9 Jul 09 at 11:08 pm

  8. SWEEEEET!!!!

    It is working!!!

    Thanks!

    Moe

    9 Jul 09 at 11:16 pm

  9. I’ve updated the code to PHP 5.3 and added all components in drop down text. The zip files aren’t yet updated but when I fix them, I’ll update this comment.

    maclochlainn

    27 Feb 10 at 1:56 pm

Leave a Reply