Copy data from one table to the new table

Hello

I copy data from columns of a table to another table and my query is
INSERT INTO TestTable (empno, empName, deptno)
SELECT empno, empname, deptno
WCP

and it works fine but I want to insert a data column in testTable based on emp.deptno
as if emp.deptno = 10 it will add 1 to the testtable.class column,
If emp.deptno = 20 it will add 2-column testtable.class,
If deptno = 30 it will add 3 to the testtable.class column,


TestTable structure is
EMPNO NUMBER (20)
ENAME VARCHAR2 (50)
DEPTNO NUMBER (20)
CLASS NUMBER (20)

Can someone please help me write this procedure.
Thank you

You can use a case statement as

INSERT INTO TestTable (empno, empName,deptno,class_column )
SELECT empno, empname,deptno, case when emp.deptno=10  then 1
                                   when emp.deptno=20  then 2
                                   when emp.deptno=30  then 3
                              end
FROM emp

See you soon
Katia

Tags: Database

Similar Questions

  • Composite planning form, copy data from one tab to the other?

    This is something I've heard of someone who did but have not actually seen. The requirement is to copy data from an existing entity to a new entity as a means of values seedlings early in the budget cycle. I was thinking about a form of 'source' and a form of 'target' within a composite shape. A calc would make a copy. After copying the Scheduler can manually adjust values, or type values in the accounts that the source had no data.

    If someone did please let me know how you did and what looked like the calc.

    Thank you!

    FA

    Hello

    Yes, this can be done in several ways. The calc script would be similar to what is mentioned above. But in regards to the copy, you can also create a menu on the source form set a rule of company on the menu and start the copy that also offer users the ability to choose several invited outside of the entity if necessary.

    Thank you

  • Copy data from one schema to another. Reopen the Question

    Hello

    I had asked this question earlier to copy data from tables of one schema to another in the same database using the database link. In my previous post have mentioned below.
    Re: copy data from one schema to another.
    Now I am faced with the question for the remote copy of database

    I have created a DB connection between my local system and the remote database. with the chain of connection as shown below
    CREATE THE DATABASE PUBLIC LINK "MERU_DEV_LOCAL_DEV".
    CONNECT TO MERUDEV IDENTIFIED BY MERUDEV WITH THE HELP OF "MERUPROD";
    In the above script
    LOCAL DEVELOPMENT scheme IS
    REMOTE schema is MERUDEV
    I try to copy remote database to my local database tables using the script below.
    network_link DEVELOPMENT impdp = schema MERU_DEV_LOCAL_DEV = MERUDEV remap_schema = MERUDEV:DEVELOPMENT TABLE_EXISTS_ACTION = REPLACE
    But the copy of the table does not occur. What could be the problem? Please suggest me or do I need to modify the script

    Thank you
    Sudhir

    You can:
    -monitor the BONE with ps - ef
    -monitor data pump: jobs are dba_datapump_jobs and dba_datapump_sessions
    -monitor with logops: v$ session_longops

  • 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

  • copy data from one database to another

    Hello

    I want to copy data from one database to another.

    I have two patterns such as

    dev1/dev@ORCL
    DEV2/dev@DCEL


    I have same tables dev1 and dev2 (tables)
    but I have not given in dev2 (tables).
    now, I want to copy dev1 (tables) in dev2 (tables).

    You can also use the database link:

    select * from dev1.emp@orcl;
    

    What database are you connected to?
    You must create and use the links in the database for all other databases.

    For example if you are connected to the database A and to retrieve data from database B, you must create a connection of database in base B

    create database link B connect to  identified by  using 'B';
    

    Then you can retrieve data from database B with

    select * from [yourschema.]yourtable@B;
    

    This will work only for tables that are visible to the user that you used in the definition of database link.

    Published by: hm on 10.08.2011 22:15

  • Inserting data from one table to another table

    Hello

    I have the following SQL where I am updating a table by adding new data from another table, but without success.

    INSERT INTO
    () TOP_PROSPECTS
    COMMON_ID
    DATE_ADDED
    REVIEW_RANK
    EVAL_DATE
    PM_ASSIGN
    WHY_NOTES)
    SELECT
    t.COMMON_ID
    t.DATE_ADDED
    t.REVIEW_RANK
    t.EVAL_DATE
    t.PM_ASSIGN
    t.WHY_NOTES
    Of
    TEMP_IVAN_MARY t
    WHERE
    COMMON_ID <>t.COMMON_ID

    Any suggestions?

    Thank you.

    Published by: user13822709 on August 14, 2012 09:14

    Published by: user13822709 on August 14, 2012 09:15

    Is that what you're trying to do with the insert. I think there may be a sign {noformat}<{noformat}{noformat}>{noformat} missing in the where clause. This site eat those, so you need to use the equivalent! = post here.

    If I'm wrong about the missing trader, then it looks like you want to insert rows in temp_ivan_mary that are not already in top_prospects. If Yes, then you need something like:

    insert into top_prospects
       (common_id, date_added, review_rank, eval_date, pm_assign,
        why_notes)
    select t.common_id, t.date_added, t.review_rank, t.eval_date,
           t.pm_assign, t.why_notes
    from temp_ivan_mary t
    where t.common_id not in (select common_id from top_prospects
                              where common_id is not null)
    

    Function index and data available volumnes etc. then a mergr can be more effective. Something like:

    merge into top_prospects p
       using (select common_id, date_added, review_rank, eval_date,
                     pm_assign, why_notes
              from temp_ivan_mary) t
       on (p.common_id = t.common_id)
       when not matched then
          insert (common_id, date_added, review_rank, eval_date, pm_assign,
                  why_notes)
          values (t.common_id, t.date_added, t.review_rank, t.eval_date,
                  t.pm_assign, t.why_notes)
    from temp_ivan_mary t
    

    John

  • How to copy data from one hard drive to another after the upgrade?

    I have a HP e9220y, and I recently bought a new hard drive for it. There is nothing wrong with the former, but this one has a 64 MB cache and 7200 RPM so I hope it will be a little faster. I installed it and it works fine, but I want to copy all data from the old disk to the new so I can start everything off the faster hard drive and I seem to have a bit of doing wrong. I can't just copy and paste because of the Windows system files that are used. And last night when I set up Windows backup, and went to bed, when I thought it that Windows has recovered from a stop unexpected, rebooted, and only 2 GB of data saved obtained.

    What is the best way to move all the data from the old drive to the new drive, make it the default C: drive and move partitions system and factory_image as well? Thank you!

    Please read this link to another post made by Big_Dave and myself

    http://h30434.www3.HP.com/T5/desktop-hardware/hard-drive-imminent-failure-problem/TD-p/438567

    (1) If your old drive and the new drive is Seagate or Western Digital, then free House with their cloning software.

    (2) before starting the clone process, I found best to perform a disk cleanup and defragmentation.

    Cloning software to copy the two partitions. Example:

    Old drive 250 GB formatted to 232 C: created 220 and 12 GB D:

    New 1000GO drive formatted to 931 GB created 919 GB C: and D: to 12 GB

    The "Seagate disc Wizard" cloning software will let create you a clone automatic or manual partition resizing.

    The two modes to offer an overview of the actions before commit you. The manual on this page of Seagate (PDF) is 68 pages.

    After the cloning process he complete, all you have to do is swap on the disks. Besure to connect your new disc on the original motherboard SATA port.

  • Copy data from one to the other members of the siblings

    I have the hierarchy of entities such as:

    1234-abc-777

    -1234-abc-777-a11

    -1234-abc-777-b12

    -1234-abc-777-c15

    and I have to copy the benefit rate which present in 1234-abc - 777-> usd - > real-> 1234-abc-777 children final. I can't hard-code as I haved this type of hierarchy of 30.

    Is it possible to use any function to get 1234-abc-777-a11. I tried to use the function @Match dim crosswise but I receive the error message when running the script.

    Note:-a11 is common in any other hierarchy 30.

    Hello

    Glenn, I agree that it will create blocks that are not required if you use the DATACOPY approach. But it may be advantageous to have your rate to the level that you are calculating the data (but only for valid data of block combinations)

    The way I approach this kind of requirement is using this three-step process. I have a previous post where I posted a detailed script.

    1. set on RELATIVE("Entity",0), but delete the entities holding rates, in this case use a UDA called RATE_INPUT for example and assign to entities where you enter the rate.

    Then using calc dense 'rate' = #missing to clear the old values from rates against all entities not RATE_INPUT

    2 aggregate rate to the entity above, where the rate is entered. This will mean that the entity kinship is equal to the entity that has RATE_INPUT uda

    3. FIX on RELATIVE("Entity",0) but remove the entities holding rates

    Then using calc dense 'rate' = @PARENTVAL (Entity) to enter the tax rate of the parent.

    The advantage of this method is to push a rate only to entities that already have an existing block. So not more your database or the number of blocks

    Thank you

    Anthony

  • Datacopy do not copy data from one to the other in a sparse dimension.

    Hi I m using the following script data copy of Act scenario to the scenario Fcst1, but I can't recover the data after it's done. I understand that datacopy should new blocks if necessary to copy new data. Is - this datacapy cannot copy data if there is Fcst1 blocks already created for this intersection?

    Please help, I don't have any ideas to the left, I can't make a datacopy!

    ESS_LOCALE English_UnitedStates.Latin1@Binary
    UPDATECALC OFF SET;
    SET MSG SUMMARY;
    SET CLEARUPDATESTATUS AFTER;
    SET CALCPARALLEL 3;


    SET CREATENONMISSINGBLK


    Fix (@relative("Income_Statement",0),
    "FY09",.
    @Relative("Q1",0),
    'Local_Cur', 'USD')

    / * Copy the forecast data of the forecasts for the month - Jan, Feb and March Act * /.

    ClearData "Fcst1";

    DATACOPY 'Act' to 'Fcst1 ';

    ENDFIX

    CREATENONMISSINGBLK OFF SET;

    Yes, DATACOPY does not support dynamically calculated members. It's a pain.

    Without changing your code too, could do you:
    DATACOPY ActChild1 to TransCanada.
    DATACOPY ActChild1 to TransCanada.

    ↑ This will take care of creating block.

    Then:
    FCST = ActChild1 + ActChild2;

    ^ This should work without the parameter CREATENONMISSINGBLK DEFINED as two DATACOPY instructions will take care of that.

    Kind regards

    Cameron Lackpour

  • Error when copying data from a damaged to a new profile in Windows XP user profile

    Hello

    I think my user profile may be corrupted so I'm trying to create a new profile and copy the Ntuser files anywhere in the new profile by following the instructions in the Article ID: 811151.

    I created two new Admin accounts loged on my old account and connected to one of the new admin accounts.

    When I navigate to C : \Documents and Settings\ Old_Username  there are only two of the three files listed, NTUSER. DAT and Ntuser.dat.LOG, and both are slightly dimmed. When I copy these files and go in C : \Documents and Settings\ New_Username  I get an error saying "cannot copy NTUSER: it is used by another person or program." Close all programs that might be using the file and try again. »

    My home screen tells me that only the new admin account someone connected and when I go into the Task Manager there is no process running with my where ancien_nom_utilisateur, the entire SYSTEM and the new admin account?

    So, what I'm doing wrong, how to fix this and have is my Ntuser.ini file?

    Thank you very much...


    http://support.Microsoft.com/kb/811151

    Excerpt from the article below (note that it says "except the following files")...

    Press on and hold down the CTRL key while you click each file and subfolder in this folder, except the following files:

    • Ntuser.dat
    • Ntuser.dat.log
    • Ntuser.ini

    If I helped you overcome the "used" problem, you'd probably end the corruption of the copy!

  • Load data from one table to another

    Hi all

    Please help me for my sous condition.

    Oracle version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod

    Rules
    -------
    (1) first two city must be loaded in city_1 and city_2.
    (2) if there are more than two cities, only two must be loaded first.
    (3) if only a city_1 is set, it must be loaded in city_1.

    drop table seven_cities;
    
    create table seven_cities
    (id     number,
     city_1  varchar2(100),
     city_2  varchar2(100),
     city_3  varchar2(100),
     city_4  varchar2(100),
     city_5  varchar2(100),
     city_6  varchar2(100),
     city_7  varchar2(100)
     );
     
     
    insert into seven_cities(id,city_1,city_2,city_3,city_4,city_5,city_6,city_7)
    values (1,'New York',null,null,null,'Chicago',null,null);
    
    insert into seven_cities(id,city_1,city_2,city_3,city_4,city_5,city_6,city_7)
    values (2,null,'Hyderabad','Delhi','Mumbai',null,null,null);
    
    
    insert into seven_cities(id,city_1,city_2,city_3,city_4,city_5,city_6,city_7)
    values (3,null,null,null,null,null,null,'London');  
    
    insert into seven_cities(id,city_1,city_2,city_3,city_4,city_5,city_6,city_7)
    values (4,null,null,null,'Sydeny','Melbourne','Paris','Berlin');
    
    commit;
    
    select * from seven_cities;
    
    drop table two_cities;
    
    create table two_cities
    (id number,
     city_1  varchar2(100),
     city_2  varchar2(100));
     
     Expected data to be loaded
     ----------------------------
    
    id       city_1          city_2
    1     New York             Chicago
    2     Hyderabad             Delhi
    3     London          null
    4     Sydney          Melbourne
    Thank you
    Rambeau

    The one I have already posted in response to your message duplicate (next time please do not submit duplicate messages):

    select  id,
            coalesce(city_1,city_2,city_3,city_4,city_5,city_6,city_7) city_1,
            nvl2(
                 city_1,
                 coalesce(city_2,city_3,city_4,city_5,city_6,city_7),
                 nvl2(
                      city_2,
                      coalesce(city_3,city_4,city_5,city_6,city_7),
                      nvl2(
                           city_3,
                           coalesce(city_4,city_5,city_6,city_7),
                           nvl2(
                                city_4,
                                coalesce(city_5,city_6,city_7),
                                nvl2(
                                     city_5,
                                     coalesce(city_6,city_7),
                                     nvl2(
                                          city_6,
                                          city_7,
                                          null
                                         )
                                    )
                               )
                          )
                     )
                ) city_2
      from  seven_cities
    / 
    
     ID CITY_1     CITY_2
    --- ---------- ----------
      1 New York   Chicago
      2 Hyderabad  Delhi
      3 London
      4 Sydeny     Melbourne
    
    SQL>
    

    And this solution, you are prompted by the solution of Tubby:

    with t as (
               select  id,
                       row_number() over(partition by id order by rownum) rn,
                       column_value city_1,
                       lead(column_value) over(partition by id order by rownum) city_2
                 from  seven_cities,
                       table(sys.OdciVarchar2List(city_1,city_2,city_3,city_4,city_5,city_6,city_7))
                 where column_value is not null
              )
    select  id,
            city_1,
            city_2
      from  t
      where rn = 1
    /
    
     ID CITY_1     CITY_2
    --- ---------- ----------
      1 New York   Chicago
      2 Hyderabad  Delhi
      3 London
      4 Sydeny     Melbourne
    
    SQL> 
    

    And if there is a concern on the use of the items in the collection without papers are read in the order behaviour, just create object & nested table types:

    create or replace
      type num_str_obj
        as object(
                  n number,
                  s varchar2(4000)
                 )
    /
    create or replace
      type num_str_list
        as table of num_str_obj
    /
    

    Now:

    with t as (
               select  id,
                       row_number() over(partition by id order by n) rn,
                       s city_1,
                       lead(s) over(partition by id order by n) city_2
                 from  seven_cities,
                       table(
                             num_str_list(num_str_obj(1,city_1),
                                          num_str_obj(2,city_2),
                                          num_str_obj(3,city_3),
                                          num_str_obj(4,city_4),
                                          num_str_obj(5,city_5),
                                          num_str_obj(6,city_6),
                                          num_str_obj(7,city_7)
                                         )
                            )
                 where s is not null
              )
    select  id,
            city_1,
            city_2
      from  t
      where rn = 1
    /
    
     ID CITY_1     CITY_2
    --- ---------- ----------
      1 New York   Chicago
      2 Hyderabad  Delhi
      3 London
      4 Sydeny     Melbourne
    
    SQL> 
    

    SY.

  • Load data from one table into another table of 2 different schemes

    Hello

    We have a requirement to insert data into a table in a schema of a table that is in other schemas in ODI.

    We are able to do so by creating interfaces and mappings. But we now expect to do using SQL instead of ODI interfaces.

    Is it possible to do this using the SQL statements we have source and target data sources defined in ODI.

    should be like "Insert into src.table select * from tar.table'"

    Thank you...

    Hello

    If you try to load a db to another db using sql (sql free hand) instead of interfaces instructions.

    It is possible using procedures odi too.

    1. Select the project (designer navigator) odi mode

    2. create the new procedure. Then add the command.

    in this command on the source command on the tabs of the target.

    Enter the sql statements. See the screenshots below...

    I think this will help for you,

    Thank you best regards &,.

    A.Kavya

  • Corresponding to a set of data from one table to another

    I have a table - Table_1 with columns A, B, C, D, I have another (Table_2) table with columns B, C, D.

    I try to get all the rows in Table_1 where the values correspond to columns B, C, D.

    The catch here is that returned from TABLE_1 lines should be the same number of rows as in TABLE_2 and the value in TABLE_1 from 'A' should be the same for all these lines. So--Table_1 could return several sets of data where the VALUE of A is different for each SET but - the 'GAME' must match all other values in TABLE_2 exactly (including the number of lines for each game)...

    Any help is greatly appreciated. I hope that I said above clearly enough.

    -create tables

    create table t1 (a varchar2 (10), varchar2 (10) b, c varchar (10), varchar2 (10)) d;
    create table t2 (varchar2 (10) b, varchar2 (10) c, varchar (10)) d;

    -create data, 5 games in t1 with 2 correspondents sets

    insert into t2 values ('1 ', '2',' 3');
    insert into t2 values ('2 ', '2',' 3');
    insert into t2 values ('3 ', '2',' 3');
    insert into t1 values ('a', '1', ' 2 ', 3');
    insert into t1 values ('a', '2', ' 2 ', 3');
    insert into t1 values ('a', '3', ' 2 ', 3');
    insert into t1 values ('b', '1', ' 2 ', ' 3');
    insert into t1 values ('b', '2', ' 2 ', ' 3');
    insert into t1 values ('c', '1', ' 2 ', ' 3');
    insert into t1 values ('c', '2', ' 2 ', ' 3');
    insert into t1 values ('c', '3', ' 2 ', ' 3');
    insert into t1 values ('c', '4', ' 2 ', ' 3');
    insert into t1 values (has "', 1 ', ' 2 ', ' 3'");
    insert into t1 values (has "', 2 ', ' 2 ', ' 3'");
    insert into t1 values (has "', ' 3, ' 2 ', ' 3'");
    insert into t1 values ('e', '4', ' 2 ', ' 3');
    insert into t1 values ('e', '5', ' 2 ', ' 3');
    insert into t1 values ('e', '6', ' 2 ', ' 3');

    Select * from t1 where one (not in
    Select a from t1 where does not exist (select 1 from t2 where b = t1.b and c = t1.c and d = t1.d)
    Union
    Select one of (select one, count (*) NTC group by a t1) where NTC! = (select count (*) from t2)
    )

    A B C D
    ---------- ---------- ---------- ----------
    1 2 3
    2 2 3
    3-2-3
    1 2 3 d
    2 2 3 d
    3 2 3 d

    6 selected lines

  • Pass data from one page to the other

    Hi all, I'm doing an upload of CSV file in a database application, and I wonder if it is possible to transmit the data from the file field to another php file that performs the command insert the data from the csv file into the database? Thank you!!

    Wanqi

    Hi, good news! I managed to solve the problem. It turns out that the bug was the connotation of the variable. Thanks a lot for your help!

  • 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