Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Simple demo...

by Rhose (Priest)
on Oct 03, 2001 at 18:50 UTC ( #116467=note: print w/replies, xml ) Need Help??

in reply to using sequences with dbi

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://116467]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2019-08-21 09:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found