Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Roboticus, Finally I got it working. there were quite a few issues apart from the cleanliness:

- First, The chomp part that you said not working here although it was essential. Please find my discussion on below threads: http://stackoverflow.com/questions/11645696/perls-chomp-chomp-is-removing-the-whole-word-instead-of-the-newline Chomp is removing the whole word instead of the newline

- I had this chomping problem way before I created this thread. I have documented solution on the stackoverflow one. will post my solution on perlmonks as well

- Second, for whatever reason, I had to unassign "primary Key" column by logging to the SQL developer. Although my entries were not duplicates...still..I had to do it

- Third, I was uploading the values in a wrong way. The DBI documentation led to use the "$dbh->quote" method to upload strings.

- Finally, I used Text::CSV to retrieve individual values of my CSV and then uploaded them using the "$dbh->quote".

Here is the csv:

vm,farm,dmz name1,farm1,z1 name2,farm2,z2 name3,farm3,z3

and here is my code:

#!/usr/bin/perl -w use strict; use Text::CSV; use DBI; my $csv = Text::CSV->new ( { binary => 1 } ) or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", "test.csv" or die " $!"; <$fh>; ### this is to remove the column headers. my $dbh = DBI->connect ("dbi:Oracle:host=<hostname>;sid=<SID>;port=152 +6", 'username', 'password', { RaiseError => 1, AutoCommit => 1, TraceLevel + => 0 }) or die "Cannot create Database Handle: $DBI::e +rrstr()"; while ( my $row = $csv->getline ($fh)) { my $col1 = $dbh->quote ("$row->[0]"); my $col2 = $dbh->quote ("$row->[1]"); my $col3 = $dbh->quote ("$row->[2]"); $dbh->do ("INSERT INTO CLUSTER_MAPPING (VM, FARM, DMZ) VALUES +($col1, $col2, $col3)"); } $dbh->disconnect(); close $fh;

Thank you very much for your advice and time.


In reply to Re^2: DBD::ORacle: Not able to insert into Database by slayedbylucifer
in thread DBD::ORacle: Not able to insert into Database by slayedbylucifer

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (3)
    As of 2018-11-15 04:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My code is most likely broken because:
















      Results (180 votes). Check out past polls.

      Notices?