Updating table in dbi perl

Rated 3.92/5 based on 906 customer reviews

The do subroutine allows us to execute a simple statement without the need to explicitly initialize a statement context. For example: When we insert rows into the DRIVER table we no longer need to specify a key as this will be generated by the trigger.However we might wish to know the value of the internally generated key.The example table is defined as follows: INSERT INTO driver VALUES (1,'Sebastian Vettel','Red Bull',374); INSERT INTO driver VALUES (2,'Jenson Button','Mc Laren',240); INSERT INTO driver VALUES (3,'Fernando Alonso','Ferrari',227); INSERT INTO driver VALUES (4,'Mark Webber','Red Bull',221); COMMIT; The use DBI pragma instructs Perl to load the Database Interface (DBI) module.I normally use the strict pragma, but have omitted it within this post to improve clarity.When all required rows have been fetched from the cursor the statement can be closed using the finish subroutine.This script generates the following output: Both the above methods are functionally equivalent and the choice of one or the other is simply a matter of personal taste.

updating table in dbi perl-16

The examples are based on a table listing drivers in the 2011 Formula One World Championship.

Most Perl scripts seem to use $dbh for the database handle.

In this example the database SID is XE and therefore the connect string is DBI: Oracle: XE.

The above examples do not include commit or rollback calls.

This is because, by default, Perl DBI enables automatic commits. To disable automatic commits set the Auto Commit variable in the connection handle to 0.

Leave a Reply