Need to update sequence value in two table

Hi guys
Please help me in the below query
I will need to insert a row in two different table
table1
col1 col2
table2
column1 column2
the col1 in table1 will be assigned a sequence.nextval
i need to assign the same value in table2 column 1.
can i do it in a single insert statement

i would do like this. INSERT ALL is the way to go...
SQL> create sequence my_seq;
Sequence created.
SQL> create or replace function my_seq_fn return number
  2  as
  3  lNum number;
  4  begin
  5  select my_seq.nextval into lNum from dual;
  6  return lNum;
  7  end;
  8  /
Function created.
SQL> create table t1(a number, b number);
Table created.
SQL> create table t2(c number, d number);
Table created.
SQL> insert all
  2  into t1(a,b) values(seq, val1)
  3  into t2(c,d) values(seq, val2)
  4  select my_seq_fn() as seq, level+5 as val1, level+10 as val2
  5  from dual
  6  connect by level <=10;
20 rows created.
SQL> /
20 rows created.
SQL> select * from t1;
         A          B
         1          6
         2          7
         3          8
         4          9
         5         10
         6         11
         7         12
         8         13
         9         14
        10         15
        11          6
         A          B
        12          7
        13          8
        14          9
        15         10
        16         11
        17         12
        18         13
        19         14
        20         15
20 rows selected.
SQL> select * from t2;
         C          D
         1         11
         2         12
         3         13
         4         14
         5         15
         6         16
         7         17
         8         18
         9         19
        10         20
        11         11
         C          D
        12         12
        13         13
        14         14
        15         15
        16         16
        17         17
        18         18
        19         19
        20         20
20 rows selected.
SQL> select my_seq.currval from dual;
   CURRVAL
        20 Thanks,
Karthick

Similar Messages

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Api to update the values in per_periods_of_placement table

    Hi,
    can anyone let me know whether any hrms api is available to update the values in the table PER_PERIODS_OF_PLACEMENT.
    I want to update the values under the column TERMINATION_REASON in per_periods_of_placement for few set of contingent workers(for those a wrong reason was entered need to replace with correct value now).
    Please revert asap.
    Thanks,
    Jithendra

    Here is my stand alone PL/SQL block :
    I am supplying the start_date fro mthe per_periods_of_ placement table itself...
    DECLARE
    CURSOR get_cwk_details IS
    SELECT person_id cwk_person_id,
    object_version_number ovn,
    date_start service_start_date
    FROM per_periods_of_placement pdp, hr_lookups l
    WHERE l.lookup_type(+) = 'HR_CWK_TERMINATION_REASONS'
    AND l.lookup_code(+) = pdp.termination_reason
    AND HR_GENERAL.DECODE_LOOKUP ('HR_CWK_TERMINATION_REASONS',
    PDP.TERMINATION_REASON) = 'Deceased' ;
    l_person_id NUMBER(20);
    l_ovn NUMBER(10);
    l_date_start DATE;
    BEGIN
    FOR get_cwk_details_rec in get_cwk_details
    LOOP
    l_person_id := 153564;--get_cwk_details_rec.cwk_person_id;
    l_ovn := get_cwk_details_rec.ovn;
    l_date_start := get_cwk_details_rec.service_start_date;
    dbms_output.put_line('l_person_id = ' || l_person_id);
    dbms_output.put_line('l_ovn = ' || l_ovn);
    dbms_output.put_line(' l_date_start = ' || l_date_start);
    apps. hr_periods_of_placement_api.update_pdp_details(
    P_VALIDATE => FALSE,
    P_EFFECTIVE_DATE => l_date_start,
    P_OBJECT_VERSION_NUMBER => l_ovn,
    P_PERSON_ID => l_person_id,
    P_DATE_START => l_date_start,
    P_TERMINATION_REASON => 'DW');
    COMMIT;
    END LOOP;
    END;

  • Update the values in the table on select of a particular row

    hi
    I want to update the values in the table on selecting the particular row.
    im able to select the particular row using Leadselect.
    can any one help me in updating the values in the table?
    regards
    raji

    hi,
    values are coming from my database ( SQLServer.)
    on click of the button i am able to display the values from the database.
    My problem is on selection of any row , i should be able to edit/update the values in the table .
    regards
    raji

  • Based on input file i need to update default values to some columns of database table using bulk copy process

    Hi Team,
    Am using BULK INSERT Format file option to load data into table from .txt file here am facing an issue i.e ibased on input file i need to insert default values to some columns of table so we can not declare it on table level, Can we give default values in
    format file ? if we can give how it is ? or Any alternate possibilities to this scenario instead of BULK INSERT ?
    Thanks,
    Sudhakar

    Thanks for your response, here i don't have any rights to change table structure the table is created by different team, my work is to load data from file to table. Is there any chance to supply default values by*XML* format file instead of *.fmt* file
    please let me know the possibility.
    Again, no. If you want to supply default values that are not present in DEFAULT constraints in the table definition, you will need to write your own code. There are plentyfull of options, and I have mentioned some already.
    Here are some more:
    *  Table-valued parameters, see here for examples:
    http://www.sommarskog.se/arrays-in-sql-2008.html
    *  Use BULK INSERT to load data to a staging table, and then apply the default values when you copy from staging to target.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Need to find the Difference between two table

    Hello ,
    I have stucked in program as below scenario:-
    I have two tables of huge data of same structure in a same schema.I need to find the difference exact values in tables.
    By using MINUS we can find the difference between two table ,i need to find the what exact difference in the there values with colunm and value at that column.
    Example TableA
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    80 DEF 6005 YY 446 YY8
    TableB
    Col1 col2 col3 col4 col5.... col50
    10 ABC 2001 EE 444 TT
    40 XYZ 3002 RR 445 TT3
    81 DEF 6005 Yu 447 YY8
    I need to the out put like this :-
    The Diffence between two table is
    TableA.COL1=80 TableB.Col1=81, Different
    TableA.Col4=YY TableB.col4=Yu,Different
    TableA.Col5=446TableB.col5=447,Different
    Please suggest me to write the pl/sql program for the same
    thanx in advance
    KK

    Thanx friends for all your efforts
    I have a sample code for the same,this will compare the two tables for single row in each table .
    what r the modification needed for the multiple rows of values in the two tables??
    Please suggest!!
    CREATE OR REPLACE PROCEDURE test_compare
    IS
    TYPE t_col
    IS
    TABLE OF VARCHAR2 (30)
    INDEX BY PLS_INTEGER;
    l_col t_col;
    j NUMBER := 0;
    l_sql VARCHAR2 (2000);
    col1 VARCHAR2 (30);
    col2 VARCHAR2 (30);
    val1 NUMBER;
    val2 NUMBER;
    status VARCHAR2 (30);
    CURSOR c1
    IS
    SELECT column_id, column_name
    FROM all_tab_columns
    WHERE table_name = 'TEST1';
    BEGIN
    FOR i IN c1
    LOOP
    j := j + 1;
    l_col (j) := i.column_name;
    END LOOP;
    FOR k IN 1 .. j
    LOOP
    l_sql :=
    'SELECT '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST2.'
    || l_col (k)
    || ', '
    || ''''
    || l_col (k)
    || ''''
    || ', '
    || 'TEST1.'
    || l_col (k )
    || ', '
    || 'DECODE(TEST2.'
    || l_col (k)
    || ' -TEST1.'
    || l_col (k)
    || ', 0, ''NO CHANGE'', ''CHANGED'') FROM TEST2, TEST1';
    EXECUTE IMMEDIATE l_sql INTO col1, val1,col2, val2, status;
    IF status = 'CHANGED'
    THEN
    DBMS_OUTPUT.put_line( 'TEST2.'
    || col1
    || '='
    || val1
    || ', TEST1.'
    || col2
    || '='
    || val2
    || ', '
    || status);
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line ('Error:- ' || SQLERRM);
    END;
    /

  • Regd bulk update of values in the table..

    HI ,
    I have a search page.. Have used autocustomization to create it ..This page will be used to query data from a table and then we also need to update couple of results table fields and save them.
    THere is a results region . i have included the multiselect option of table which has got me a select column as the first column in the table. Also have included a tableaction and an upate button with that ..
    Next to the table actions , Update button , I need to have a field , where in i can enter value and it shud update the updatable fields of rows in the table as bulk .. with the same value in the field next to update..
    SOme what like batch update for the table with same values..
    Could you please tell me hw do we do this ?
    Regards,
    Preeti

    Hi,
    As the update button is clicked then :
    if(pageContext.getParameter("Update")!= null)
    // Grab the value of the field next to update button
    String value = pageContext.getParameter("<id of text input>");
    //then loop through the rows
    for ( int i=0;i<row.length;i++)
    // then set the value of Attribute which you want
    row.setAttribute("<Attribute name>",value);//if this Attribute is on a text input in table then automatically it will be reflected for all rows of the table. (Bulk Update)
    Thanks,
    Gaurav

  • How to copy the value of two tables into a view.

    Hi Experts ,
    I have a requirement in which i have been provided with two tables(T1,T2) of same table structure ,i need to copy their entries into a table view with the same structure as the two tables(T1,T2) .
    suppose T1 has entries name age T2 has entries
    A 20 D 40
    B 30 E 46
    C 40
    the view should have all the entries,duplicate values no issues ...
    Could you please suggest how can i do that ?
    Thanks and Regards
    Debashis

    if table have same structure then you can use
    select * from t1
    union all
    select * from t2

  • Update a query using two tables

    CREATE TABLE T1
    FIELD1 VARCHAR2(10),
    VALUE1 INTEGER,
    FIELD2 VARCHAR2(10),
    VALUE2 INTEGER
    INSERT INTO T1 VALUES('OLD',100,'NEW',1000);
    INSERT INTO T1 VALUES('OLD',200,'NEW',2000);
    INSERT INTO T1 VALUES('OLD',300,'NEW',3000);
    CREATE TABLE T2
    FIELD VARCHAR2(10),
    VALUE INTEGER,
    NAM VARCHAR2(10)
    INSERT INTO T2 VALUES('OLD',100,'ABC');
    INSERT INTO T2 VALUES('OLD',200','ABC');
    INSERT INTO T2 VALUES('OLD',600,'ABC');
    INSERT INTO T2 VALUES('OLD',300,'XYZ');
    Currently there are old values in the table T2.But the current requirement is the corresponding new values present in table T1 should get reflected.One more condition is the NAM='ABC'
    I am trying to write in this way.It's getting target updated by multiple source rows.Please help in thi sregard.
    UPDATE T2 A
    SET A.FIELD=B.FIELD2,A.VALUE=B.VALUE2
    FROM T1 B INNER JOIN T2 A
    ON T2.VALUE=T1.VALUE1
    AND T2.NAM='ABC'
    Regards
    KVB

    You need something more like...
    UPDATE T2 A
    SET (A.FIELD, A.VALUE)=(SELECT B.FIELD2,B.VALUE2
                            FROM   T1 B
                            WHERE  A.VALUE=B.VALUE1)
    WHERE T2.NAM='ABC'(untested)

  • Need to populate sequence value in a field after insert in oaf page

    Hi All,
    I have a custom OAF insert page in that i need to populate a sequence value to a field once the data inserted successfully to the table.
    so for that i followed the below approach.
    1>Created a sequence in database.
    2>In the EOImpl java file in the setter method for the respective field have written below code.
        public void setContainid(Number value) {
            if (value == null) {
                    OADBTransaction t = getOADBTransaction();
                    value = t.getSequenceValue("XXXXX_CONTAIN_SEQ");
            setAttributeInternal(CONTAINID,value);  
    But still i am not able to populate the sequence value for the field in my oaf page,please help me out on thsi.
    Thanks

    Hi,
    Write this logic in create method of EOImpl:
      public void create(AttributeList attributeList)
        super.create(attributeList);
        OADBTransaction transaction = getOADBTransaction();
        Number contID = transaction.getSequenceValue("XXXXX_CONTAIN_SEQ");
        setContainId(contID);
    --Sushant

  • Function module to update the values in STPO table :   VERY URGENT!!!!!!!!!

    Hi All,
    Can any one tell me is there any Remote function module to update the values of components in STPO table while creating Sales order BOM, Material BOM, and WBS BOM. For example I want to update the Spare Part Indicator for Item components based on Plant.
    Please do the needful..
    Regards
    Yathish

    For material bom: CSAP_MAT_BOM_CREATE
    and CSAP_ORD_BOM_CREATE for Order BOM.
    Regards,
    Ravi

  • Need to update Ztable from final internal table

    Hi,
    ITAB   = Final internal table has 9 fields : 1 2 3 4 5 6 7 8 9
    Ztable = Ztable has 6 fields ex : 1 3 4 6 7 8
    Structure of both Itab and Ztable are different.
    I have data in the Final Internal table and needs to update data into a ztable.
    If condition is true...
      Modify ztable from itab
    endif.
    Any suggestions how I can update Ztable from the INternal table
    Regards,
    Kittu

    Hello,
    First keep the loop to the final internal table then move all the records to the work area after moving to workarea then create another workarea for the Ztable then move only the field values which are there in Ztable then use modify keyword.
    example
    move:
    y_wa_final_itab-kdauf to y_wa_zhr_item-vbeln,
    y_wa_final_itab-kdpos to y_wa_zhr_item-posnr,
    y_wa_final_itab-receiptno to y_wa_zhr_item-receiptno
    modify zhr_item from y_wa_zhr_item

  • BAPI_GOODSMVT_CREATE ---- need to update custom field in MSEG table

    Greetings all,
    I'm using 'BAPI_GOODSMVT_CREATE' to create goods movements. also I need to update one cutom field(z-field) in MSEG table. Could anyone please advice how can I update the custom field thru EXTENSIONIN.
    thanks in advance.

    see the help
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/4099948b8911d396b70004ac96334b/frameset.htm
    Regards
    Kiran Sure

  • Need to update corresponding columns in details table

    Hi,
    I have a header and lines table.
    In header table we have a comments field, requirement is whenever someone is updating comments in header it should update lines comment column as well.
    I tried using fire action on Comments field like as soon as user is entering something in Comments field I am capturing that event and firing and update statement for lines table
    but the problem here is, if user enters the comments and doesn't save it at header level it stills fire an update statement in lines and updating the comment field of lines table.
    I need to update header comments in lines level at Apply button.
    Please someone suggest something.
    Best Regards
    Ragni Gupta

    Hi Gurus/Expert,
    Please suggest something, its really urgent!!
    Thanks
    Ragni Gupta

  • Compare and test values in two tables

    hi everbody, I use oracle 10g
    I have a table for large itemsets called L shown below with values
    ITEMS CODE
    b 1
    c 2
    d 3
    e 4
    d:e 5
    b:c 6
    I generate all candidate combinations firstly 2-sequences for in code field values for that I use below code
    select ltrim(replace(sys_connect_by_path(code,','),',',':'),':') comb,level
    from L
    where level > 1
    connect by level =2 ;
    some candidate examles generated above code shown belown ( i interest only comb results values )
    comb
    1:1
    1:2
    1:3
    1:4
    1:5
    1:6
    2:1
    2:2
    6:1
    6:6
    I have another table called T2 shown below with some values
    TID     ITEM     CID     T_DATE
    1     b     1     05.05.1999
    1     c     1     05.05.1999
    2     e     1     17.05.1999
    3     d     2     13.05.1999
    4     b     2     19.05.1999
    4     c     2     19.05.1999
    5     d     2     21.05.1999
    6     a     3     07.05.1999
    6     b     3     07.05.1999
    7     d     3     15.05.1999
    7     e     3     15.05.1999
    8     b     4     11.05.1999
    8     c     4     11.05.1999
    9     c     4     16.05.1999
    now I want to test every items belong to candidate code generated above with item values of T2 table
    in test table T2 is grouped by CID and T_DATE. I want to compare items belong to current code with item of T2 table. if first item(s) in candidate combination is found in T2 table , second item(s) must be found too if there is. but this first and second item(s) together must be found same CID but at different T_DATE belong to that CID. if found, this candidate okey for me.for example we take candidate 3:1. items are d ( code 3 ) and b ( code 1 ) respectively. first item d is searched for CID = 1, it is not found. now we search item d for CID = 2 again , yes it is found in TID=3 row then we look another item b for CID=2 but item b must be found after d row for same CID and at different T_DATE. yes item d is found too for CID=2 after b item at different T_DATE in TID=4 row. that is we wants, is customer ( for example CID 2) buy item b after buying item d same customer at another time as sequence. second example may be candidate 5:6. is customer buy items b and c together ( for code 6) after at another time buying items d and e ( code 5 ) together by same customer
    NOTE : I use code field sequence values for pointer of items. items may be used directly on generating candidate process and used comparing process with T2 table
    thanks for smart idea....

    In addition I would suggest you read this:
    http://forums.oracle.com/forums/help.jspa
    and learn to use the tags to format the parts of the post that belong in fixed format.                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • The New Abap Debugger

    Hi everybody... In which SAP R/3 Version i can find the New Abap Debugger? Is this a new project that hasn't be implemented yet? Regards, Carlos Lerzundy

  • Acknowledgement for Idoc To File Scenario

    Hi Experts, My scenario is idoc to file and if the file is successfully delivered at destination then i need an acknowledgement saying that the file was received successfully. How to achieve this. Can any body send me the scenario with screen shots.

  • Calendar Sync in a mac

    Hi there, I've just converted my old BB to the new Q10. All seems fine, but it seem the calendar syncronization with my macbook is stopped working. In link 1.1.1.13 I cannot even find a calendar option. It's that normale behaviour?

  • ITunes freezes MacBook Pro after Mountain Lion reinstall

    A bad sector on my Macbook Pro (synched to my iMac) occurred within days of my first Mountain Lion update. I reinstalled Mountain lion, and used migration assistant with time machine to reinstall everything else. It was working for 8 hours when I dec

  • 6288 restarts in the tab view menu

    Hi! I have updated my branded (t-mobile- Germany) 6288 to the 6.43 firmware. So far it works. But whenever I am in the menu tab view and change the menu, eg from menu 1 to menu 7 by "scrolling" to the left or just one "scroll" to the right, the phone