records by inserting into one another table

Hi Masters

I have to insert records from table to table b, which do not exist in table b. Please, help me in this record.

create table test1 (eno number (2), ename varchar2 (10));

Insert into test1 values(1,'abc');
Insert into test1 values(2,'xyz');
Insert into test1 values(3,'pqr');
Insert into test1 values(4,'vara');

create table test2 (eno number (2), ename varchar2 (10));

Insert into test2 values(2,'xyz');
Insert into test2 values(4,'vara');

I tried like this...

SQL > get the ap;
1. INSERT ALL
2. WHEN r_num = 1
3 THEN IN VALUES test2 (eno, ename)
4 OTHER INTO test2 VALUES (null, null)
5. SELECT eno, ename
6, ROW_NUMBER () OVER (PARTITION BY eno, ename)
7 ORDER BY eNAME - or else
8                             )  AS r_num
9 * FROM test1
SQL > /.

4 lines were created.

SQL > select * from test2;

ENO ENAME
----- ----------
2 xyz
4 vara
1 abc
2 xyz
3 pqr
4 vara

6 selected lines.

the result above is not correct... Please advice.

Concerning

Evelyne

Use MERGE:

SQL > select * from test1;

ENO ENAME
---------- ----------
1 abc
2 xyz
3 pqr
4 vara

SQL > select * from test2;

ENO ENAME
---------- ----------
2 xyz
4 vara

SQL > fusion
2 in test2
3 using test1
4 you (test1.eno = test2.eno and test1.ename = test2.ename)
5 when not matched
6. then insert
7 values(test1.eno,test1.ename)
8.

2 lines merged.

SQL > select * from test2;

ENO ENAME
---------- ----------
2 xyz
4 vara
3 pqr
1 abc

SQL >

SY.

Tags: Database

Similar Questions

  • How can I insert data from another table into a table containing a timestamp column

    How you insert data from another table in a table if the target table contains a timestamp column. I tried to set the default value of GETDATE() column in the target table, but it does not work.


    I use MS SQL

    Sorry, I managed to get around this by inserting null as the value

  • Inserting into a temporary table

    Hi all

    I use this code to insert into a temporary table

    INSERT INTO VISIT_TEST

    (NO, VISIT_ID)

    VALUES

    (1,: ALL_ADMITTED_PATIENT.) VISIT_ID);  -guess: ALL_ADMITTED_PATIENT. VISIT_ID is another number.

    COMMIT;

    It inserts nothing,

    but when I try to insert all the values of pl/sql with the same way

    INSERT INTO VISIT_TEST (NO., VISIT_ID) VALUES (2, 4);

    It inserts with success.

    the code for creating the table of tempo is

    CREATE A VISIT_TEST GLOBAL TEMPORARY TABLE (NO NUMBER, NUMBER VISIT_ID) COMMIT PRESERVE ROWS

    Why does not insert on it data?

    PS: the whole issue is that I run a report from a form, and the query of the report is based on the temporary table.

    what I want to know is, when I run the report from inside my form, is considered a new session, and this is why the report cannot see the data in the table of tempo or am I wrong?

    Thank you

    > when I run the report of my form, which constitutes a new session, and this is why the report cannot see the data in the table of tempo, or am I wrong?

    You're not bad. Forms and reports use separate database sessions. Reports can not see TWG data entered via Forms module.

    Concerning

  • want my bitmaps to fade into one another

    I have built a header for my site and have exported the header with its 4 different images I want to fade each other, with the moving text on it and everything. My question is:
    How to set the interpolation for the bitmaps to fade into one another?
    they need to be converted in member countries? chart? they need to break?
    Help me please...
    Thanks in advance

    I'm usually just about everyone in a symbol. (Edit - covert to the symbol)
    Then, put each on a separate layer.
    take the one on the bottom layer and to make a new image more further along the timeline (say 50 frame) can do another keyframe on frame of 70.
    Select the 70 image, then select the image on the stage. Now in the properties panel, select "Alpha" in the color drop-down the menu drop down and slide it up to 0%.
    Then, select any setting between 50 and 70 frame and then right-click on it and select Create a motion tween.
    It fades your photo out.
    Now layer 2 move your photo along the frame of 50 and make a keyframe on frame of 70 and 100 frame.
    Back to the 50 frame select the image, select "Alpha" and make sure it is on 0%. Go to the section 70 and make sure tha photos alpha is 100%. Then recreate the motion tween.
    Now test your animation
    Hope this Helps
    See you soon
    Alan

  • Record is not inserted into the transparent Table Forms 10g

    Hi all

    I have the built in 10g (10.1.2.0.2) form.

    Basically, the form has 2 blocks.
    1 block with a single element, where we enter a value and press on enter (this place you block2 and run the query).
    Block 2 (tabular) will get the records. This block2 have now 3 columns (caseid, userid, date).

    Now when I insert a new record, I just need to get the caseid only. And username and date must be filled in automatically.
    I can fill fields username and the DATE.
    And when I enter a value element of the block 2 caseid and then Control + S(to insert the record and Save the transaction),.
    I get the message saying FRM-40400: transactions: 1 applied and saved records.
    But when I ask again for the same thing, I do not have is the record inserted into the table.
    Why is this happening?

    Help please...

    Drop the trigger for INSERTION WE (do not comment code or write NULL) and move your code to INSERT before trying.

    -Clément

  • Same question different results when insert into one table.

    Hello

    I have an insert statement as below.

    insert into mid_table_name
    Select seq.nextval key1, Field1, Field2,...)
    Select Field1, Field2 b.test2 a.test1...
    tab1 tab2 a and b
    where a.key1 = b.key1
    and...
    ...
    )

    When I run the present, it's inserting less files that actually, the subquery returns.

    I noticed that

    (1) when I run the subquery, illustrated below, it returns more than 60 lines of k which is what I expect.
    (select Field1, Field2 b.test2 a.test1...
    tab1 tab2 a and b
    where a.key1 = b.key1
    and...
    ...
    )

    (2) However, when I run including the outer query, showb below, it returns only about 8 k; the same is get inserted into the table.

    Select seq.nextval key1, Field1, Field2,...)
    Select Field1, Field2 b.test2 a.test1...
    tab1 tab2 a and b
    where a.key1 = b.key1
    and...
    ...
    )


    Any help will be greatly appreciated.

    Thank you
    Prep

    You can try this one.

    Select seq.nextval, ff.*
    Select * from)
    Select Field1, Field2 b.test2 a.test1...
    tab1 tab2 a and b
    where a.key1 = b.key1
    and...
    ...
    )
    FF

  • How to insert 10,000 records test data into the emp table

    Hi I am new to oracle can someone please help me write a program so that I can insert the test data into the emp table
    SELECT       LEVEL empno,
                 DBMS_RANDOM.string ('U', 20) emp_name,
                 TRUNC (DBMS_RANDOM.VALUE (10000, 100000), 2) sal,
                 DBMS_RANDOM.string ('U', 10) job,
                 TO_DATE ('1990-01-01', 'yyyy-mm-dd')
                 + TRUNC (DBMS_RANDOM.VALUE (1, 6000), 0)
                   hiredate,
                 CASE
                   WHEN LEVEL > 10 THEN TRUNC (DBMS_RANDOM.VALUE (1, 11), 0)
                   ELSE NULL
                 END
                   mgr,
                 TRUNC (DBMS_RANDOM.VALUE (1, 5), 0) deptno
    FROM         DUAL
    CONNECT BY   LEVEL <= 10000
    
  • insert into the summary table of the table.

    I was wondering if there is a smart way to do it with SQL, but I'm not sure. I would like to consult you yo guys.

    I have a table like this
     CREATE TABLE "TEMPLE_FINANCE"."TEST" 
       (     "COLUMN1" VARCHAR2(10 BYTE), 
         "COLUMN2" VARCHAR2(10 BYTE), 
         "COLUMN3" VARCHAR2(10 BYTE), 
         "COLUMN4" VARCHAR2(10 BYTE)
       ) ;
    
    
    Insert into TEST (COLUMN1,COLUMN2,COLUMN3,COLUMN4) values ('1','2','50.00',null);
    Insert into TEST (COLUMN1,COLUMN2,COLUMN3,COLUMN4) values ('1','2','50.00',null);
    I would like to at the rate of an update and you end up with
    "COLUMN1"     "COLUMN2"     "COLUMN3"     "COLUMN4"
    "1"                  "2"          "100.00"     
    What update statement can run for this?
    I would enter in the summary of the lines based on the column 1 and column2 and get rid of repeative lines.
    I have try this insert statement, but it's bascially just adding an extra record in the table.
    INSERT INTO  TEST (SELECT COLUMN1, COLUMN2, SUM(COLUMN3), COLUMN4 FROM TEST GROUP BY COLUMN1, COLUMN2,COLUMN4);
    any help would be grateful.

    Published by: mlov83 on January 25, 2013 12:45

    Published by: mlov83 on January 25, 2013 13:03

    Hello

    I can't help but wonder if you have the best design of table for what it is, you need to do.

    The best solution would be to create a new table, using the SUM (TO_NUMBER (Column3)) and GROUP BY, and then delete the original table and rename a new one to the old name. While you're at it, change Column3 as a NUMBER and add a primary key.

    In collaboration with just the existing table, INSERT one won't work. INSERT always adds new lines. You want something that can INSERT new lines (or update some existing routes) and DELETE lines at the same time. FUSION can do it all. Here's a way to use the MERGE:

    MERGE INTO     test     dst
    USING   (
              SELECT column1, column2, column4
              ,      SUM (TO_NUMBER (column3))
                                 OVER (PARTITION BY  column1, column2, column4)
                                AS column3_total
              ,      ROWID             AS r_id
              ,      MIN (ROWID) OVER (PARTITION BY  column1, column2, column4)
                                          AS min_r_id
              FROM    test
         )          src
    ON     (src.r_id     = dst.ROWID)
    WHEN MATCHED THEN UPDATE
    SET     dst.column3       = TO_CHAR ( src.column3_total
                                , 'FM9999999.00'
                            )
    DELETE
    WHERE     src.r_id     != src.min_r_id
    ;
    

    Published by: Frank Kulash on January 25, 2013 16:07

  • Select values from the db1 table and insert into the DB2 table

    Hello

    I have three databases oracle running in three different machines. their ip address is different. among the DB can access databases. (means am able to select values and insert values into tables individually.)

    I need to extract data from the DB1 table (ip say DB1 is 10.10.10.10 and the user is DB1user and the table is DB1user_table) and insert the values into DB2 table (say ip DB2 is 11.11.11.11 and the user is DB2user and table DB2user_table) of DB3 that is to have access to the two IPs DB.

    How do I do this

    Edited by: Aemunathan on February 10, 2010 23:12

    Depending on the amount of data must be moved between DB1 and DB2, and the frequency at which this should happen, you might consider the SQL * COPY more control. I think it's very useful for one-off tasks little, so I can live within its limits of the data type. More http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/apb.htm#i641251.

    Change some parameter of sqlplus session are almost mandatory in order to get decent transfer rates. Tuning ARRAYSIZE and COPYCOMMIT can make a huge difference in flow. LONG change may be necessary, too, depending on your data. The documentation offers these notes on use:

    To activate the copy of data between Oracle and databases non-Oracle, NUMBER of columns is replaced by DECIMAL columns in the destination table. Therefore, if you are copying between Oracle databases, a NUMBER column with no precision will become a DECIMAL column (38). When copying between Oracle databases, you must use SQL commands (CREATE TABLE AS and INSERTION), or you must make sure that your columns have a specified precision.

    SQL * the VALUE LONGER variable limits the length of the LONG column you are copying. If all LONG columns contain data exceeds the value of LONG, COPY truncates the data.

    SQL * Plus performs a validation at the end of each successful COPY. If you set the SQL * variable more COPYCOMMIT DEFINED to a value positive n, SQL * Plus performs a validation after copying all lots n of records. The SQL * Plus ARRAYSIZE variable SET determines the size of a batch.

    Some operating environments require that the service names be placed between double quotes.

    From a SQL * Plus term on DB3, can resemble the command to move all content from my_table in DB1 to the same table in DB2

    COPY from user1/pass1@DB1 to user2/pass2@DB2 -
    INSERT INTO my_table -
    USING select * from my_table
    

    Note the SQL code * more line-continuation character ' - '. It is used to escape the newline character in a SQL * Plus command if you do not have to type all on one line. I use it all the time with this command, but I can't locate the documentation on that right now. Maybe someone else can put their finger on it.

    There are other ways to accomplish what the command copy and it is not without its quirks and limitations, but I find that there is usefulness in an Oracle Toolbox.

  • Splitting words before inserting into the new table

    SQL> desc company
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     CO_ID                                     NOT NULL NUMBER(9)
     R_DATE                                             TIMESTAMP(0)
     CONAME                                             VARCHAR2(140)
     ESTYR                                              NUMBER(5)
     COUNTRY                                            VARCHAR2(32)
     PRODUCTS                                           VARCHAR2(3900)
    
    SQL> select unique(products) from company where rownum<6;
    
    PRODUCTS
    --------------------------------------------------------------------------------
    bars,tubes,pre-weld seams,isosceles and un-isosceles angles,special profiles,u-p
    rofiles,plates,t-profiles,flanges,tube fittings,round,hollow bars,double-t-profi
    les (ipe und ipb),pipe clamps,flat,special designs according to drawings for new
     products,profiles for floor covering,hexagon
    
    carbon steel bright bars,tool steel bright bars,alloy steel bright bars,stainles
    s steel bright bars
    
    cold rolled coil,e.g sheet,prepainted sheet,galvalume coil,copper scrap,stainles
    s steel sheet,shredded scrap,hms1 and 2,cobalt ore,rail scrap,hot rolled coil,ga
    lvanized sheet,iron ore
    
    PRODUCTS
    --------------------------------------------------------------------------------
    
    ferro alloy producer
    switch technology,special tubes,rails,steel strip,special steel
    I created another table:
    crate table keywords(
    k_id number(14),
    keywords varchar2(500) unique
    );
    
    create sequence keywords_pk_seq
    start with 3484 increment by 1;
    
    create or replace trigger keywords_pk_trig
    before insert on keywords
    referencing new as new
    for each row
    begin
    select keywords_pk_seq.nextval into :new.k_id
    from dual;
    end;
    /
    I want to:
    one) to split columns of company.products where is comma (,) for example, bars, tubes, pre-soudures, tubes will became 4 different as words:
    bars
    tubes
    welds
    tubes

    (b) then I want to insert these words in the table keywords.keywords with condition separated by ignoring the existing keywords.keywords (e.g. tubes came twice, let's get just a tubes) for example
    k_id keywords
    1 bars
    2 tubes
    3 before welding

    Thank you and best regards

    You can use the merge statement:

    for example

    merge into keywords
    using (
    with t as (select 'pipes,taps,spanner,spade,tubes' as txt from dual)
    -- end of sample data
      select distinct REGEXP_SUBSTR (txt, '[^,]+', 1, level) kw
      from t
      connect by level <= length(regexp_replace(txt,'[^,]*'))+1
      ) x
     on (keywords.keyword = x.kw)
    when not matched then insert (id, keyword) values (key_seq.nextval, x.kw)
    /
    

    But keep in mind that the sequence in this example will be updated for each line independently to know if she gets inserted or not.
    If you set the ID using a sequence triggered when inserting then this will solve this problem.

  • insert into a final table based on a condition

    Hello
    create table table1(invoice_number varchar2(4), covg_date date, employee_number varchar2(5),
     service_option varchar2(2), FEES VARCHAR2(5), AMOUNT NUMBER(9,2));
     
    insert into table1 values('1','01-JUL-2011','11','8','F1,F2',100);
    insert into table1 values('2','01-JUL-2011','12','2','F1,F2',110);
    insert into table1 values('3','01-JUL-2011','13','9','F1,F2',120);
    insert into table1 values('4','01-JUL-2011','14','3','F1,F2',130);
    commit;
    
    create table table2(invoice_number varchar2(4), covg_date date, employee_number varchar2(5), 
    service_option varchar2(2),FEES VARCHAR2(5), AMOUNT NUMBER(9,2));
    
    insert into table2 values('1','01-JUL-2011','11','88','F1,F2',100);
    insert into table2 values('2','01-JUL-2011','12','2','F1,F2',110);
    insert into table2 values('3','01-JUL-2011','13','9','F1,F2',122);
    insert into table2 values('4','01-JUL-2011','14','3','F1',130);
    insert into table2 values('4','01-JUL-2011','15','3','F1',130);
    commit;
    
    create table final_table(insert_type varchar2(1),invoice_number varchar2(4), covg_date date, employee_number varchar2(5), 
    service_option varchar2(2),FEES VARCHAR2(5), AMOUNT NUMBER(9,2));
    We need to insert in final_table based on the differences between table1 and table2. The condition for this is:
    For example: for a given employee number (11) for a covg_date(July-2011) given, if there is at least a difference in any value of the column that is in this case the service_option (8.88)...
    I need to insert record from table1 into final_table with insert_type as 'ELDERS '.
    and insert record of table2 in final_table with insert_type as 'NEW '.

    Same employee number 14, there is a difference between column fees and I should insert as in the example above
    Same employee number 13, there is a difference between the column AMOUNT and I must insert as in the example above.

    For example employee number 15, there is no record in table1 but found in table2 and which will be inserted as it is...

    What my idea was to go through separate employee_number, covg_date in table1 and check every value in table2 to the same disease and insert into final_table...

    But if there is a better option as insertion directly using select clause or a sort of direct insertion without loop...

    Thanks for the help in advance

    Maybe a modified version of something like this:

    INSERT INTO final_table
    ( insert_type
    , invoice_number
    , covg_date
    , employee_number
    , service_option
    , fees
    , amount
    )
    SELECT insert_type
         , invoice_number
         , covg_date
         , employee_number
         , service_option
         , fees
         , amount
    FROM   (
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'OLD' AS insert_type
         FROM   table1
         MINUS
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'OLD' AS insert_type
         FROM   table2
         UNION ALL
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'NEW' AS insert_type
         FROM   table2
         MINUS
         SELECT invoice_number
              , covg_date
              , employee_number
              , service_option
              , fees
              , amount
              , 'NEW' AS insert_type
         FROM   table1
           )
    WHERE  employee_number = :emp_number
    AND    covg_date       = TO_DATE(:date_string,'MM/DD/YYYY')
    ;
    
  • delete records that are related to another table

    I want to delete records from a table (A), these recordings has a relationship with another table (B)

    using a query to set these records is that I want to delete

    with B as
    (
    f select '2', '3' l double
    Union of all the
    f select '2', '3' l double
    Union of all the
    f select '4', '4' l double
    )


    Select * from A, B
    where B.f() > 3 and b. > 3
    and A.f. = B.f()
    and A.l = b.

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production


    Thanks in advance!

    Hello

    Here's one way:

    DELETE     a
    WHERE     f     > 3
    AND     l     > 3
    AND     (f, l)     IN (
                   SELECT  f, l
                   FROM     b
                     )
    ;
    
  • "missing the SELECT keyword" error during an insert into the temporary table using the blob value

    I'm trying to insert into an oracle temp table using select that retrieves data from a blob field but I get the error: "lack the SELECT keyword.

    How we store temporary in oracle result when we make this type of operation (extraction of data in fields and try to load them into a separate table on the fly.?)

    with cte as)

    Select user_id, utl_raw.cast_to_varchar2 (dbms_lob.substr (PREFERENCES)) as USER my_blob

    )

    create table new_table as

    SELECT user_id,EXTRACTvalue(xmltype(e.my_blob),'/preferences/locale') regional settings

    E ETC

    ----------------------------------------------------------------------------------

    BLOB data - value - which is

    <? XML version = "1.0" encoding = "ISO-8859-1" ?>

    - < Preferences >

    < time zone > America/New_York < / > zone

    < displayscheduleinusertimezone > Y < / displayscheduleinusertimezone >

    < local > Spanish < /locale >

    < DateFormat > JJ/mm/aaaa < / DateFormat >

    < timeFormat > hh: mm aaa < / timeFormat >

    < longformat > Long_01 < / longformat >

    < doubleformat > Double_01 < / doubleformat >

    < percentformat > Percentage_01 < / percentformat >

    < currencyformat > Currency_01 < / currencyformat >

    < / Preferences >

    A WITH clause that must immediately precede the SELECT keyword:

    SQL > create table t:

    2 with the o as (select double dummy)

    3 select * West longitude;

    Table created.

  • Duplicate records and modify data in another table

    First of all, I have two tables (CUSTOMER and ADDRESS) with the following definition:

    CUSTOMER has 7 columns (aa, ab, ac, ad, ae, af, ag)

    AA is the primary key

    AE, af, ag are the duplicate columns and he should be arrested by ae, af, ag

    a foreign key between the CUSTOMER and ADDRESS

    ADDRESS has 5 columns (bb, bc, bd, aa)

    BB is the primary key

    Here is an example of the content at the start

    CUSTOMER

    AA ab ac ad ae af ag

    12 432 23 44 32 22 44

    13 32 33 213 32 22 44

    14 321 22 22 17 21 33

    15 22 43 90 17 21 33

    16 21 23 94 17 21 33

    ADDRESS

    BB bc bd be aa

    17 321 33 23 12

    18 123 32 22 13

    20 22 23 34 14

    21 22 21 22 15

    22 12 34 22 16

    And the result,

    CUSTOMER

    AA ab ac ad ae af ag

    12 432 23 44 32 22 44

    14 321 22 22 17 21 33

    ADDRESS

    BB bc bd be aa

    17 321 33 23 12

    18 123 32 22 12

    20 22 23 34 14

    21 22 21 22 14

    22 12 34 22 14

    How could I do with SQL?

    Hello

    user10681153 wrote:

    ...
    INSERT INTO CUSTOMERS VALUES (12,432,23,44,32,22,44);

    INSERT INTO CUSTOMERS VALUES (13,32,33,213,32,22,44);

    INSERT INTO CUSTOMERS VALUES (14,321,22,22,17,21,33);

    INSERT INTO CUSTOMERS VALUES (15,22,43,90,17,21,33);

    INSERT INTO CUSTOMERS VALUES (16,21,23,94,17,21,33);

    INSERT INTO THE ADDRESS VALUES (17,321,33,23,12);

    INSERT INTO THE ADDRESS VALUES (20,22,23,34,14);

    INSERT INTO THE ADDRESS VALUES (21,22,21,22,15);

    INSERT INTO THE ADDRESS VALUES (22,12,34,22,16);

    In your original message, there are 5 rows in address; now, there are only 4.  In light of these new data, I guess that the results you origianlly displayed for the customer are always the same, but the results that you want to start address are now:

    BB BC BD BE AA

    ---------- ---------- ---------- ---------- ----------

    17 321 33 23 12

    20 22 23 34 14

    21 22 21 22 14

    22 12 34 22 14

    I don't see anything wrong with my previous solution.  Do you have?

  • Insert values from another table

    Hello I have a table:

    T1
    ---
    ID
    user

    and another table:
    T2
    ---
    intellectual property
    Mac

    So I modified T1:
    ALTER table T1 add ip number (20);
    ALTER table T1 add mac number (20);

    So I have:
    T1
    ---
    ID
    user
    intellectual property
    Mac

    T1 and T2 are the same number of lines.

    Now, I want to insert the values of IP and mac of T2 in the fields ip address and mac of T1.
    IP and mac of T2 fields can be "not null".

    How can I do?

    Thanks in advance

    and what do you think about something like this:

    UPDATE t1
       SET t1.mac =
           (SELECT t2.mac FROM t2 WHERE t2.id = t1.id),
           t1.ip =
           (SELECT t2.ip FROM t2 WHERE t2.id = t1.id)
    

    Give it a shot... validate the results before stolen.

    HTH,
    Thierry

Maybe you are looking for