Sequence table ??

View: New views
3 Messages — Rating Filter:   Alert me  

Sequence table ??

by omoz4real :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All



please does anyone know why I have to create a sequence table in a database before values can be added inserted from a web/enterprise application into another table in the database. If i try to insert data from the web application through a command button without the sequence table it gives me an error such as CustomerManagement.sequence dosent exist where customermanagement is the table name.



Thanks in advance





Re: Sequence table ??

by Martin Stoufer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you are using Oracle. Just make a Sequence object and a Trigger
object that fires on insert to your main table. In the trigger it gets
the next value of the sequence and uses that to insert into the table.

create or replace TRIGGER
"YOURSCHEMA"."YOURTABLE_YOURTABLEID_TRG" BEFORE INSERT OR UPDATE ON
YOURTABLE
FOR EACH ROW
DECLARE
v_newVal NUMBER(12) := 0;
v_incval NUMBER(12) := 0;
BEGIN
  IF INSERTING AND :new.YourTableID IS NULL THEN
    SELECT  YourSequenceTriggerID_SEQ.NEXTVAL INTO v_newVal FROM DUAL;
    -- If this is the first time this table have been inserted into
(sequence == 1)
    IF v_newVal = 1 THEN
      --get the max indentity value from the table
      SELECT max(YourTableID) INTO v_newVal FROM YourTable;
      v_newVal := v_newVal + 1;
      --set the sequence to that value
      LOOP
           EXIT WHEN v_incval>=v_newVal;
           SELECT FYourSequenceTriggerID_SEQ.nextval INTO v_incval FROM
dual;
      END LOOP;
    END IF;
   -- assign the value from the sequence to emulate the identity column
   :new.FacilityID := v_newVal;
  END IF;
END;


smime.p7s (5K) Download Attachment

Re: Sequence table ??

by JULIAN ENRIQUE OSORIO AMAYA :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It depends on the DBMS you are using
Oracle and PostgreSQL use sequences to insert data in tables

2009/10/21 omoz4real <omoz4real@...>
Hi All



please does anyone know why I have to create a sequence table in a database before values can be added inserted from a web/enterprise application into another table in the database. If i try to insert data from the web application through a command button without the sequence table it gives me an error such as CustomerManagement.sequence dosent exist where customermanagement is the table name.



Thanks in advance







--
Julian Osorio Amaya
IngenierĂ­a de Sistemas.