I assume since you are using SEQUENCE.NEXTVAL, that this is an Oracle environment, so maybe this will help a bit. (Please note, this is not "good" code, but it was quick. *Smiles*)

use strict; use dbi; use dbd::oracle; #-- Define constants use constant TRUE => 1; use constant FALSE => 0; use constant ORA_USER => 'myschema'; use constant ORA_PASS => 'sesame'; use constant ORA_TNS => 'tst00'; use constant ERR_OK => 0; #-- Define variables my $mDBHandle; my $mSQLInsertHandle; my $mSQLSelectHandle; my $mSQLInsert = <<'EOSQL'; INSERT INTO test (val, name) VALUES (test_seq.nextval,?) EOSQL my $mSQLSelect = <<'EOSQL'; SELECT val, name FROM test EOSQL my @mTuple; #-- Connect to the database $mDBHandle = DBI->connect ( 'dbi:Oracle:' . ORA_TNS, ORA_USER, ORA_PASS, { AutoCommit => FALSE, PrintError => FALSE, RaiseError => FALSE, } ) || die $DBI::errstr.' - '.$DBI::err; #-- Prepare the SQL statements $mSQLInsertHandle = $mDBHandle->prepare($mSQLInsert) || die $DBI::errs +tr.' - '.$DBI::err; $mSQLSelectHandle = $mDBHandle->prepare($mSQLSelect) || die $DBI::errs +tr.' - '.$DBI::err; #-- Display records $mSQLSelectHandle->execute() || die $DBI::errstr.' - '.$DBI::err; print "Val\tName\n"; print "---\t----\n"; while (@mTuple = $mSQLSelectHandle->fetchrow_array) { print $mTuple[0],"\t",$mTuple[1],"\n"; } print "\n\n"; #-- Execute the SQL insert statements $mSQLInsertHandle->execute('test1') || die $DBI::errstr.' - '.$DBI::er +r; $mSQLInsertHandle->execute('test2') || die $DBI::errstr.' - '.$DBI::er +r; #-- Commit the inserts $mDBHandle->commit(); #-- Display records $mSQLSelectHandle->execute() || die $DBI::errstr.' - '.$DBI::err; print "Val\tName\n"; print "---\t----\n"; while (@mTuple = $mSQLSelectHandle->fetchrow_array) { print $mTuple[0],"\t",$mTuple[1],"\n"; } print "\n\n"; #-- Disconnect from the database $mDBHandle->disconnect(); #-- Exit exit(ERR_OK); #-- End of Script

In reply to Simple demo... by Rhose
in thread using sequences with dbi by idunno

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.