SunQuest
           Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 8th, 2004, 09:13 AM
claire@@ claire@@ is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 15 claire@@ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question auto incremntal id's

The following is my cgi in Perl.
As you may see I am trying to insert the customer id automatically by selcting the last max id and +1... But i dont have a clue exactly how to do this.
Can anyone please have a look at what I have done so far and point out where Ive gone wrong. Every time i try to send this error message is either 'invalid number' or primary key violation.

Many thanks

Claire.



$ENV{"ORACLE_HOME"} = "/home/oracle/product/9.2.0";
print "Content-type: text/html\n\n";
my $dbh = DBI-> connect('dbi:Oracle:host=info200.infc.ulst.ac.uk;sid=ORCL;port=1521',
'watters', 'P32208403')
or die "Couldn't connect to database: " . DBI->errstr;
my $customername=param('winecustomer');
my $address1=param('address1');
my $city=param('city');
my $postcode=param('postcode');
my $country=param('country');
my $telno=param('telno');
my $email=param('email');
my $cardno=param('cardno');
my $cardtype=param('cardtype');
my $expirydate=param('expirydate');
my $chname=param('chname');
my $wine=param('wine');
my $quantity=param('quantity');
my $customerid=('select max(customerid)+1 from winecustomer');




my $sth2=$dbh->prepare('insert into winecustomer
(customerid) values(max(customerid) + 1)
');

$sth2->execute($customerid);
my $sql =qq{insert into winecustomer (customerid, customername,address1, postcode, country,telno, email, city) values(?,?,?,?,?,?,?,?)};

my $sth=$dbh->prepare($sql);

$sth->execute($customerid, $customername, $address1, $postcode, $country, $telno, $email, $city) or die $DBI::errstr;



print "Thankyou , your details have been recieved\n\n";
$dbh->disconnect;

Reply With Quote
  #2  
Old April 11th, 2004, 12:09 AM
galith_haham galith_haham is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 64 galith_haham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 25 m 17 sec
Reputation Power: 5
Hi,

I think you are better of using sequence. that way you let the database decide on the next value ...


Galit.

Reply With Quote
  #3  
Old April 11th, 2004, 06:22 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,343 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 5 m 22 sec
Reputation Power: 891
definitely use a sequence

select max(id) will fail unless there is only ever at most one (1) user, or else you use transaction locks
__________________
r937.com | rudy.ca

Reply With Quote
  #4  
Old April 13th, 2004, 12:26 AM
galith_haham galith_haham is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 64 galith_haham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 25 m 17 sec
Reputation Power: 5
Hi,

than use the sequence

select XXX.nextval/currval into BBB from dual.

if you choose the nextval it will assign a number and no one but the transaction which issued that statment will be given that value.

Galit.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > auto incremntal id's


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway