Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > Oracle
|
Oracle General Oracle database discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Oracle section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2004, 10:13 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default auto increment primary key-compile error

I have table BILL and ITEM

CREATE TABLE bill (
in_inv NUMBER PRIMARY KEY,
bill VARCHAR2 (512),
ship VARCHAR2 (512),
invdate DATE,
invno VARCHAR2 (12),
po VARCHAR2 (12),
dn VARCHAR2 (15),
cur VARCHAR2 (15),
pri VARCHAR2 (35),
term VARCHAR2 (30) );

CREATE TABLE item (
in_line NUMBER PRIMARY KEY,
line NUMBER,
invno VARCHAR2 (12),
po1 VARCHAR2 (10),
stock1 VARCHAR2 (2000),
qty1 NUMBER (10),
uom1 VARCHAR2 (5),
pri1 VARCHAR2 (10),
amo1 VARCHAR2 (10),
total VARCHAR2 (10) );

I want in_inv (table BILL)and in_line (table ITEM) can generate AUTO INCREMENT value.

I have try this but get compile error msg.

CREATE TABLE bill
(in_inv NUMBER PRIMARY KEY,
bill VARCHAR2 (512),
ship VARCHAR2 (512),
invdate DATE,
invno VARCHAR2 (12),
po VARCHAR2 (12),
dn VARCHAR2 (15),
cur VARCHAR2 (15),
pri VARCHAR2 (35),
term VARCHAR2 (30) );

CREATE SEQUENCE bill_seq
START WITH 1
INCREMENT BY 1
CACHE 1000;

CREATE OR REPLACE TRIGGER bill_preinsert
BEFORE INSERT ON bill
FOR EACH ROW
BEGIN
SELECT bill_seq.nextval
INTO :new in_inv
FROM dual;
END;


CREATE TABLE item
(in_line NUMBER PRIMARY KEY,
line NUMBER,
invno VARCHAR2 (12),
po1 VARCHAR2 (10),
stock1 VARCHAR2 (2000),
qty1 NUMBER (10),
uom1 VARCHAR2 (5),
pri1 VARCHAR2 (10),
amo1 VARCHAR2 (10),
total VARCHAR2 (10) );

CREATE SEQUENCE item_seq
START WITH 1
INCREMENT BY 1
CACHE 1000;

CREATE OR REPLACE TRIGGER item_preinsert
BEFORE INSERT ON item
FOR EACH ROW
BEGIN
SELECT item_seq.nextval
INTO :new in_line
FROM dual;
END;

Thanks in advance

 
Old June 16th, 2004, 08:46 AM
Authorized User
 
Join Date: May 2004
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you tell us the error message your getting

 
Old June 16th, 2004, 08:53 AM
Authorized User
 
Join Date: Apr 2004
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It appears that there is a missing period between the :new and the column name in both triggers.

Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC





Similar Threads
Thread Thread Starter Forum Replies Last Post
auto increment primary key jcuga SQL Language 2 June 3rd, 2007 09:04 AM
Increment a primary key bvpsekhar MySQL 7 May 9th, 2007 07:09 AM
SQL query to find key when auto-increment SandyFeder SQL Server ASP 1 November 21st, 2005 10:49 AM
How to auto increment primary key method SQL Server 2000 5 May 24th, 2005 03:25 PM
auto gerate of primary key Abhinav_jain_mca SQL Server 2000 15 October 1st, 2004 05:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.