Insert the records of 2 tables in tables.

Hi all
I have 3 tables as below
SQL > desc a1
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 NUMBER (20)
COL2 VARCHAR2 (10)

SQL > desc a2
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 NUMBER (20)
COL2 VARCHAR2 (10)

SQL > c1 desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 NUMBER (20)
COL2 VARCHAR2 (10)

Now, I want to insert records from a1 and a2 in c1 with the help of a unique sql. Please can someone give me the sql statement.

Thank you...

Hello

Example:

insert into tab3
select * from tab2
union all
select * from tab1;

Bartek

Tags: Database

Similar Questions

  • 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;
    /
    
  • Update trigger that inserts the record in another table

    I searched the forum and the web for an example like this and I can not find a:

    A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.

    I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
    Thanks in advance.

    Hello

    You can specify that the trigger should fire only when certain columns are referenced, like this:

    create or replace trigger test_fund_trig
    before update OF FUNDING
    on table_a
    ...
    

    If you do this, the trigger will not draw on statements such as:

    UPDATE  table_a
    SET     mod_date = SYSDATE;
    

    You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.

  • delete all the records in a table, the speed of insertion is not change.

    I have an empty table, and I insert a record need 100ms.
    During this table a 40,0000 trace, I insert a record need 1 s, it's ok, because I need to make a comparison according to an index before inserting a record need, so more record, more time.
    The problem is when I delete all the record in this table, the insertion time is always 1s, not reduce to 100ms. Why?

    Hello

    Read this part of the oracle documentation

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/logical.htm#CNCPT004

    The reason is always 1s, because when you inserted 400ko record as HWM (high tide is the border between old and new space in a segment.) moved to the top. And when you remove all records of your HWM still in the same coordinate system and that you have not reset to 0. So when you insert 1 it save free space and after finding faces (usually a regular insertions got 6 steps it inserts data). If you truncate your table you and try it again it will be faster that your HWM is reset to 0.

    Concerning

  • Insert the record type

    Hi all

    I created a table with two columns method. I am assigned two values to variable recordtype.
    When inserting the record in the table, a compiler error is to be there.
    Create table emp_info(empno number(5),ename varchar2(30));
    
    DECLARE
    
    l_rec emp_info%rowtype;
    
    BEGIN
    
    l_rec.empno := 101;
    l_rec.ename := 'KING';
    
    insert into emp_info(empno,ename)
    values(l_rec);
    
    commit;
    
    END;
    ERROR on line 11:
    ORA-06550: line 10, column 35:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 10, column 1:
    PL/SQL: SQL statement ignored


    Can I insert with output Recordtype variables indicating the column names. Can someone help me?

    Do not list of columns. Do not put brackets in the record variable:

    SQL> DECLARE
      2      l_rec emp_info%rowtype;
      3  BEGIN
      4      l_rec.empno := 101;
      5      l_rec.ename := 'KING';
      6      insert
      7        into emp_info
      8        values l_rec;
      9       commit;
     10  END;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • Insert the record in the second table by making the trigger on the first table

    I hv created 2 tables as shown below the code sql. I want to insert some record (line current value) column of the first table, next sequence value and sysdate into second table. I hv created trigger but I gave warning.
    so I want to know what is the problem in my sql code.
    Pls correct!

    SQL > create table myuser1 (u_id varchar2 (10), uname varchar2 (20), sex char(1));

    SQL > create table myuser2 (reg_no number (5), reg_date Date, u_id varchar2 (20));

    SQL > create the sequence myuser2_seq;

    SQL > alter table myuser1 add constraint pk_myuser1 key (u_id) primary;

    SQL > alter table myuser2 add constraint pk_myuser2 key (reg_no) primary;

    SQL > CREATE TRIGGER MYTRIGGER
    2 AFTER INSERT ON myuser1
    3 FOR EACH LINE
    4 BEGIN
    5 INSERT INTO myuser2 (reg_no, reg_date, u_id)
    6 VALUES (myuser2_seq.nextval, SELECT SYSDATE FROM DUAL, select u_id myuser)
    1)
    7 END;
    8.

    WARNING: Trigger created with compilation errors.

    JKMourya wrote:
    I hv created 2 tables as shown below the code sql. I want to insert some record (line current value) column of the first table, next sequence value and sysdate into second table. I hv created trigger but I gave warning.
    so I want to know what is the problem in my sql code.
    Pls correct!

    SQL > create table myuser1 (u_id varchar2 (10), uname varchar2 (20), sex char(1));

    SQL > create table myuser2 (reg_no number (5), reg_date Date, u_id varchar2 (20));

    SQL > create the sequence myuser2_seq;

    SQL > alter table myuser1 add constraint pk_myuser1 key (u_id) primary;

    SQL > alter table myuser2 add constraint pk_myuser2 key (reg_no) primary;

    SQL > CREATE TRIGGER MYTRIGGER
    2 AFTER INSERT ON myuser1
    3 FOR EACH LINE
    4 BEGIN
    5 INSERT INTO myuser2 (reg_no, reg_date, u_id)
    6 VALUES (myuser2_seq.nextval, SELECT SYSDATE FROM DUAL, select u_id myuser)
    1)
    7 END;
    8.

    WARNING: Trigger created with compilation errors.

    SELECT inside VALUES clause is NOT allowed.
    do SELECT statements before the INSERT command

  • ADF Mobile: Insert a record into a table by WS - DC method

    It's something that is very basic and I could not know.

    There is this method of 'create' base on the service project to insert a single record in a table.

    I created a WS - DC on my mobile project. I see my createItem on the list method. But what I have this XItem.xsd.

    So when I get the ValueExpression binding, I don't know how to set the attribute values...

    ValueExpression ve = AdfmfJavaUtilities.getValueExpression ("#{bindings.xItemView1.inputValue}", Object.class);

    PS: GenericType does not work.

    Your service must expose a method create and then you drag this method to your page and call it with an object as a parameter.
    Should be similar to the way in which an update is done here:
    https://blogs.Oracle.com/Shay/entry/adf_mobile_update_through_web

  • Impossible to insert a record into a table

    Hello

    I was working on a procedure in which I had to insert 1,00,000 records each in 3 tables. But the process stopped after inserting 56000 records.
    After that I ran the query again, but now it is not insert a single record.

    I just created a fictitious table

    create the table vinod1 (no number);

    and I tried to insert a value by using

    insert into vinod1 values (100);

    But to my surprised the query has executed since the past 10 years and has not inserted a line.

    I also tried on SQLPLUS and I use oracle 10g


    Can you please help me and explain why I'm unable to insert the same if I am able to create the table.


    Thank you
    -Vinod

    are you using an option can be REPLICATED in your session, also what is the quota given to the user on the tablespace. The storage space that you used to create the table.

  • by comparing the records with another table

    Hello
    I have the following 2 tables (test_prs & test_dep) and registers
    My goal is to compare test_prs with test_dep records and return the records that are not in test_dep

    Here is the table scripts
    create table test_prs (id ,p_id ,r_id)
    as
    select 1,200566,200566 from dual
     union all
    select 2,200567,200567
    from dual
    
    create table test_dep (id,de_typ,de_id,de_u_typ,de_u_id)
    as
    select 10,'AS',200566,'PG',200566
    FROM DUAL
    UNION ALL
    select 11,'AS',200567,'PG',200567
    FROM DUAL
    
    
    insert into test_dep 
    select 12,'AS',400189,'PG',400273 FROM dual union all
    select 13,'AS',400273,'PG',400250 FROM dual union all
    select 14,'AS',400273,'PG',400192 FROM dual union all
    select 15,'AS',400273,'PG',400191 FROM dual
    
    insert into test_prs
    select 3,400273,400273 from dual
    I tried the following query to meet my criteria. My output should be null, but all records
    select * from 
    test_prs  prs
    where  exists (select 1 from test_dep de where de.de_id !=prs.p_id and de.de_u_id !=prs.p_id )
    Could you please help me the same

    Published by: smile on 7 March 2012 15:00

    Smile says:
    Thanks for the request

    The query does not work with the following documents

    insert into test_dep
    select 16,'AS',750664,'PG',750758 FROM dual 
    
    insert into test_prs
    select 4,750758,750668 from dual
    

    the r_id should not be put in correspondence with the columns in the test_dep table. P_id must only be put in correspondence

    OK, you want to match against the de_id and the de_u_id p_id? Or a line where either p_id concordances r_id de_u_id or de_id must not be returned?

    To match p_id against de_id and de_u_id, you can write the query like this:

    select id, p_id, r_id from test_prs where
    p_id in
    (select p_id from test_prs
    minus
    select de_id from test_dep
    minus
    select de_u_id from test_dep);
    

    Brgds
    Johan

  • help in registration of the records from two tables

    HI: I have two tables joined the first field. The field is the primary key in the first table. Need help listing records from both tables with each a line/record results.
    create table EVENTS (
    event_key varchar2(64) primary key,
    event_description varchar2(64),
    create_time int
    );
    
    
    create table EVENT_UPDATES (
    event_key varchar2(64) NOT NULL ,
    update_description varchar2(64),
    update_time int
    );
    
    
    insert into EVENTS values('Event1', 'This is event1', 1);
    insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
    insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
    insert into EVENTS values('Event2', 'This is event2', 4);
    insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
    insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);
    I want to print each record in the table of EVENTS such as a line and the corresponding records in EVENT_UPDATES as a line like this record
    Event1   1     This is event1
                3     Ticket created
                10   Event cleared
    Event2   4     This is event2
                6     Ticket created
                8     Event cleared
    TIA
    Ravi
    select  case weight
              when 1 then event_key
            end key,
            time_val,
            description
      from  (
              select  event_key,
                      create_time time_val,
                      event_description description,
                      1 weight
                from  events
             union all
              select  event_key,
                      update_time,
                      update_description,
                      2 weight
                from  event_updates
            )
      order by event_key,
               weight
    /
    
    KEY          TIME_VAL DESCRIPTION
    ---------- ---------- -------------------------
    Event1              1 This is event1
                        3 Ticket created
                       10 Event cleared
    Event2              4 This is event2
                        6 Ticket created
                        8 Event cleared
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • insertion of records in multiple tables

    Hope someone can keep me on the right track here.

    My current database structure is:

    I think that's all this from back to me - it is in fact only all your networking / lookup tables. so I now have the following tables:

    Candidates
    ---------------
    Candidate_ID (AutoNumber)
    Name (text)
    ...

    1, Iain
    2, fi
    3, Rob


    Job offers
    --------------
    Vacancy_ID (AutoNumber)
    Holiday (text)
    ...

    1, cartographer
    2, gardener
    3, OT
    4, Web Designer
    5, recruitment manager


    Profiles of school boards
    -----------
    Profile_ID (AutoNumber)
    Profile (text)
    ...

    1, card making
    2, Web design
    3, gardening
    4, hand therapy
    5, recruitment
    6, aviation
    7, sport
    8, travel


    VacancyProfiles
    ----------------------
    Vacancy_ID (number)
    Profile_ID (number)
    ...

    1.1
    1, 2
    4.2
    2, 3
    3, 4
    5.5
    5, 6

    CandidateProfiles
    --------------------
    Candidate_ID (number)
    Vacancy_ID (number)
    ...

    1.1
    1, 2
    1.7
    1.8
    2, 3
    2, 4
    2.8
    3.5
    3.6
    3.7

    and created two queries

    CandidatesQuery
    --------------------

    SELECT Candidates.Candidate_ID, Candidates.Name, Profiles.Profile_ID, Profiles.Profile
    Profiles of JOIN IN-HOUSE (candidates INNER JOIN CandidateProfiles ON Candidates.Candidate_ID = CandidateProfiles.Candidate_ID) ON Profiles.Profile_ID = CandidateProfiles.ProfileID;

    1, Iain, 1, card making
    1, Iain, 2, Web design
    1, Iain, 7, Sport
    1, Iain, 8, travel
    Fi, 2, 3, gardening
    2, fi, 4, hand therapy
    Fi, 2, 8, travel
    3, Rob, 5, recruitment
    3, Rob, 6, Aviation
    3, Rob, 7, Sport

    and

    Vacancies_Query
    -------------------

    SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy, Profiles.Profile_ID, Profiles.Profile
    Profiles of JOIN IN-HOUSE (vacant posts INNER JOIN VacancyProfiles ON Vacancies.Vacancy_ID = VacancyProfiles.VacancyID) ON Profiles.Profile_ID = VacancyProfiles.ProfileID;
    ...

    1, cartographer, 1, card making
    1, cartographer, 2, Web design
    Gardener, 2, 3, gardening
    3, OT, 4, hand therapy
    4, web designer, Web design 2
    5, recruitment manager, 5, recruitment
    5, recruitment manager, 6, Aviation

    -----------

    But I'm a little shaky on how to make my insert (and modify) the pages of documents. Simple, it is enough if I just want to add a new candidate or vacation - just add a record in a table.

    But ideally, I would like to add profiles associated with each new candidate or vacation at the same time - which probably would add records for the CandidatesProfile and VacanciesProfiles tables too.

    Is this possible and if yes how do I configure?

    Or should it be a two steps process, IE adding records to the table of candidates and then add records to the table of CandidatesProfiles?

    What I am used to doing in MS Access forms would be something like the use of sub forms, but really don't know how to reproduce it in a web page.

    Pointers appreciated.

    See you soon,.
    Iain

    Well, I think I got in the way which it - I'm going to mark this as replied and start a new thread, as I narrowed down it to something more specific I need to do. Basically it adding a new candidate and goes to a page of profiles add-on that uses checkboxes for each profile.

    When I select all profiles, it adds them to the table of Candidateprofile, but not with the newly added candidate candidateID, but with a 0 candidateID - so I need to figure out how to pass the CandidateID candidate newly added page AddCandidate page AddProfiles...

    Iain

  • Unable to display the records in a table

    I am a user of a database DB1 U1. The Table T1 is available in a schema/user U2 in the same database DB1. Records are also available in T1.

    The U1 user has select privileges on the table T1. But the select query returns no records in the table T1 for the U1 user. It returns "0 rows. But it has more than 1000 available records in this table, but unable to see those documents. But the U2 user can see these documents and select query retrieves records as usual. How to check what is stopping to select records. How to check what is the method of security set in place which prevents the U1 user to see the records in the table T1.

    Help, please. . I'm naïve...

    Thank you

    You seem to have a virtual private database and/or use of fine-grained access control.

    The two concepts are explained in books online for the version of the database that you didn't disclose it.

    The rules are generally stored in the dictionary DBA_FGA views *.

    --------

    Sybrand Bakker

    Senior Oracle DBA

  • Addign a computed column of the record count in table external

    Hello

    I have a csv file that is loaded using the external table. My need is to give a number to each record in the file and save it in one of the extra column in the table, can anyone suggest how it is possible?

    The structure of the file is:
    $cat emp.txt
    7369,SMITH,CLERK,7902,12/17/1980,800,,20
    7499,ALLEN,SALESMAN,7698,2/20/1981,1600,300,30
    7521,WARD,SALESMAN,7698,2/22/1981,1250,500,30
    7566,JONES,MANAGER,7839,4/2/1981,2975,,20
    7654,MARTIN,SALESMAN,7698,9/28/1981,1250,1400,30
    7698,BLAKE,MANAGER,7839,5/1/1981,2850,,30
    7782,CLARK,MANAGER,7839,6/9/1981,2450,,10
    7788,SCOTT,ANALYST,7566,12/9/1982,3000,,20
    7839,KING,PRESIDENT,,11/17/1981,5000,,10
    7844,TURNER,SALESMAN,7698,9/8/1981,1500,0,30
    7876,ADAMS,CLERK,7788,1/12/1983,1100,,20
    7900,JAMES,CLERK,7698,12/3/1981,950,,30
    7902,FORD,ANALYST,7566,12/3/1981,3000,,20
    7934,MILLER,CLERK,7782,1/23/1982,1300,,10
    
    --and the table structure is:
    
        CREATE TABLE TMP_emp_ext
        (
        EMPNO                                      NUMBER(4),
        ENAME                                              VARCHAR2(10),
        JOB                                                VARCHAR2(9),
        MGR                                                NUMBER(4),
        HIREDATE                                           DATE,
        SAL                                                NUMBER(7,2),
        COMM                                               NUMBER(7,2),
        DEPTNO                                             NUMBER(2)
        )
        ORGANIZATION EXTERNAL
          (  TYPE ORACLE_LOADER
             DEFAULT DIRECTORY DIR_N1
             ACCESS PARAMETERS
               ( records delimited  by newline
            fields  terminated by ','
            missing field values are null
           )
             LOCATION (DIR_N1:'emp.txt')
          )
        REJECT LIMIT UNLIMITED
        NOPARALLEL
        NOMONITORING
     /
    Now, my need is to give a number to each record... like the record from 7369, SMITH should be granted record n ° 1, 7499, ALLEN should be record No. 2 etc... can anyone suggest how it is possible?

    Thank you
    orausern

    T. Kyte write RECNUM should work in http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:52733181746448 #52977916329285 because it is SQL * Loader syntax. However I've wasn't able to make it work with Oracle 10.2.0.4. But in case of errors of loading, you should find in _XXXXX.log the number of rejected records line (in my example it's the meaning of the 'line 2' "line 2"):

    erreur lors du traitement de la colonne EMPNO, la ligne 2, pour le fichier de données /tmp/emp.txt
    ORA-01722: invalid number
    
  • How to read/select only the records from a table with non-English characters

    Hello
    I need to find all records in a table with non-English (mainly Chinese) characters in at least one of the varchar2 columns. Let me kow if someone knows a way by which it can be done using SQL/PLSQL.

    Best regards
    Imran
    select * from your table
    where your_column != convert(your_column, 'UTF8', 'US7ASCII)
    

    Replace UTF8 with your database character set

    Published by: thtsang on October 15, 2009 03:53 - unequal sign change of! =

  • Change all the record in a table by clicking a button

    Hello:
    My version is 11.1.1.6 Jdev

    I want to calculate a new price for all products in an af:table with a unique af:inputText and clicking on a single af:commandButton.
    How can I multiply the price of the column of af: table by a value typed in af:inputText?

    It's my interator

    It is actionListener may in af:commandButton, but I don't know how to go on:

    Sub CalculateNewPrice()
    {
    DCBindingContainer links =
    (DCBindingContainer) BindingContext.getCurrent () .getCurrentBindingsEntry ();
    DCIteratorBinding = selected2
    bindings.findIteratorBinding ("PriceListView2Iterator");
    RowSetIterator iterListPrices = selected2.getRowSetIterator ();
    }

    Hello.
    See:Re: Loop example DCIteratorBinding - jdev 11.1.2

Maybe you are looking for