Relating a sequence to a table

hi there
i have a table "Employee" for which I have an index column emp_no (Primary Key).
i want to write a sequence for this column, such that it starts at 1 and gets incremented by 1 everytime I insert a row in "Employee"
Any help will be great.
Mahesh.

I have to disagree with you here about the use of variables. There is nothing gained by selecting the sequence value into a variable and then assigning that variable to the :new.column_name.
Offsets? Formatting? I'm not entirely sure what you mean here since the purpose of the sequence is to give you a value - not a value in a certain range. In other words, what's the point of a sequence if you're going to turn around and change the number?
Exception handler? Recording the sequence value? Not sure why an exception factors in here, but anywhere you could use the variable you should instead just use the :new.column_name value.
Naming conventions? For what?
Using the value later in the trigger? Again, just use :new.column_name. Using a variable is totally redundant.
If there is some specific case that you feel warrants a variable, I would really like to hear about it because the reasons you mentioned here just don't necessitate the use of a variable.
I'm pushing back on this because I feel pretty strongly on this issue, but this is just a friendly discussion.

Similar Messages

  • How to CREATE SEQUENCE in one table

    dear all
    the one thing i want to know when i use CREATE SEQUENCE in one table like this and then at that table
    CREATE SEQUENCE oproduct_sequence
    START WITH 1  INCREMENT BY 1 
    nocache
    create table oproduct(
    tname varchar2(20) not null,
    tid int default  oproduct_sequence.nextval
    the system indicat that i cannot use this way to create table , so i really want to know how can i achieve this method
    becuase when i want to insert inot table oproduct only use
    insert into oproduct  valuse('aaaa');
    and the result like
    aaaaa 1
    bbbb   2

    Actual name is before insert trigger. Some examples are listed below:
    Example Number 1 ...
    create sequence product_seq start with 1 increment 1
    create or replace trigger product_insert before insert for each row begin
    select productseq.nextval
    into :new.product_id
    from dual;
    end;
    Example Number 2 ...
    How to create an autoincrement field in a table with a sequence ...
    SQLWKS> create table bob(a number , b varchar2(21));
    Statement processed.
    First create a sequence
    SQLWKS> create sequence x ;
    Statement processed.
    Then create the trigger.
    create trigger y before insert on bob
    for each row
    when (new.a is null)
    begin
    select x.nextval into :new.a from dual;
    end;
    Example Number 3 ...
    First create a sequence:
    create sequence emp_no_seq;By default it increments by 1 starting at 0.
    Use its values when inserting data into the table:
    insert into t_emp values (emp_no_seq.nexval, 'Joe Black');~ Madrid.

  • Count Records in Table Except If Related Record Exists in Child Table

    Dear All
    I have the following query that counts all of the records in the table SENAlert based upon the teacher's username in a related table.
    SELECT COUNT(SENAlert.SENAlertID) AS Expr1
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    WHERE (Teacher.TeacherUsername = 'dsmith')
    I need to extend this query by adding another table called SENAlertHistory. I would like to count the number of alerts (SENAlertID) for the specified teacher
    but where there is no related record in the SENAlertHistory table. Here's what the relationship diagram looks like:
    What's going to happen is when a teacher clicks a button to say they have read an alert, I will record this in the SENAlertHistory table. Therefore when performing a count of how many unread alerts the teacher has, I need to ignore the alerts they have
    already read (i.e. the records in the SENAlertHistory table).
    This is a bit too advanced for me -- I have tried! I was hoping someone would be able to help me please?
    Many thanks
    Daniel

    Try below code
    -- If you dont need the read alert count
    SELECT COUNT(SENAlert.SENAlertID) AS Expr1
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    WHERE (Teacher.TeacherUsername = 'dsmith')
    AND NOT EXISTS
    (SELECT * FROM SenAlertHistory SAH WHERE Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID )
    -- If you need the read alert count
    SELECT COUNT(SENAlert.SENAlertID) - COUNT(SAH.SEMAlertHistorySENAlertID) AS Expr1,COUNT(SAH.SEMAlertHistorySENAlertID)readalert
    FROM Class INNER JOIN ClassMember ON Class.ClassClassCode = ClassMember.ClassMemberClassCode
    INNER JOIN Student ON ClassMember.ClassMemberStudentID = Student.StudentID
    INNER JOIN SENAlert ON Student.StudentID = SENAlert.SENAlertStudentID
    INNER JOIN Teacher ON Class.ClassTeacherCode = Teacher.TeacherCode
    LEFT OUTER JOIN SenAlertHistory SAH ON Teacher.TeacherCode = SAH.SenAlertHistoryTeacherCode and SENAlert.SENAlertID = SAH.SEMAlertHistorySENAlertID
    WHERE (Teacher.TeacherUsername = 'dsmith')
    Thanks
    Saravana Kumar C

  • Relation between different GUID and tables in RPM

    Hi All,
    can you tell me the relation between different GUID and tables in RPM. Many thanks.
    Regards,
    J B

    Hi Deepesh,
    Try the foll. join :
        SELECT  fragment_guid  INTO  (some internal Table)
             FROM  comm_pr_frg_rod
             WHERE  product_guid  = (your product guid list)
    This should give u a complete match of the products.
    Hope this helps.
    Regards,
    Raviraj

  • Delivey related info rqrd from one table

    Hi,
    Can I got the following SCM related information from one standard table. plz reply ASAP.
    1. Outbound Delivery Number.
    2. Invoice Number of O/D.
    3. Invoice Value
    4. Invoice Qty. (Base Unit)
    T & R
    Sanjay

    Hi
    I think that you have had your question answered so if you are happy with this can you please award points if you want to but mainly can you please mark your question as answered so that it is easier to navigate around the open questions in the forum as the number of pages are growing and growing and it takes too long to go through everything especially if a satisfactory answer has already been given and people like me who want to help will give up and so some people may not get any help.
    Thanks for this
    Frenchy.

  • Multiple sequences on one table?

    I have a simple table with 3 columns: ID, DML_ID and VALUE. The table was designed to be a metadata table with values for certain DML_IDs. The table has been maintained by IT. However, now the users wants to have control over some of the values. Let's call it User_Maintained values. IT does DML on this table and migrate the change to acceptance and production. At the same time users do DML in production. This causes ID conflict between dev, acc and prod.
    My solution is to use 2 sequences, one for IT_maintained IDs the other for User_maintained IDs. One of the sequences starts with a much bigger number like 1000000 to avoid the conflict. Create a before insert trigger on the table to pick the right sequence number depends on if the DML is IT or user maintained.
    My question here is, is it ok to use 2 sequences on one table? Is it against best practice of Oracle?
    Another idea from my co-worker is, use single sequence instead of 2. The sequence will reside in production database and all the 3 databases (dev, acc and prod) will get ID from the same sequence through dblink. Personally I don't like the idea because I don't think getting sequence from production to be used in development is the "best pratice" of Oracle. Although I don't know where I can find the document to support my opinion.
    Any idea is appreciated!!
    Sharon

    I've discussed with the DBAs and some developers, we all have concern about the idea of one sequence on production being used by all 3 databases (dev, acc and prod). Database clone is one issue. Also making one database (dev or acc) relies on another (production) is not a good approach. Each database should be as independent as possible - only create the linkage when it's necessary. In this case I don't think it's necessary.
    I will go with one sequence for user maintained values (in prod), and a manual increase number (max(id) of IT maintained value plus 1) for IT list.
    I do all these because the table was a bad design from the first begining so I can't really come up with a correct solution to work around this.
    Thanks for everybody who gave input here. Very appreciated!

  • How to find the sequence for a table.

    Hi Everyone,
    I've got plenty of sequences. How can I identify that what are the sequences acting on a table?
    Regards,
    BS2012.

    Greg.Spall wrote:
    In my last job, we used the table/column comments to point to the sequence.
    so:
    CREATE SEQUENCE seq_test1;
    CREATE TABLE my_table
    (id   number);
    COMMENT ON TABLE my_table IS 'Test table for demonstration purposes on OTN';
    COMMENT ON COLUMN my_table.id IS 'Primary Key, sequence populated: seq_test1';... or something like that :P
    But yeah, outside of that, good luck if you have no documentation!Of course, ALL of the 'code search' solutions put forth are assuming the references will be found in PL/SQL packages. That ignores the potential that the code could be located somewhere else, like application code that exists OUTSIDE of the database .... Bottom line is that there is no 100% one-size-fits-all method for automating the discovery of relationships between tables and sequences.

  • Relation between BSEG with Asset Tables

    HI Guru's,
    how to find relation between BSEG with Asset Tables like ANLA and ANEP..
    regards
    JK

    Foreign keys
    - ANEP items are linked to ANLA via fields in common ANLN1 and ANLN2
    - ANEK header is linked to ANEP items via fields in common ANLN1, ANLN2, GJAHR and LNRAN
    - BKPF and BSEG are linked to ANEL ANEP via BUKRS, BELNR and GJAHR
    Optimization (as BSEG is behind a cluster table RFBLG)
    - Append BSIS (ZABSIS) and BSAS with ANLN1 and ANLN2, then create an index with these fields. As BSIS is filled via MOVE-CORRESPONDING statement, only a one-shot report to initially fill the new fields is to be developed. (look at old OSS [Note 62435 - F-03: Selection by purchasing documents|https://service.sap.com/sap/support/notes/62435] for optimization via purchase order)
    Regards

  • Sequencing in Planning Table

    Hi Gurus,
    Can any one throw light on Sequencing in Planning Table (MF50)?
    Where do we use this?
    What are pre requistites?
    How is useful?
    As anyone made a scenario on this.
    Please reply.
    Srini

    Dear Srini,
    Can any one throw light on Sequencing in Planning Table (MF50)?
    Where do we use this?
    What are pre requistites?
    How is useful?
    1) MF50 is Mostly  used in REM process
    2) say for example you have two PV's for one material in REM
    3) Demand given for this material is 100 Nos
    4)  after running MRP, system will pick one PV for 100 Nos
    5) Now, we can go in MF50, & we can split the qty 100 Nos between two PV's
    PV 1 - 50 Nos
    PV 2 - 50 Nos
    6) Now you can see in MD04, for this material will be splitted ( I.e two plan orders with 50 Each Nos )
    7 ) on the whole, MF50 is used to Split Demand Quantities between PV's
    Your old & good Forum member
    so suggest you to close all your previous threads
    Plz don't misundersatnd
    Regards
    Madhu Kumar

  • Relation between Eban and Erev tables

    Hi,
       What is the Relation between Eban and Erev tables?
    Thanks and Regards,
    Parvatha Reddy

    Hi,
    if you have activated version management for purchase requisitions (spro - mm - purchasing - version mgmt - set up ver mgmt for PR), then if any changes are made to the fields as specified in the customizing, then an entry is made in EREV table. EBAN is the pur. reqn table.
    Hope it answers your query.
    Regards,
    Vivek

  • Relation between BKPF and EKBE table for reversing document?

    Is there any relation between BKPF and EKBE table for reversing document when STBLG is blank in BKPF.
    AND
    How to differentiate Old Accounting document / Reverse document / New document when in BKPF-STBLG is blank for all three document and BKPF-XBLNR are same for all.

    Hi Varun,
    Table Document no (BKPF-BELNR) is link between Material document no (EKBE-BELNR). If you are looking for validating Material reversal document then please use following logic for your requirement.
    Material Document (MBLNR) & Material Document Year (MJAHR). Pass material document (MBLNR) to MSEG-SMBLN to read MSEG-MBLNR with MSEG-MJAHR to MSEG-SJAHR, if record found delete both the documents i.e. MSEG-SMBLN & MSEG-MBLNR (donu2019t consider these documents in the logic) and display Material Document No. (MSEG-MBLNR)
    Regards,
    Santosh

  • Relation between vbuk and vbup tables?

    relation between vbuk and vbup tables?
    regards phani

    Dear Phani,
    http://help.sap.com/saphelp_erp2005/helpdata/en/70/a7853478616434e10000009b38f83b/frameset.htm
    VBUK .... Sales Document: Header Status and Administrative Data
    VBUP ....Sales Document: Item Status
    VBUK contains header status where as VBUP contains individual item status of the header. Similar to VBAK and ABAP where VBAK contains Sales Document header data and VBAP contains Sales document item data.
    Hope this will help.
    Regards,
    Naveen.

  • Help-how can i see the sequence in the table?

    Hi, i created sequence for the table. but how can i view the sequence as a column in the table? like the sequence started with 1 and increment by 1. how can i make it available as a column in the table? thanks a lot for anyone's prompt reply. much appreciated.

    eg.
    Create table:
    create table t1 (
    id number(10),
    col1 varchar(2)
    Create sequence:
    CREATE SEQUENCE "PEMARTEN"."T1_ID" NOCYCLE NOORDER CACHE 20 NOMAXVALUE MINVALUE 1 INCREMENT BY 1 START WITH 1
    You can do 2 things:
    Use the sequence in your insert query:
    eg.
    insert into t1 (id, col1) values (t1_id.nextval, 'example');
    OR
    Create a before insert trigger (prefered):
    CREATE OR REPLACE TRIGGER "PEMARTEN"."BI_T1" BEFORE INSERT ON "PEMARTEN"."T1"
    REFERENCING OLD AS OLD NEW AS NEW
    FOR EACH ROW
    DECLARE
    new_id number;
    BEGIN
    SELECT t1_id.nextval
    INTO new_id
    FROM dual;
    :new.id := new_id;
    END;
    Now you can just insert data:
    insert into t1 (col1) values ('example');
    sequence.nextval increments the sequence and returns the next value
    sequence.currval returns the current value of a sequence
    I hope that helps.
    Kind regards,
    Pieter

  • Relation between RESB and AUFM tables

    can any one tell me how to build the relation between the above two tables
    first i am getting the data from resb
    now i need to get the data from  aufm
    but there are no common key fields
    while selecting the data from aufm i want to put the where conditon on key fields only

    hi
    good
    use this process to know the details.
    Go to SQVI transaction... Create a qucik view.. ztest.. give desc..etc
    Select data source as table join.... enter
    now one screen will come with blank data (blue scrren)
    in that application toolbar second button .. click that.. enter VBAK..
    click that again.. enter VBAP.. now an image will come with links b/w vbak and vbap.. you can use any no. of tables there....
    thanks
    mrutyun^

  • Error while relating sequence to a table

    thanks for a quick reply.
    i incorporated the suggestions that i got from here and i am getting the following error while i am trying to create a trigger:
    ERROR at line 1:
    ORA-04089: cannot create triggers on objects owned by SYS
    It is pretty self-explanatory but I dont know why I am getting this error. I am connected as sys/change_on_install as SYSDBA
    Help please!!
    Mahesh

    Mahesh,
    Hehehe well I had a little chuckle here after reading that. Don't create objects as SYS, that be a bad thing, unless your an elite hax0r.
    First make a new user and create that table and trigger and sequence under this new user. The create user syntax is below. It is wise to make a user also that has DBA privs, so you don't need to be connecting as SYS (The syntax below makes a DBA user). This is very helpful if your forget your SYS password (which you really should be changing).
    Note that you will have to specify the new user name, password, and in particular the TABLESPACE this new user will be making objects in. I put USR as it, but check to see if you have this tablespace or find one to make objects in, because right now your makeing tables in the SYSTEM table space which is a baaad thing.
    DROP USER "U_TYLER";
    CREATE USER "U_TYLER" IDENTIFIED BY "MY_PASSWORD_HERE"
    DEFAULT TABLESPACE "USR"
    TEMPORARY TABLESPACE "TEMP"
    PROFILE DEFAULT ACCOUNT UNLOCK;
    GRANT "CONNECT" TO "U_TYLER";
    GRANT "RESOURCE" TO "U_TYLER";
    GRANT "DBA" TO "U_TYLER";
    ALTER USER "STB" DEFAULT ROLE ALL;
    GRANT CREATE SYNONYM TO U_TYLER;
    GRANT DROP PUBLIC SYNONYM TO U_TYLER;
    GRANT CREATE PUBLIC SYNONYM TO U_TYLER;
    Reply back if your still having some troubles, cause we love to help people worldwide :).
    Tyler

Maybe you are looking for

  • Can't open CR2 files in photoshop and camera raw

    This weekend I rented a Canon 5D Mark iii. I have downloaded the files and all of the thumbnails in camera raw say CR2 and when I try to open Photoshop does not recognize this product. I have: Photoshop CS4 Camera Raw CS4 Canon 5D Mark ii I have chec

  • No error messages in php

    Hi! I have an old computer witch I have installed apache, php and mysql. Every thing is working except from one thing (so far). I have tested that php works, but my problem is that I don't get any error messages back from the server if there is an er

  • IPv4 Gateway Issue? - HP LaserJet 400 M401dn / 400 MFP M425dn

    Hello, I work in healthcare and in our environment we have mostly HP LaserJet printers. Within the last 6 - 12 months we have started using some HP LaserJet 400 M401dn and HP LaserJet 400 MFP M425dn printers. They all have been updated with the lates

  • How to create purchase order and sales orders

    Hi guys, i want to create sales order in IDES and i need to create purchase order ECC. depending on that i want to create the idoc for that and i want to send info through xi to the other sys. will u plz any of u can help me in this query. Thanks & R

  • Horizontal menu with horizontal sub menu using image rollovers or similar

    Hello, I am brand new to web design and working on my first site.  What I lack in skills, I have in free time to learn right now : ) Please let me know if there is a tutorial or other resource that describes what I am trying to do...I've been searchi