Sequence.Next_Val as PKJ without trigger

Hi all,
How can I use SEQUENCE.NEXT_VAL to fill a PK, without use trigger?
Tks.

I'd like simulate exactly as "Identity", without use trigger and use without use seq.next_val. I'd like by default when I insert I get the seq.next_val.Here is one sample without using any trigger and also not referencing the sequence in your insert statement ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE    10.2.0.3.0      Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.01
satyaki>
satyaki>drop sequence ss;
Sequence dropped.
Elapsed: 00:00:00.07
satyaki>
satyaki>create sequence ss
  2  start with 1
  3  increment by 1;
Sequence created.
Elapsed: 00:00:00.01
satyaki>
satyaki>create or replace type s_dumm as object
  2    (
  3      n_o     number(10),
  4      d_s_c   varchar2(50),
  5      CONSTRUCTOR function s_dumm(d_s varchar2) return self as result
  6    );
  7  /
Type created.
Elapsed: 00:00:00.43
satyaki>
satyaki>create or replace type body s_dumm
  2   is
  3     CONSTRUCTOR function s_dumm(d_s varchar2)
  4     return self as result
  5     is
  6     begin
  7       select ss.nextval
  8       into n_o
  9       from dual;
10       d_s_c := d_s;
11       return;
12     end;
13   end;
14  /
Type body created.
Elapsed: 00:00:00.44
satyaki>
satyaki>
satyaki> create table test_type of s_dumm;
Table created.
Elapsed: 00:00:00.15
satyaki>
satyaki>
satyaki>select * from test_type;
no rows selected
Elapsed: 00:00:00.05
satyaki>
satyaki>
satyaki>insert into test_type values(s_dumm('First Test.'));
1 row created.
Elapsed: 00:00:00.44
satyaki>
satyaki>select * from test_type;
       N_O D_S_C
         1 First Test.
Elapsed: 00:00:00.06
satyaki>
satyaki>
satyaki>insert into test_type values(s_dumm('Second Test.'));
1 row created.
Elapsed: 00:00:00.06
satyaki>
satyaki>select * from test_type;
       N_O D_S_C
         1 First Test.
         2 Second Test.
Elapsed: 00:00:00.10
satyaki>Regards.
Satyaki De.

Similar Messages

  • Importing table without trigger

    Hi
    Whenever i import table on a dummy user,trigger is imported on the live user.
    Oracle version is Oracle 8i,OS is windows 2003 server.
    For eg. If i m importing table in rahul user which is dummy user,table is imported in rahul user but trigger is imported on smat user which is our live user.
    So can i import table without trigger or trigger should be imported on dummy user.
    Can any1 help
    Thanks in advance.
    rahul

    Check the trigger ownership or ownership of the table related to th triggers

  • Problem inserting auto-sequence for PK value using trigger - ORA-02287

    I have a query where the sub-query is working. I created a table to receive the results of the query. I created a Sequence:
    CREATE SEQUENCE SEQ_RPT_H2_LOOPS
    MINVALUE 1
    START WITH 1
    INCREMENT BY 1
    NOMAXVALUE;
    Then I created a trigger:
    CREATE OR REPLACE TRIGGER TRG_RPT_H2_LOOPS
    BEFORE INSERT ON RPT_H2_LOOPS
    FOR EACH ROW
    BEGIN
    SELECT SEQ_RPT_H2_LOOPS.NEXTVAL INTO :NEW.RECORD_ID FROM DUAL;
    END;
    And here is the Insert query.
    accept month_year;
    accept prior_month_year;
    insert into rpt_h2_loops (
         RECORD_ID,
         MKT_CODE,
         MKT_NAME,
         ECCKT,
         VENDOR_ID,
         ECCKT_VENDOR_ID,
         OCN,
         FAC_TYP,
         ALOC,
         ZLOC,
         STATE,
         OCN_STATE,
         OCN_STATE_COLO,
         SRVC_TYP,
         CUR_PERIOD,
         PRIOR_PERIOD,
         TIME_STAMP )
    select seq_rpt_h2_loops.nextval
    ,substr(r.sub_acct,4,3)
    ,m.market
    ,rr.ckt
    ,rr.vendor_id
    ,rr.ckt||rr.vendor_id
    ,rr.ocn
    ,rr.srvc_typ
    ,'N/A'
    ,rr.zloc
    ,rr.st_cd
    ,rr.ocn||rr.st_cd
    ,rr.ocn||rr.st_cd||rr.zloc
    ,rr.srvc_typ
    ,'&month_year'
    ,'&prior_month_year'
    ,sysdate
    from rco.rate_route rr
    ,rco.cogs_resource r
    ,rco.cogs_mkt m
    where rr.cvbi_key = r.cvbi_key
    and     m.subacct = r.sub_acct
    and     to_char(rr.period, 'mm/yyyy') = '&month_year'
    and     to_char(r.period, 'mm/yyyy') = '&month_year'
    and     rr.srvc_typ = 'CUNE'
    group by    substr(r.sub_acct,4,3)
    ,m.market
    ,rr.ckt
    ,rr.vendor_id
    ,rr.ckt||rr.vendor_id
    ,rr.ocn
    ,rr.srvc_typ
    ,rr.zloc
    ,rr.st_cd
    ,rr.ocn||rr.st_cd
    ,rr.ocn||rr.st_cd||rr.zloc
    );The problem is that I am getting a ORA-02287: sequence number not allowed here on the NEXTVAL keyword.
    The sequence and trigger compiled without problem. I just can't seem to insert that value into the query. Any help would be appreciated.

    you are defeating the purpose of trigger which is before insert so just rewrite the query and remove the column for which value will be inserted using the created sequence and your code will work.
    Regards,
    Vikas Kumar

  • How to export a sequence as an AAF without media and then relink in Avid

    Just in case it helps anyone else sharing material Avid ←→ PPro....
    If I export a sequence as an AAF then it expects me to want to include the media, whereas I don't want to duplicate media.
    If I put the AAF in a bin - with a piece of media (I used black) - then it will export just the AAF without media.
    Importing this to Avid results in Media Offline - and I could not get normal relinking to find the media (is it possible?).
    However using this as a guide I found that I could get the media to relink, having imported the AAF to Avid (and ignored the warnings):
    1. AMA link to all the media that is in your Pr sequence in a fresh Avid bin (you'll need to know where that media is)
    2. Select all the clips in that bin
    3. Go to the offline sequence, right click and select relink
    4a. Select radio button that says 'Relink selected items to selected items in all open bins'
    4b. Under 'relink by' select 'start' and 'name', check 'ignore extension'
    It does require that you haven't renamed any of the clips in your premiere project - that the clip names match the file names.
    (In FCP7 there was an option to rename clips to match files OR rename files to match clips.)

    There is one drawback to the Copy/New from Clipboard method. It does not pick up all the elements of the chart. It doesn't give you the axis titles, legend, or chart name.
    I do this:
    1) Print using the Open PDF in Preview setting
    2) In Preview, select the chart and whatever surrounding area you want to have with it.
    3) Copy
    4) New from Clipboard
    5) Save in the desired format.
    You can often skip steps 4&5 and paste directly into another document if that is where it is headed.

  • Can I use 4k footage in a 1080p sequence, then export 4k without resolution loss?

    Hi,
    I cut a 1080p sequence using 4k footage that I scaled down in the Effect Controls window. If I export that sequence as a 4k file, will Premiere compress that original 4k footage to 1080p, then expand it back to 4k in the exported file (please say no)? Or is Premiere intelligent enough to interpret the export scaling using the size of original footage, rather than the sequence size? (Hope that makes sense)
    Of course it's wise to create a sequence based on your delivery requirements, but sometimes clients change their mind and I don't feel like rescaling every damn clip. But thanks for the advice
    Thanks!
    David

    Premiere will export to the settings of the timeline / sequence you've created.  It doesn't matter what formats you've used withing that timeline.  So if you use 4k in a 2k sequence, Premiere sees it as a 2k sequence and, without user intervention, will export at that format.
    Obviously you can up-scale during export but i) why would you want to do that when you've previously down-scaled and ii) anything above 100% magnification will begin to pixelate.

  • Can we restart the sequence at any moment without  define max val

    Hi all
    can we restart the sequence without define the max value
    i am creating batch for month and in every month i never know how much batches i have i want when the month change then batch restart
    thanks and regards
    vikas singhal

    Hi,
    Refer to : http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1119633817597
    http://www.jaredstill.com/content/reset-sequence.html
    - Pavan Kumar N

  • What is the alternate to this? without trigger & insrt...value(seq.nextval)

    create sequence myv ;
    drop table t33;
    create table t33
    (c1 number default myv.nextval);

    Perhaps this, though the downside is it's rather more bulky than a generated number, and less human-readable:
    SQL> create table t33
      2  (c1 raw(16) default sys_guid(), c2 varchar2(30));
    Table created.
    SQL> insert into t33 (c2) values ('Banana');
    1 row created.
    SQL> select * from t33;
    C1                               C2
    2571E04E2E3F59BFE040007F01001E0C Banana
    1 row selected.

  • Derived column without trigger

    Hello eveyone,
    I was wondering if anyone can tell me if it is possible to have a computed column on a Oracle Table (like in Excel formula's). Let's suppose this example:
    CREATE TABLE MYTABLE
        BIRHTDAY DATE,
        AGE          NUMBER(10,4) (= (SYSDATE-BIRHTDAY) / 365) )
    );This is an example; I know this does not make any sense. But that's the idea. I know I can have a column which can be updated through triggers (after insert/update of a given columns), or I can also create a view.
    But is there any way to create a derived column with its logica defined within the create table statement?
    Thanks for your help,
    O.

    Hi,
    If yoo are on a lower version then one option you have is a view.
    Keep your data as it is, write a view which will do the calculation and show you the result.
    For example(a very basic one)
    drop table test;
    create table test (sal number, comm number);
    alter table test add (emp_id number);
    insert into test values (1,2,1);
    insert into test values (3,2,2);
    insert into test values (4,1,3);
    insert into test values (5,2,4);
    commit;
    create or replace view v_test as select emp_id,sal,comm,sal+comm total from test;
    select * from v_test;Cheers!!!
    Bhushan

  • Nextval from trigger without using DUAL

    Hi everyone,
    It is possible to obtain the nextval of a sequence from a trigger without using DUAL?
    I have a table (TABLE1) with column ID NUMBER(10).
    I have a sequence (SEQ1)
    I need a trigger on before insert TABLE1 and I need obtain the nexval of the sequence BUT I CAN NOT use DUAL (it is forbbiden in my project. Don't ask :((( )
    can you help me?
    thanx a lot!

    "So of course using select seq.nextval from dual is
    most of the time unnecessary thing and should be
    banned as much as possible, but I think that simple
    prohibition is quite stupid."
    why do you think using dual ist most of the time
    unnecessary?Because in most scenarious you won't need dual.
    What are the reasons for using dual?
    1) because you need the value later in some other computations. The most elegant, simple and performant solution is just use returning clause of the insert statement.
    2) because the value is not provided. As I'm usually using more or less logic in DB or at least some business logic API (as pl/sql packages/procs) I'm always inserting new rows using sequence.nextval in the very insert statement so absolutely no need for before insert trigger supplying id value.
    If you think that select sysdate/sequence.nextval and similar things are very cheap then it is not true :)
    I've seen some batch procedures processing many rows and for each row:
    1) get sequence.nextval into variable from dual
    2) insert row using variable in id
    And select seq.nextval from dual took more tha 10% of overall time.
    Ok just a simple test case on 9i
    declare
    val number;
    begin
      for i in 1..10000 loop
        select seq1.nextval into val from dual;
        insert into seq2 values (val);
      end loop;
    end;dbms_profiler shows that total time for select into was ~982 msec but insert just took 722 msec. So actual insert took less than select from dual! The overall time was 1.922 secs.
    OK now let's see how it is with following script:
    declare
    val number;
    begin
      for i in 1..10000 loop
        insert into seq2 values (seq1.nextval) returning a into val;
      end loop;
    end;insert row took 931 msec and overall time was 1.094 secs.
    So this is for batch. For OLTP like app the only difference is that resource waste is spread out for many transactions but the overall net result is the same - you are inefficiently wasting resources.
    Ok in 10g results will be better with fast dual, but select anything from dual is very bad habit especially if used extensively.
    Gints Plivna
    http://www.gplivna.eu

  • JDeveloper 10g Creating a new record with trigger sequence primary key

    Hi there, I'm sorry to post this incredibly simple question and I'm sure that someone must have answered this on this forum before but the searching of this site is incredible slow and painful and after 30 mins I can't find help.
    I am using a struts Data Action to create a new record in the database and then being forwarded to an edit page where I can enter the new details. Then when the details are entered I am clicking an update button and returning to a browse screen where I can either commit the change to the database or rollback. Sounds pretty simple but I am really struggling with trying to get the trigger of the number sequence to work properly.
    Ideally I would like to click the create new record button and then the primary key/triggered sequence number is already displayed on the empty form...
    ... but if this is too tricky or not possible then I would like the user to either not enter any value in the key field (which currently causes error - JBO-27014: Attribute PoNo in PO_SYS_MODULE.PoSystemView1 is required) OR the user enters a number and the trigger overwrites this number with the next in the sequence.
    I can enter a new record if I look in the manager console and see the next number in the sequence and then create the record using this number and then click commit twice, as the first time I get the error: JBO-25019: Entity row of key oracle.jbo.Key[154 ] not found in PoSystem. Or if I enter a value 5 times greater than the next in the sequence I have to click the commit button 5 extra times to get the sequence to match the input.
    I hope that this lengthy explanation fills you in on my problem, there must be a simple solution to this and I will be VERY grateful to anyone who can help me.
    Many thanks
    Ben Sayers (clearly a newbie)

    Hi,
    ADF Business Components handles this for you - unless yo prefer doing this manually. In the Entity Object, set the PK attribute's type to DBSequence. Then create a database sequence and use a database trigger to add the sequence value on insert
    Frank

  • Trigger with sequence question

    figured it out
    Edited by: Jay on Apr 24, 2012 9:49 AM

    If we believe that your BEFORE INSERT trigger compiles successfully (it will not if your CREATE SEQUENCE DDL is actually using case-sensitive identifiers)
    CREATE OR REPLACE TRIGGER user_UPDATE
      AFTER UPDATE ON table1
      FOR EACH ROW
    BEGIN
      INSERT INTO table2
        change_id,
        change_date
        user,
        address,
        phone
      VALUES
        SEQ_user_update.NEXTVAL,
        sysdate
        :new.user,
        :new.address,
        :new.phone
    END;If we believe that the CREATE SEQUENCE DDL statement you posted is correct and that your BEFORE INSERT trigger does not compile then you'd need to put double-quotes around the sequence name
    CREATE OR REPLACE TRIGGER user_UPDATE
      AFTER UPDATE ON table1
      FOR EACH ROW
    BEGIN
      INSERT INTO table2
        change_id,
        change_date
        user,
        address,
        phone
      VALUES
        "SEQ_user_update".NEXTVAL,
        sysdate
        :new.user,
        :new.address,
        :new.phone
    END;Justin

  • Before report trigger execution sequence

    Hi,
    What is the execution sequence of the before report trigger ?
    In the report builder help, the definition says "The Before Report trigger fires before the report is executed *but after queries are parsed and data is fetched*."
    But the oracle document "Oracle iDS Reports: Build Internet Reports: Volume 2: Student Guide" says
    "Before a report executes; *after queries are parsed, but before records are fetched*
    I have built a report where, i am populating a table A with some data in the before report trigger. The data model query is a "select * from A ". But the report o/p is blank since the before report trigger was fired after the query was parsed and fetched. My understanding is that the queries should only be parsed but not fetched before the "before report trigger"
    Regards,
    Suresh

    Hi,
    this is an important question.
    In fact the online help is right: Before its execution the query is parsed and data fetching is strarted.
    Thus any plsql operation that may influence the query and the data accessed is too late in the BEFOREREPORT trigger.
    THe issue is that there is no error message or warning. THe problem scenario bandwidth is wide: From "no problem at all" to constant or intermittent error scenarios or worst case unrecognized problems like missing records or any strange behavior in the layout.
    So very carefull while using BEFOREREPORT trigger
    Ciao
    Markus

  • Sequence inside a Trigger ??

    Is it possible to use a sequence inside trigger's definition ?
    I don't understand why when i give a static value to my RowId in a trigger's definition it works, but when get a value from a sequence, the trigger become invalid.
    Please Help.

    Somewhat off the spatial topic but what the heck! This is easy :
    SQL> create table t
    2 (person_id number,
    3 person_name varchar2(32));
    Table created.
    SQL> create sequence person_id_seq start with 1 increment by 1;
    Sequence created.
    SQL> create trigger person_id_trig
    2 before insert
    3 on t
    4 for each row
    5 begin
    6 select person_id_seq.nextval
    7 into :new.person_id
    8 from dual;
    9 end;
    10 /
    Trigger created.
    SQL> insert into t (person_name) values ('Steve');
    1 row created.
    halls@GENDEV> select * from t;
    PERSON_ID PERSON_NAME
    1 Steve
    SQL> insert into t (person_name) values ('Rod');
    1 row created.
    halls@GENDEV> select * from t;
    PERSON_ID PERSON_NAME
    1 Steve
    2 Rod
    SQL>
    Steve

  • Auto number by sequence and trigger - issue

    Hi,
    i need to insert auto number in one of the column of my table, and i tried like the following way..
    CREATE TABLE STOP_TRACKING
      ID                    NUMBER                           primary key,
      MSISDN                NUMBER                  NOT NULL,
      TIME_STAMP            DATE                    DEFAULT SYSDATE,
      STOP_TRACKING_RESULT  NUMBER,
      REQUEST_ID            VARCHAR2(60 BYTE)
    TABLESPACE SYSTEM
    PCTUSED    40
    PCTFREE    10
    INITRANS   1
    MAXTRANS   255
    STORAGE    (
                INITIAL          64K
                MINEXTENTS       1
                MAXEXTENTS       2147483645
                PCTINCREASE      0
                FREELISTS        1
                FREELIST GROUPS  1
                BUFFER_POOL      DEFAULT
    LOGGING
    NOCACHE
    NOPARALLEL;
    COMMENT ON COLUMN STOP_TRACKING.STOP_TRACKING_RESULT IS 'IF RESULT ID "0" - OK AND IF RESULT ID "1" - NOT OK';
    create sequence seq_autonumber;
    CREATE OR REPLACE TRIGGER trg_autonumber
    BEFORE INSERT ON STOP_TRACKING
    FOR EACH ROW
    WHEN (new.id IS NULL)
    BEGIN
      SELECT seq_autonumber.NEXTVAL
      INTO   :new.id
      FROM   STOP_TRACKING;
    END;
    /when i execute the create trigger sql in toad sql editor am getting a pop up saying
    >
    variable name:NEW
    Type: drop down list ...here i tried almost relevant data types, int,long,....
    Value:...here i entered 1
    and clicked ok...and got the error as
    ORA-01036: illegal variable name/number
    >
    what could be issue?
    Edited by: Aemunathan on Nov 22, 2009 2:55 PM

    I just copy pasted your code.
    Works just fine.
    I believe you issue is realed to TOAD rather than pl/sql.
    Would have loved to help you but i use pl/sql developer.
    However if possible send a screen shot.
    Cheers!!!
    Bhushan

  • Solved: ADF BC and primary keys - how to implement without using triggers

    Using the following OBE as an example:
    http://www.oracle.com/technology/obe/obe9051jdev/ADFWorkshop/BuildingADFApplicationsWorkshop.htm
    There is just one view that has CustomerId defined as a primary key, where the value for the primary key comes from the customer_seq sequence.
    How do you create the model using ADF BC entity to create an entity object that has a primary key that needs to be populated by a sequence table when inserted WITHOUT using a trigger?
    Basically I want to just use ADF BC instead of toplink in the OBE. We do not use triggers to insert primary keys, so this example is a good match for what I need.
    Can someone help me out. How do I adjust the model to use just ADF BC - how do I define the entity object to use a sequence. Do I just override the create method in the impl? Is it that simple? Or is there a way to do this point and click in the entity tool.
    Thanks!

    I'm not the dba (or one of several) - so don't shoot the messenger... the dba's do not like to use triggers in the code. I have been told that this has caused too many problems in application development.
    I don't ask why, just deal with the fallout.
    I did try using the following code in a create method:
    protected void create(AttributeList attributeList)
    super.create(attributeList);
    SequenceImpl s = new SequenceImpl("customers_seq", getDBTransaction());
    // this.setCustId(s.getSequenceNumber());
    this.createPrimaryKey(s.getSequenceNumber());
    When I run the test program for the module, I get a new entry with the id empty and greyed out. I was hoping that this would be filled in on the actual insert, but no joy. As soon as I try to commit, I get an error:
    (oracle.jbo.AttrValException) JBO-27014: Attribute CustId in CustomersWSView is required)
    So what needs to be done?
    Message was edited by:
    klee

Maybe you are looking for

  • N81 is not getting started.

    my mobile n81 has some problem as while charging it give only white li8 and it is not getting on after a long time of chargin. can u tell wht is the problem in it and how can it be ressolved????????????

  • Problem regional formats setting

    Hi all, in my Dashboard I am using the SDK KPI Tile to show some values (but this problem occurs in others components too). In the initial view of my datasource I selected scaling factor 1,000. The KPI Tile should display the value 300 000 as 300 T€.

  • FILE------ XI-------- RFC

    Hi Friends, i have a requirement to work on file-xirfc synch with bpm. in this, i am not able to find the synchronous send step in integration process designing. i request you to please send me the documentation about this designing of integration pr

  • HT201210 getting error 2001 when sync to itunes.can any one help?

    Hi Pluged in a iphone 4 to itunes which is the newst one and updating iphone to iso 7 the lastest one when it keeps coming up with an error 2001 and stuck onconnect to itunes ircon on iphone. tired to restore but keeps coming up with same error. can

  • Changing env-entry after deployment

    Hi, I was wondering how I can change the value of an env-entry after deployment? Do I have to change the value in the ejb-jar.xml, redeploy the application, or is there a utility I can use? thanks Steve