The fact that you're dealing with an Oracle database is really neither here nor there, except that you'll probably be storing the data in a column on type BLOB. This can be handled pretty much transparently with DBI.

When you talk of "uploading", I assume you mean a web form. If the site in question is inside a corporate LAN, the most efficient use of programmer time (what efficiency were we talking about again?) will be to use CGI to handle the decoding of the POST or GET data correctly.

You also want to prepare the SQL insert statement and use placeholders: if the query is hit with any regularity the optimiser will pull the previous query plan out of the library cache. This probably won't change the program efficiency one whit (because network latency is going to be your biggest problem by an order of magnitude), but it's a good habit to get into, and will serve you well in the future.

When all is said and done, you can probably do this in about 10 lines of simple code in Perl. If you have any particular questions on how to put it all together, don't hesitate to ask, if you get stuck on a some aspect of the problem.

Hell, given a page with a file upload input widget named 'upload', it would probably look something like (warning: untested code ahead):

use strict; use warnings; use CGI; use DBI; my $q = CGI->new; my $db = DBI->connect( ... ); # see DBD::Oracle for details END { $db and $db->disconnect }; my $insert = $db->prepare( <<END_SQL ) or die $db->errstr; insert into tabname (colname) values (?) END_SQL if (defined(my $data = $q->param('upload'))) { $insert->execute($data) or die $insert->errstr; }

By default, DBI will do commits automatically. You would be wise to turn this off, and do an explicit commit if everything goes according to plan, otherwise rollback. That is left as an exercise to the reader.

• another intruder with the mooring in the heart of the Perl


In reply to Re: File upload to Oracle database using perl by grinder
in thread File upload to Oracle database using perl by jasmine12345

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.