Insert correctly last record to the child table in the multi user environment.

Hello
I have the following situation.

Two Tables
Table1 has a primary key named ID column
Tabel2 contains a column named table1_id, this is a foreign key to table1.

I have a tabular report that contains an add record button and a button submit to table1. (this table has other columns that require attribution)

I want to insert a record into table2 automatically whenever the user presses submit.

I have a query like this to get the last record in table1:
SELECT MAX(id) 
  FROM table1
and I would use it in a submit after procedure like this:
DECLARE v_id NUMBER;

BEGIN

    SELECT MAX(id)
      INTO v_id
      FROM table1

    INSERT
      INTO table2(table1_id)
    VALUES (v_id);

END;
The thing that worries me, is that the application that I use is a multi user environment. I'm afraid that if two or more people use as MAX recording is not the right one.
It's a legitimate concern?
If so, is there a best way to do this kind of thing.

Ben:

The triggers are usually avoidable IMO. But, there is always a but, you already use triggers elsewhere in your application, and probably your form the apex uses the routines of APEX MRU for DML and thus leaves the trigger as the only viable option to achieve what you're trying to do.

CITY

Tags: Database

Similar Questions

  • How to find inserted last record in the table.

    Version: Oracle 10g

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    As I got to know that the Rowid is not a result perfect result. Please provide your inputs.

    user13416294 wrote:
    Version: Oracle 10g

    This is not a version. It's a product name. A version is 10.1.0.2 or 10.2.0.4, etc.

    I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
    How to find inserted last record in the table 'manufacturing '.

    Not possible as your data model do not answer for him. As simple as that.

    If there is a need to determine an order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or several attributes are necessary to represent this information. Your data model in this case is therefore unable to meet your requirements.

    If the requirements are valid, set the data model. In other words - your question has nothing to do with Oracle and nothing to do with the other pseudo columns in Oracle, the rowscn or the rowid. It is a question of pure data modeling. Nothing more.

  • Inserting a new record in the database using a form empty ADF

    Hello

    I'm trying to insert a new record into the database using a form.

    I have an Employee table and its corresponding entity object and the view object. The table has an id that is used as the primary key and is filled using a sequence in the comic book.

    Data controls, I dragged and dropped at the sight of the employee as a form of ADF and checked the submit button include. Then I dragged and dropped the validation on submit button operation.

    When I connect to the app and go to the page used to create, I have 2 problems:
    1 - the form is filled with the logged in user info.
    2. If I try to change the news and validation, the user info is changed in the database and no new record is created.

    It makes a little sense to me, but I would like to know if there is a way around it (get an empty form and insert a new record).
    NB: the employee id is not part of the form, I want to be filled using the sequence.

    Kind regards
    MB

    User, please tell us your jdev version!

    To do this, you must create a new record before going to the display of the form page. In a stubborn workflow (btf), you drag the operation createInsert of the VO on the btf and it will generate a link method, add a view to the btf and put a navigation of the binding of the method of the page. Mark the method as 'Activity by default'. Now, ren, you call the workflow, you create a new record that will show your blank form.

    Timo

  • Ask the deptno 20 last record at the end show

    Oracle 9i Database

    I want to create a query that shows records, Deptno 20 last record at the end.
    application of shot show all records that are in the emp table.
     SQL> select empno,ename,job,deptno, row_number() over (order by deptno) rno from emp;
    
         EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
          7782 CLARK      MANAGER           10          1
          7839 KING       PRESIDENT         10          2
          7934 MILLER     CLERK             10          3
          7369 SMITH      CLERK             20          4
          7876 ADAMS      CLERK             20          5
          7902 FORD       ANALYST           20          6
          7788 SCOTT      ANALYST           20          7
          7566 JONES      MANAGER           20          8
          7499 ALLEN      SALESMAN          30          9
          7698 BLAKE      MANAGER           30         10
          7654 MARTIN     SALESMAN          30         11
    
         EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
          7900 JAMES      CLERK             30         12
          7844 TURNER     SALESMAN          30         13
          7521 WARD       SALESMAN          30         14
    
    14 rows selected.
    
    SQL> 
    I want the result
    EMPNO ENAME      JOB           DEPTNO        RNO
    ---------- ---------- --------- ---------- ----------
    7566 JONES      MANAGER           20          8
    7499 ALLEN      SALESMAN          30          9
    7698 BLAKE      MANAGER           30         10
    7654 MARTIN     SALESMAN          30         11
    7900 JAMES      CLERK             30         12
    7844 TURNER     SALESMAN          30         13
    7521 WARD       SALESMAN          30         14
    Concerning
    with t as
     ( select    7782  e1,'CKING '  e2  ,  ' PRESIDENT '  e3     ,   10  e4    from dual union all
       select    7934, 'MILLER'  ,  'CLERK  '        ,    10       from dual union all
       select    7369, 'SMITH '  ,  'CLERK  '        ,    20       from dual union all
       select    7876, 'ADAMS'   , 'CLERK '        ,     20       from dual union all
       select    7902, 'FORD '   ,  'ANALYST '       ,  20       from dual union all
       select    7788, 'SCOTT'   , 'ANALYST '       ,  20       from dual union all
       select    7788 ,' SCOTT '  ,'ANALYST '  ,       20       from dual union all
       select    7566, 'JONES ',    'MANAGER '   ,     20       from dual union all
       select    7499, 'ALLEN ' ,    'SALESMAN'   ,    30       from dual union all
       select    7698, 'BLAKE ' ,    'MANAGER '    ,   30       from dual union all
       select    7654, 'MARTIN' ,  'SALESMAN '  ,    30       from dual union all
       select    7900, 'JAMES ' ,   'CLERK '      ,       30       from dual union all
       select    7844, 'TURNER' ,  'SALESMAN ' ,     30       from dual union all
       select    7521 ,'WARD ' ,    'SALESMAN ' ,     30       from dual
    )
    SELECT o.*
      FROM (SELECT p.*,
                   MAX (CASE
                           WHEN p.e4 = 20
                              THEN p.rno
                        END) OVER (ORDER BY p.e4) AS mx
              FROM (SELECT a.*, ROW_NUMBER () OVER (ORDER BY e4) rno
                      FROM t a) p) o
     WHERE o.rno >= o.mx
    
  • jump the last record loading using external table

    Hi gentlemen,

    I have a requirement to load data from text file of oracle database by using the external table. I need to remove the header records and complementary.

    I can use the skip option to remove the header, IE front-line.

    Is it possible to remove the additional record (IE last line) using the external table.


    Thanks in advance.

    Ferry

    Hello ferry.
    Do not hesitate on occasion as useful and Correct answers for those of us Newbie trying to get credibility :)

    Thank you
    Luke

  • remove the last record from the plsql table

    TYPE r_LOOPElement IS RECORD (TermID   NUMBER 
                                          );
    
    TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
    i_CustomerLoop      t_LOOPType ;
    
    i_CustomerLoop(1).TermID=1;
    i_CustomerLoop(2).TermID=2;
    i_CustomerLoop(3).TermID=3;
    Under certain conditions, I need to remove the last record from i_CustomerLoop

    whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.

    Hello

    See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]

    Kind regards

  • How to find the last record of the extracted records

    Dear members,

    I have an OFA Page in which I view record master detail. For each master record can one or more detail records.

    In the page I got the button NEXT. If the user clicks the next button, I'm populating the next record of the master and its corresponding detail records.

    To achieve this, I wrote the code below in AM:_


    Public Sub findNextRec()
    *{*
    String headerID = null;
    Rank rank is getMaster_VO1 () .next ();.
    if(Row!=null)
    *{*

    headerID = row.getAttribute ("HeaderId") m:System.NET.SocketAddress.ToString ();
    getDetail_VO1 (.setMaxFetchSize(-1));
    getDetail_VO1 () .setWhereClause (null);
    getDetail_VO1 () .addWhereClause ("header_id in (: 1)" ");
    getDetail_VO1 () .setWhereClauseParams (null);
    getDetail_VO1 (.setWhereClauseParam(0,headerID));
    getDetail_VO1 () .executeQuery ();

    *}*
    *}*

    My CO code in processFormRequest method is as follows:_


    If (PageContext.GetParameter ("Next")! = null)
    *{*
    am.invokeMethod ("findNextRec");
    *}*

    Here my requirement is that if it's a last drive, I want to show the user a message saying it's last recording. To achieve this please let me know what the code should be written.

    Thanks in advance.

    Best regards
    Arun D. Reddy

    Arun,

    If my interpretation is correct, then you can achieve the same thing by making some minor changes to your existing code.

    public void findNextRec()
    {
    String headerID=null;
    Row row = getMaster_VO1().next();
    if(row!=null) //your code will return null when if there is no record
    {
    headerID=row.getAttribute("HeaderId").toString();
    getDetail_VO1().setMaxFetchSize(-1);
    getDetail_VO1().setWhereClause(null);
    getDetail_VO1().addWhereClause("header_id in (:1)");
    getDetail_VO1().setWhereClauseParams(null);
    getDetail_VO1().setWhereClauseParam(0,headerID);
    getDetail_VO1().executeQuery();
    }
    else{
    //write down the message that there exist no more rows (custom message)
    
         }
    }
    

    Kind regards
    GYAN

  • XP does not remember the last record in the file

    I ran a microsoft utility to repair a registry problem under xp.  now none of my programs don't forget the record '' last saved as. '' Each always default record on the desktop.  Where in the registry may I to address?

    It is specific about where you want to save your program files. It is not the same for all programs.

    Use this program called TweakUI and change settings.

    TweakUI
    http://download.Microsoft.com/download/f/c/a/fca6767b-9ed9-45a6-B352-839afb2a2679/TweakUiPowertoySetup.exe

    See also:

    http://forums.techguy.org/Windows-XP/912279-solved-how-do-i-change.html

  • inserting a new record in the database of a form

    Hi friends,

    I'm trying to insert a record into the database via a form I created in Oracle 10 g.
    Using the default menu (DEFAULT & bar SMARTBAR), I should be able to save the record, shouldn't I?

    Is someone can you please help me solve this problem?

    Thank you, sheetal :)

    Check if your code sequence and make like this code example (focused only on the "BOLD" letters, because I think that your specific sequence will not be in order i.e. ALL), you must make your sequence in order with no cycle.

    CREATE the SEQUENCE "YOUR_SEQUENCE_NAME" MINVALUE 1 MAXVALUE 99999 INCREMENT OF 1 START WITH 1 CACHE 20 ORDER NOCYCLE .

    Hope this will help.

    Abbas

  • Need help with the error "user environment.

    I get the following message to the start and now all my personal files and settings are gone.  Help, please.

    Environment of the user - Windows cannot load the locally stored profile.  Possible causes of this error include insufficient security rights or a damaged local profile.  If the problem persists, contact your network administrator.

    DETAILS - an operation i/o initiated by the registry failed irreparably.  The registry could not read, write or flush, one of the files that contain images of the registry system.  Windows cannot find the local profile and connects you with a temporary profile.

    Changes to this profile will be lost when you log out.

    Thanks for any help.

    Hi primovic,.

    ·         Since when are you facing this problem?

    ·         Did you make any changes before the show?

    Step 1: The following article should help you to solve the problem.

    Error message: "Windows cannot load the locally stored profile".

    Step 2: You can follow this link to copy the data from the damaged to the new profile user profile.

    How to copy data from a corrupted to a new profile in Windows XP user profile

  • Nested table of object type have only one record all the time

    Hi all

    I have a question regarding the storage of multiple records in a nested Table that is of type OBJECT.

    The program below that I wrote for the test and during the test, I was able to store only the last record in the nested Table.

    Please let me know what I did wrong here.

    Step 1:
    CREATE or REPLACE TYPE book_obj AS OBJECT (name varchar2 (25), author varchar2 (25), abstract varchar2 (4000));
    /

    Step 2:
    CREATE or REPLACE TYPE book_table IS TABLE OF THE book_obj;
    /

    Step 3: CREATE TABLE book (name, varchar2 (25), varchar2 (25) author, varchar2 (4000)) abstract;
    INSERT VALUES Accountants ('Harry Potter,' 'MK', 'It's magic');
    INSERT the book VALUES ("Ramayana', 'VK', 'It is mythiology'");
    COMMIT;

    Step 4:
    declare
    bookset book_table;
    ln_cnt pls_integer;
    Start
    bookset: = book_table (book_obj ('madhu', 'kongara', 'sudhan'));
    dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see COUNT = 1
    bookset: = bookset_t(); -> Assignment to NULL.
    dbms_output.put_line (' the number is ' | bookset.) (Count); -> I see County 0
    for rec in (select * from book) loop-> now a loop twice.
    dbms_output.put_line (' name > ' |) Rec.Name);
    bookset: = bookset_t (book_t (rec.name, rec.author, rec.abstract));
    end loop;
    dbms_output.put_line (' the number is ' | bookset.) (Count); -> I can see COUNT = 1 (why?)
    END;

    I looped twice to fill two records in the TABLE IMBRIQUEE OF TYPE OBJECT. But when I see the Count I get only 1 and the data is also having the last record.

    Can you get it someone please let me know how to fill out the table nested with all records. Tell me where I am wrong.

    Very much appreciate your help here.

    Thank you and best regards,
    NKM

    Maldini says:
    dbms_output.put_line (' the number is ' | bookset.) (Count); -->, I can see COUNT = 1 (why?)

    Because instead of add to bookset collectionto set (ergo replacement) it a collection containing recovered book. Use:

    declare
        bookset book_table;
        ln_cnt pls_integer;
    begin
        bookset := book_table(book_obj('madhu','kongara','sudhan'));
        dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
        bookset := book_table(); --> Assigning back to NULL.
        dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
        for rec in (select * from book) loop --> Now Looping two times.
          dbms_output.put_line(' name > '||rec.name);
          bookset.extend;
          bookset(bookset.count) := book_obj(rec.name, rec.author, rec.abstract);
        end loop;
        dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
    end;
    /
    The count is 1
    The count is 0
    name > Harry Potter
    name > Ramayana
    The count is 2
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    Or better use bulk collect:

    declare
        bookset book_table;
        ln_cnt pls_integer;
    begin
        bookset := book_table(book_obj('madhu','kongara','sudhan'));
        dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1
        bookset := book_table(); --> Assigning back to NULL.
        dbms_output.put_line('The count is '||bookset.count); --> I can see count as 0
        select  book_obj(name,author,abstract)
          bulk collect
          into  bookset
          from  book;
        for i in 1..bookset.count loop --> Now Looping two times.
          dbms_output.put_line(' name > '||bookset(i).name);
        end loop;
        dbms_output.put_line('The count is '||bookset.count); --> I can see COUNT =1 (why)
    end;
    /
    The count is 1
    The count is 0
    name > Harry Potter
    name > Ramayana
    The count is 2
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Cursor Oracle return only the last record

    I am a newbie in oracle stored proc. I tried to select data using the slider, but it only return last record. The recording must be greater than 1.

    CREATE or REPLACE procedure MySchema.Test (myrefcur on sys_refcursor)
    Is

    Begin
    declare

    Cursor C1 IS

    Select mySerialNum from TableA;
    MyRecord C1% rowtype;

    Begin
    Open C1;
    Loop
    Fetch C1 into myrecord;
    When the output C1% NotFound;

    Open for Myrefcur
    Select SerialNumB from TableB where SerialNumB = myrecord.mySerialNum;

    End loop;
    Close C1;
    End;
    end;

    However, it only returns the last record in the list.

    Original case *.
    The original code is as below:

    1st, I'll need to select a list of ImageSerialNum of ImageSerial

    * 1 query:
    Select A.ImageSerialNum from ImageSerial A, ProductionOrder B, Bom C
    Where A.ProductionOrderID = B.ProductionOrderID And B.Assembly_Num = C.Model_Num and
    B.Revision = C.Revision And B.EngRevision = C.EngRevision and
    C.Bom_ID = passInVariable* and C.FactoryID = "7"

    2nd, I'll need to check the process of EACH series with the code below:

    * Low code a return process for 1 series only.

    Select t.processid, t.processname, t.assembly_num, t.revision, t.engrevision of
    (Select p.ProcessID, p.ProcessName, in. Assembly_Num, in. review, in. EngRevision, im.imageserialnum
    Process p, Routesequence rs, Imageserial im, ProductionOrder in.
    Where im. ImageserialNum = SerialNum* and p.ProcessID = rs. ProcessID
    And rs. RouteID = in. RouteID and rs. SequenceID = im. NextRouteSequence
    And in. ProductionOrderID = im. ProductionOrderID AND IM. STATUS OF '0'
    UNION
    SELECT A.REWORKROUTEID AS PROCESSID PROCESSNAME AS B.ROUTENAME, C.ASSEMBLY_NUM, C.REVISION, C.ENGREVISION, a.imageserialnum
    OF IMAGESERIAL A, B OF ROAD, PRODUCTIONORDER C
    WHERE A.REWORKROUTEID = B.ROUTEID AND A.IMAGESERIALNUM = SerialNum*.
    AND A.PRODUCTIONORDERID = C.PRODUCTIONORDERID and a.status = '0') t

    After that, I would like to combine the two in 1 stored proc code.

    in this case, you just want to join the two applications to use in the FROM clause
    As I don't have your tables, I created two tables, each representing the results of your queries. Substitute the names of table with your queries

    SQL> drop table master
      2  /
    
    Table dropped.
    
    SQL> drop table details
      2  /
    
    Table dropped.
    
    SQL>
    SQL> create table master
      2  (ImageSerialNum varchar2(25));
    
    Table created.
    
    SQL>
    SQL>
    SQL> insert into master values ('Serial1');
    
    1 row created.
    
    SQL> insert into master values ('Serial2');
    
    1 row created.
    
    SQL> insert into master values ('Serial3');
    
    1 row created.
    
    SQL> insert into master values ('Serial4');
    
    1 row created.
    
    SQL> insert into master values ('Serial5');
    
    1 row created.
    
    SQL>
    SQL> create table details
      2  (ImageSerialNum  varchar2(25)
      3  ,ProcessID  number
      4  ,ProcessName varchar2(25)
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into details values ('Serial1',  1, 'Process1');
    
    1 row created.
    
    SQL> insert into details values ('Serial3',  3, 'Process3');
    
    1 row created.
    
    SQL> insert into details values ('Serial5',  5, 'Process5');
    
    1 row created.
    
    SQL>
    SQL> select m.imageserialnum
      2       , d.processid
      3       , d.processname
      4    from master m
      5    left outer
      6    join details d
      7      on (m.imageSerialnum = d.imageserialnum)
      8   order by m.imageserialnum
      9  /
    
    IMAGESERIALNUM             PROCESSID PROCESSNAME
    ------------------------- ---------- -------------------------
    Serial1                            1 Process1
    Serial2
    Serial3                            3 Process3
    Serial4
    Serial5                            5 Process5
    

    your query will be something like

    select m.imageserialnum
         , d.processid
         , d.processname
      from () m
      left outer
      join (
    
  • Select the last disk in the history table

    How to select the last record in a history table? the example data is
    < p >
    Product EffectiveDate

    prod1 01/01/1980

    prod1 01/01/1990

    prod1 01/01/2000

    prod2 02/02/1980

    prod2 02/02/2000
    < /p >
    < p >


    The expected result is



    Product EffectiveDate

    prod1 01/01/2000

    prod2 02/02/2000
    < /p >

    Assuming that there is a single line with max (effectivedate) for a given product

    SELECT product, attrib1, attrib2, ... , max_effective_date
      FROM (SELECT product,
                   attrib1,
                   attrib2,
                   ... ,
                   effectivedate,
                   max( effectivedate ) over (partition by product) max_effective_date
              FROM history_table)
     WHERE effectivedate = max_effectivedate
    

    should work.

    Justin

    Published by: Justin cave on October 30, 2008 18:32

    Formatting changes

  • Format the first and the last record of query result

    Hello
    I have the following query

    < tt > select 1 seq, "This is the first record" data from dual union of all the
    Select 2, 'Data ' | tNom tab Union all
    Select 3, "It was last last record" double
    order by 1 < /tt >

    When I have the coil this summary to a listfile with col seq noprint option I get:

    This is the first record
    Data MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    Data MLA_VPD_TABLES
    It was the last last record

    But I want to:

    It's first record MLA_ACCESS_LIST
    Data MLA_APPLICATIONS
    Data MLA_VPD_PCK
    MLA_VPD_TABLES it was save finally last record

    I tried with 1 statement with the use of lead and lag, because first and last record stand the other result record. But I get ORA-30484: lack of specification of the window for this function

    Is this possible with 1 statement or am I've sentenced to modify the results by myself?

    Thank you Auke

    Select row_number() case above (tNom control)
    When 1 then 'it's the first record
    end | tNom |
    -case row_number() over (order by desc tNom)
    When 1 then 'it was the last record. "
    end
    tab
    order by tNom

    HTH

  • Insert and update records to MySQL from Oracle

    Hello

    Our application will be insert/update new records in the Oracle database, but I need to insert/update new records in the MySQL database. Oracle and MySQL tables have the same columns.

    Right now, we intend to create DBLink between Oracle and MySQL. The question is to know how to write code to insert/update new records to MySQL from Oracle. I'm a new guy in this area.

    Please give us some examples of code, thanks!

    With Oracle, you should be able to just write the same thing as usual, except for the include link database when you reference the table for example your SQL

    insert into tablename@mysqldblink...

    updating of the game tablename@mysqldblink...

    Services gateway through the database link (odbc drivers or anything else that is used) must make the most of the necessary conversions for you.

Maybe you are looking for

  • Re: Unable to update BIOS onSatellite L40 - 17U

    Hello So, my laptop is Satellite L40 - 17U currently running bios 1.80 and try to updateto 5.50. In windows 7, I'm trying to update the BIOS with the supplied *.bat filetoshiba Web site, I get an error: Failure of WinIo initialization (WinIo.sys) Wha

  • Why my custom control consuming 30% of the CPU power?

    Hello on my laptot C2D 2.0 GHZ if I open just VI with custom control I developed it consumes about 30% of the CPU power. Could someone explain why? Is also my problem with this control? I see it with 8.5 and 8.6 as well. It must be linked to its repr

  • 5740 memory card won't show photos on the laptop Windows 7.0

    OK, now the images appear on the lcd screen, but it is still impossible to show the pictures on the memory card in the printer on the computer laptop im using windows 7. Any help please?

  • How can I configure Spanning Tree

    Hello I have several core Dell passes using PowerConnect 6224 s most - these ink in my Cisco provider kit. We run several VLAN and have redundant links between stacked switches. I have read up on top of the tree covering weight and have the following

  • BlackBerry smartphone how to add new device on BlackBerry Protect Online

    Hi guys I got a BB Torch 9860 when it was released and returned to Vodafone UK for the replacement for the same exact model, when I go online on blackberry protect I see still old device here I managed to remove it and I need to add this new inside b