Insert the record of one table to another with the help of the cursor

Help, please!

the tables are - 1. countries (country_id pk, country_name, region_id)
2A (country_id, country_name, region_id)
table data are
1 to 1
2 b 2
3 C 3
NULL d 4
5 e 5
6 f 6
7 g 7
-----------------------
Insert the record in the table a country table with the help of the cursor, insert all the non-null records.
This procedure does not correct result
-----------------------

create or replace
Amit procedure as
cursor c1 is select * from a;
RW a % rowtype;
Start
Open c1;
Fetch c1 into rw.
While (C1% found)
loop
insert into countries values (rw.country_id, rw.country_name, rw.region_id);
commit;
Fetch c1 into rw.
If rw.country_id is null then
Fetch c1 into rw.
end if;
end loop;
Close c1;
exception
while others then
dbms_output.put_line ('exception = name ' |) RW.country_name);
end;

You don't need cursor at all;

create or replace procedure amit as

begin
  insert into countries (Country_ID, Country_Name, Region_ID)
  (select a.Country_ID
         ,a.Country_Name
         ,a.Region_ID
   from a
  );

  dbms_output.put_line('Rows inserted : ' || sql%rowcount);

  commit;

end;
/

Tags: Database

Similar Questions

  • Insert records from one table to another table

    Hello

    I want to insert all records in table 1 which are not in table 2 in table2

    o/p
    Insert into table2
    Select * from table1
    where a.id! = b.id;

    Please let me know is there any way I can complete reviews
    insert
      into table2
      select  *
        from  table1
        where id not in (
                         select  id
                           from  table2
                        );
    

    SY.

  • Shutter button to copy records from one table to another;  ORA-04091:

    Hello

    I am trying to create a trigger that will move data from one table to the other.

    I have two tables (Trial1, Trial2) two of them contains the same attributes (code, c_index)

    I want to spend each new record inserted in (code Trial1) (code in Trial2)

    It's my trigger:
    Create or replace trigger trg_move_to_trial2
    After Insert on Trial1
    for each row
    Start
    insert into Trial2 (code)
    Select: new.code of Trial1;
    end;
    He compiled, but when I insert a new record (the code) in (Trial1), it shows this error:
    Error report:
    SQL error: ORA-04091: table STU101. TRIAL1 is changing, function of triggering/can not see
    ORA-06512: at "STU101. TRG_MOVE_TO_TRIAL2', line 3
    ORA-04088: error during execution of trigger ' STU101. TRG_MOVE_TO_TRIAL2'
    04091 00000 - "table %s.%s is changing, function of triggering/can not see.
    * Cause: A trigger (or plsql user-defined function that is referenced in)
    This statement) attempted to watch (or modify) a table that has been
    in the Middle being modified by the statement that shot.
    * Action: Rewrite the trigger (or function) so it does not read this table.
    I know matter what it means error, but I did not how to fix the error.

    ..................................................................................................

    I tried to change the (insert after on Trial1) before (insert on Trial1); It worked, but not in a good way. When I insert value in (code Trial1) new and refreshed Trial2 table, just as much as the records I have 2 test they will be duplicated. For example
    Trial2
    code
    111
    222
    333
    when I insert in Trial1
    Trial1
    code
    444
    Trial2 will be:
    code
    111
    222
    333
    444
    444
    444
    can you please tell me how to fix this?

    Kind regards

    Published by: 1002059 on April 23, 2013 17:36

    You should not select Trial1 - you already have data. Simply insert this value.

    Create or replace trigger trg_move_to_trial2
    After insert on Trial1
    for each row
    
    begin
    
    insert into Trial2 (code)
    values (:new.code);
    
    end; 
    

    Kind regards
    David

  • How replicates all records from one table to another table without using expdp, impdp

    Hi I have two database in a database, that I have a table called t1 and another base data, I have the second table .so, my first table have records, that I need to transfer all records second T2 without use of expdp and impdp in every 5 min... what I do

    ??

    The best solution for this scenario is to use Oracle Golden Gate

    However, it requires a license, and you must pay for it.

    If this is not possible, you can create a job scheduler that uses a link DB in order to reproduce the recordings of the target database, but it will take the entire table to the target database and then INSERT AS SELECT truncate the data of the entire table every time that the job is running (because you can't follow only the records that have been changed or modified).

    In addition, read here on the replication of data using materialized views.

  • ORA-00904: "RENEWED_FD." "' OLD_FDR_NO ': invalid identifier...... HOW table TO INSERT SEVERAL ROWS of ONE TABLE to ANOTHER.

    Hi all

    I have two tables RENEWED_FD and KEC_FDACCT_MSTR.

    In the RENEWED_FD table, there are columns namely OLD_FDR_NO, ACCT_CUST_CODE, ACCT_TYPE, QUANTITY.

    In the KEC_FDACCT_MSTR table, there are columns namely ACCT_FD_NO, ACCT_CUST_CODE, ACCT_TYPE, QUANTITY.

    In the RENEWED_FD table, OLD_FDR_NO is present and rest all columns are empty, so I want to insert all other values of column in table KEC_FDACCT_MSTR

    where RENEWED_FD. OLD_FDR_NO = KEC_FDACCT_MSTR. ACCT_FD_NO.

    How to do this in Toad for ORACLE FORMS 6i or Oracle?

    Help me

    Thank you.

    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production


    I tried with the following code:

    Code:

    INSERT INTO RENEWED_FD

    (ACCT_CUST_CODE, ACCT_TYPE, SUM)

    SELECT ACCT_CUST_CODE, ACCT_TYPE, AMOUNT

    OF KEC_FDACCT_MSTR

    WHERE RENEWED_FD. OLD_FDR_NO = KEC_FDACCT_MSTR. ACCT_FD_NO;

    But I got this error:

    ORA-00904: "RENEWED_FD." "" OLD_FDR_NO ": invalid identifier

    Oh, you're on 9i db. In 9i the MATCHED and UNMATCHED aren't optional, and you must use both. FUSION has evolved through time, and it's a shame that you cannot make the most out of it because of your version.

    You use better UPDATE statement then.

    update of renewed_fd one

    Set)

    a.acct_cust_code

    a.acct_type

    a.amount

    ) =

    (

    Select b.acct_cust_code

    b.acct_type

    b.amount

    of kec_fdacct_mstr b

    where a.old_fdr_no = b.acct_fd_no

    )

    where

    There are)

    Select null

    of kec_fdacct_mstr b

    where a.old_fdr_no = b.acct_fd_no

    )

  • to add records to one table from another

    Hello gurus

    I have a table in which I have a few files... now, I want to add in the documents of table A of another table B has the same structure and columns.

    Y at - it a command for it
    insert into A
    select * from B;
    
  • Insert a value in one table to another

    Hello.

    I had created a deptEO and a dept1VO and also created a VO with querry editable deptupVO.,.
    I moved the table in the form of the master of secondary table
    master form of shaped table and dept1VO deptEO

    My scenario:

    When the user clicks the Enter button

    all the values in the table of empEO must be inserted in the emp1VO;

    How can I do this

    Published by: wilhelm wundt, the Aug 30, 2011 22:29

    Sorry that this is the method

    c1.first();
    
  • Copy from one table to another

    Is there a simple way to copy/add all the records from one table to a master table?

    INSERT INTO master_table (Field1, Field2, field3)
    SELECT field1, Field2, field3
    From other_table
    WHERE everything what

    If the data types, order and the column names are the same for both tables, then it would also work to copy all other_table lines in master_table:

    INSERT INTO master_table
    SELECT *.
    From other_table

    Phil

  • How can I insert a snapshot from one pdf to another format?

    How can I insert a snapshot from one pdf to another format?

    Hey Rodney,

    (1) Please open the pdf you want to take the picture, go to Edition & select Take Snapshot. )

    (2) make drag & select the area of the pdf file, you need to take the snapshot using your mouse.

    (3) now paste the snapshot into the paint & save it.

    (4) open the second pdf file where you want to place the snapshot in pdf editing mode, now add the image of the snapshot using the option 'Add images' on the desired place.

    Let me know if or even meet any problem.

    Kind regards

    Nicos

  • I am suddenly unable to rename folders. Insert the cursor, but it does not respond when I type characters, or even when I hit him back out. Know a simple fix?

    After cropping of a photo with Photoshop I discovered that I was unable to rename.  I soon found out that the same thing is true when I tried to rename main folders in My Documents.  I am able to insert the cursor, but it does not respond when I type characters, or even when I hit him back out.  Know a simple fix?

    Name change is a directory operation.  It would seem that you have read and write access to your directories, but you do not change access.  This highlights a problem with file permissions.  How is 'Simple' the fix depends on which version of Windows you have to a certain extent.

    Windows XP Pro (with "Simple file sharing" turned off) using the security"" tab. When you right-click on a file or a folder and select 'Properties', then click on the 'Security' tab to view and change the permissions.

    "How to disable the file sharing simple and how to set permissions on a shared folder in Windows XP"
      <>http://support.Microsoft.com/kb/307874 >

    Windows XP Home Edition is a bit more complicated.  You can start safe mode and log in as administrator for the 'Security' tab as above, or you can open a command prompt window (start-> Run-> "cmd") and allows you to display the 'cacls' command or change the permissions of files and folders.  You should check that your username has permission to ull 'F' for your records.  Not pretty, but it works.

    CACLS: <> http://technet.microsoft.com/en-us/library/bb490872.aspx >

    HTH,
    JW

  • Correspondence of the columns from one table to another

    I have a database column that contains the name of a person. I have another table that has a column that contains the names separated by a comma.

    I want to match records where all records of two columns have a corresponding name. I tried this:

    < cfquery name = "MyQuery" datasource = "myds" >

    SELECT *.

    OF TBL_A

    WHERE TBL_A.customername IN (#DifferentQuery.ListOfNames #)

    < / cfquery >

    Everything that I try results in only get a recording. Basically, I want to get all records from a table where one of its columns contains the name of a column in another table.

    It's a many-to-many relationship. That is to say an editorial can be linked to many ads, and vice versa.  He is best represented with three tables. Such as:

    Table: [Editorial] column: [EditorialID (PK), EditorialText,...]

    Table: Columns of the [advertiser]: [AdvertiserID (PK), AdvertiserName]

    Table:   [Editorial_Advertisers] columns: [EditorialID, AdvertiserID]

    The name of the advertiser throw himself into a column...

    my client can decide which ads get related to which editorials

    The third table stores the relationship between ads and editorials.  So instead of storing a list of advertisers, you need to insert record for each EditorialID + AdvertiserID combination. You can then use joins to retrieve all the advertisements for EditorialID 123.

    SELECT  a.AdvertiserName
    FROM     Editorial_Advertiser ea INNER JOIN Advertiser a ON ea.AdvertiserID = a.AdvertiserID
    WHERE   ea.EditorialID = 123
    
  • Insertion of one table to another is too slow

    I have 129975 records in a table. I'm trying to transfer to another table. It was 50 minutes, and the process is still ongoing. What could be the problem? Index can solve this problem? Please give me the code.
    Thank you

    What awaits the session? Don't know how to check it

    Your DBA knows how to check: a TRACE/TKPROF with wait events (10046 level)

    SQL and PL/SQL FAQ
    Read the explanations of these links:
    -When your query takes too long...
    -How to send a SQL tuning request

  • Copy all the BLOBs from one table to another

    Hi all

    I hope that I put in the right place. I am trying to copy from one table to the other BLOBs, but were usuccessful. Here is the script that I wrote to do, but it just loaded a field saying not supported. Is there something I'm missing, I'm using the APEX 3.1.2.

    Thanks for your help.

    DECLARE
    number of v_id;
    v_document blob.
    v_filename varchar2 (200);
    v_mimetype varchar2 (200);



    CURSOR c_Document IS
    SELECT id, name of the document file, mimetype
    IN v_id, v_document, v_filename, v_mimetype

    OF CAB_APPEAL_ACTIONS
    WHEN THE DOCUMENT IS NOT NULL;

    BEGIN

    FOR r_Document in c_Document
    LOOP
    INSERT INTO CAB_APPEAL_DOCUMENTS
    (APPEAL_ACTION_ID,
    DOCUMENT,
    FILE NAME,
    MIMETYPE
    )
    VALUES
    (v_id,
    v_document,
    v_filename,
    v_mimetype
    );

    END LOOP;

    END;

    In addition, what is wrong with just...

    INSERT INTO CAB_APPEAL_DOCUMENTS (APPEAL_ACTION_ID,
                                      DOCUMENT,
                                      FILENAME,
                                      MIMETYPE)
       SELECT   id,
                document,
                filename,
                mimetype
         FROM   CAB_APPEAL_ACTIONS
        WHERE   DOCUMENT IS NOT NULL;
    

    APEX will end process page in a BEGIN block... END; block anyway.

    See you soon

    Ben

  • Inserting data into one table to another table.

    Hi all

    I'm having a few problems when copying data from the 1 table to another table. I have a data 1 date in a table, and I want to insert data in a partition of the main table. As it is the dev database space by getting a problem. I don't have enough space that I can maintain the data for the same date in 2 places.

    Here every way possible in oracle this 1 table may be made partition in the other table. (Just a question).

    Please suggest me a way out and if possible should be fast that data are more than 50 million lines and size along 10 GB.

    Thank you

    Are the columns of your source table identical to that of the destination partitioned table?

    If so, you can create an empty partition in the partitioned table and then create a swap partition to swap the source with the new empty partition table.

  • Insert data from one table to another

    I have two tables SALES_MASTER and SALESMAN_MASTER which is described below.

    SQL > desc SALES_MASTER;
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    NO VARCHAR2 (6)
    NAME VARCHAR2 (20)
    PIN NUMBER (8)
    CITY VARCHAR2 (20)
    VARCHAR2 (20) STATE



    SQL > desc SALESMAN_MASTER;
    Name Null? Type
    ----------------------------------------- -------- -----------------------
    SALESMANNO VARCHAR2 (6)
    SALESMANNAME VARCHAR2 (20)
    ADDRESS1 VARCHAR2 (30)
    ADDRESS2 VARCHAR2 (30)
    CITY VARCHAR2 (20)
    PIN NUMBER (8)
    VARCHAR2 (20) STATE
    SALAMT NUMBER (8.2)
    TGTTOGET NUMBER (6.2)
    YTDSALES NUMBER (6.2)
    REMARKS VARCHAR2 (60)

    I want to insert data from SALESMAN_MASTER (2nnd table) to SALES_MASTER(first table). I want to insert only two columns NO, NAME and PIN code. All of these columns are compatible. I tried this command. But it's not working. Help me.

    SQL > insert into SALES_MASTER
    2 (NO., NAME, PIN CODE)
    3 values
    4. Select SALESMANNO, SALESMANNAME, PIN code
    5 SALESMAN_MASTER;
    Select SALESMANNO, SALESMANNAME, PIN code
    *
    ERROR on line 4:
    ORA-00936: lack of expression
    INSERT INTO SALES_MASTER
       ( NO
       , Name
       , PINCODE )
       SELECT SALESMANNO
            , SALESMANNAME
            , PINCODE
         FROM SALESMAN_MASTER;
    

    Kind regards
    Christian Balz

Maybe you are looking for