To make three tables from one table

Hi,
I have created a random table from a big table and now i want to make three tables of same numbers, means each table should contain 1000 records, as the table has random idx column, so i cant divide directly on basis of idx. in addition, i cant create three seperate tbles from main table, as i dont want any duplicate data in those three tables, whcih may occur if i will create each table individually.
Best regards,

Table 1.
create table emp1 as
select empno,ename,sal--,................
from(select e.*,row_number() over(order by rowid) rn,count(*) over(order by null) cnt
     from emp e)
where rn < cnt/3
Table 2.
create table emp1 as
select empno,ename,sal--,................
from(select e.*,row_number() over(order by rowid) rn,count(*) over(order by null) cnt
     from emp e)
where rn between cnt/3 and cnt*2/3
Table 3.
create table emp1 as
select empno,ename,sal--,................
from(select e.*,row_number() over(order by rowid) rn,count(*) over(order by null) cnt
     from emp e)
where rn > cnt*2/3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Passing value to bind variable of another table from one table

    hi,
    I have a multi select table. When one row is selected from this table (no button is clicked, only selection is done), an attribute from that selected row (say userid) should be passed to the bind variable of another table and the corresponding details of that particular userid should be displayed in the other table. When more than one row is selected, the other table should display no rows.
    My main problem is what code has to be written to pass value to bind variable and where it should be written.
    Please give me a detailed explaination as soon as possible.
    Thank you.

    Sorry, didnot add this. The table is multi select table.

  • SQL query to find differences (changes) between tables (from one table) where field names are different

    Hi All,
    I am looking to create a view which returns new or modified data (differences) based on a comparison between two tables.
    The EMP_SOURCE table stores all employee data including duplicate staff numbers (STAFFNO):
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    ) ON [PRIMARY]
    GO
    The EMP table stores unique staff numbers. This is the table used by the application.
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL,
    CONSTRAINT [PK_EMP] PRIMARY KEY CLUSTERED
    [EMP_ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    We are looking to migrate data from EMP_SOURCE to EMP but only records which are new in EMP_SOURCE and do not exist in EMP or records which are different in EMP_SOURCE from EMP.
    EMP_SOURCE:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    John Smith
    Manager
    London
    UK
    1087
    Beth King
    Analyst
    New York
    USA
    2095
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Beth King
    Junior
    Washington
    USA
    2095
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    EMP:
    EMP_ID
    EMP_NAME
    EMP_TITLE
    EMP_OFFICE
    EMP_COUNTRY
    EMP_NUMBER
    1
    John Smith
    Manager
    London
    UK
    1087
    2
    Beth King
    Analyst
    New York
    USA
    2095
    3
    Karl Bent
    Manager
    Washington
    USA
    1106
    Based on the above comparison, EMP_SOURCE table has the following differences:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Differences in red. Beth King should be completely ignored because of duplicate staff numbers (EMP_NUMBER).
    Any help to create a view which returns only the differences from EMP_SOURCE would be appreciated.
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');

    HI Manc !
    You may use the below code to get your desired output;
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    GO
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');
    SELECT FULLNAME,JOBTITLE,LOCATION,COUNTRY,STAFFNO FROM EMP_SOURCE
    EXCEPT
    SELECT EMP_NAME,EMP_TITLE,EMP_OFFICE,EMP_COUNTRY,EMP_NUMBER FROM Emp
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • Move a table from one table space to another tablespace and different table

    Hi,
    I have a 60gb table nearly 200 million records in it and the table has range partition.
    inorder to archive this table we have created 3 different tables and 3 different tablespaces for the tables.
    I want to move certain partitions to tableA and certain partitions to tableB and on to tableC and on the top i'm creating a view to access these 3 tables.
    Is there any technique to move the partition wise data to different tables. is there any new technique in 11g database?
    The database is 11gr1
    linux rhel5 x-86-64
    Edited by: user8894072 on Oct 12, 2010 2:03 PM

    if i do that like each partition has some millions of records. and the undotablespace is filling out and also the temp table space is filling out. The performance is very very poor if i use the create statement.
    Insert INTO TableA (select * FROM <BASETABLE> where pay_end_dt between '01-Jan-1999' and '31-Dec-2005')
    the above statement is also degrading the performance. I just need the synatx to move the partioned wise data to new table.

  • How do I make data from one Table flow into a separate Table

    How do I make data from one Table flow into a separate Table in iworks numbers?

    Great stuff Yvan,
    KOENIG Yvan wrote:
    Here you may see the way to transfer the contents of a column of Table A in a column of Table B
    I used two kinds of formulas.
    In the cell A2 of Table B
    the formula is :
    =Table A :: $B2
    It may be :
    =Table A :: $B
    Apply Fill Down
    Copy paste it in cell A1 which is in a header row.
    This formula does its duty but it’s not robust enough and will not survive to a Sort.
    This is why in B2, I inserted a more robust formula :
    =OFFSET(Table A :: $A$1,ROW()-1,2)
    You will find details about the functions used in Numbers User Guide delivered with every copy of iWork ‘08
    Yvan KOENIG (VALLAURIS, France) samedi 6 août 2011 17:45:22
    iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.0
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !
    The first suggestion was the simple answer I needed,
    Thank you

  • Simple way to insert data from one table

    Hi,
    I need to know a simple way on how to transfer the data from one table to another....
    First table xx_inv_tab1 has three columns col1, col2, col3 and where as second table xx_inv_tab2 has five columns col1, col2, col3, col4, col5.
    Here col2, col3, col4 are the same columns as in table1 xx_inv_tab1...
    Now I want to transfer first table data in to second table .... first column of second table holds a sequence, followed by the first table three columns data and followed with col4 and col5 which will hold NULL values....
    In my scenario, I have 70 - 75 columns in my first table which I want to move to second table which three new columns (one is sequence and other two has null values)...
    Any ideas if we make it in a simplest way rather saying insert into xx_inv_tab2 (col1, col2, col3 ............................................. col75) values (seq, col1, col2..........................col75, null, null)
    Help Appreciated..
    Thanks

    Easy
    untested
    insert into xx_inv_tab2 t2 (col1,col2,col3,col4)
    select yourSequence.nextval, t1.col1, t1.col2, t1.col3
    from xx_inv_tab1 t1
    ;Note that col5 does not need to be used, since you want to fill it with NULL.
    USe excel or sql developer to write you a list of column names, if you are to lazy to write all 75 columns by yourself.
    What might also work:
    untested
    insert into xx_inv_tab2 t2
    select yourSequence.nextval, t1.*, null
    from xx_inv_tab1 t1
    ;Edited by: Sven W. on Aug 31, 2012 4:41 PM

  • Adding Data From One Table to Another

    Now, this doesn't strike me as a particularly complex problem, but I've either strayed outside the domain of Numbers or I'm just not looking at the problem from the right angle. In any case, I'm sure you guys can offer some insight.
    What I'm trying to do is, essentially, move data from one table to another. One table is a calendar, a simple two column 'date/task to be completed' affair, the other is a schedule of jogging workouts, i.e, times, distances. Basically, I'm trying to create a formula that copies data from the second table onto the first but only for odd days of the week, excepting Sundays (and assuming Monday as the start of the week). Now, this isn't the hard part, I can do that. The problem comes when I replicate the formula down the calendar. Even on the days when the 'if' statement identifies it as an 'even day', the cell reference to the appropriate workout on the second table is incremented, so when it comes to the next 'odd day', it has skipped a workout.
    I can't seem to see any way of getting it to specifically copy the NEXT line in the second table, and not the corresponding line.
    This began as a distraction to try and organise my running so I could see at a glance what I had to do that day and track my progress, but now it's turned into an obsession. SURELY there's a solution?
    Cheers.

    Hi Sealatron,
    Welcome to Apple Discussions and the Numbers '09 forum.
    Several possible ways to move the data occur to me, but the devil's in the details of how the data is currently arranged.
    Is it
    • a list of three workouts, one for each of Monday, Wednesday and Friday, then the same three repeated the following week?
    • an open-ended list that does not repeat?
    • something else?
    Regards,
    Barry

  • How to transfer the tables from one file group to another file group in SQL 2008.?

    Hello all,
    I have few issues regarding the transfer of the tables from one file group to another file group  in SQL 2008 and also How can we  backup
    and restore the particular database based on file group level.
    Let’s say I have a tables stored within the different FG. such as
    Tables                                                    
      File group
    Dimension tables                                              
                                                                     Primary
    Fact tables                                               
                                                                              FG1
               FG2…
    zzz_tables                                               
                                                                              DEFAULT_FG    
    dim.table1                                                                                                                          DEFAULT_FG
    dim.table2                                                                                                                          DEFAULT_FG
    Here all I want to transfer the dim.table1 ,dim.table2  from  DEFAULT_FG to the Primary File
    group .So is there simple methods for transfer the dim.table1,2  from one FG to another .I have tried somewhat but I couldn’t get the exact way .So if someone have better idea please share your knowledge that would be really appreciated.
    Secondly after moving those dim.table1 ,dim.table2 from DEFAULT_FG to Primary ,All I want to backup and restore the database only containing  the Primary and FG1,FG2… not
    a DEFAULT_FG.Is it possible or not.?
    Hope to hear from the one who knows better approach for this kind of task .Your simple help will be much appreciated.
    Regards,
    Anil Maharjan

    Well after all my full day research on this topic had paid off, I finally got the solution and am so happy to research on these things. It makes
    us feel really happy after all our research and hard work doesn't goes as waste.
    Finally I got what I am looking for and want to make sure that I am able to transfer the tables from DEFAULT_FG to another FG without tables
    having clustered index on that tables .
    With the help of the link below I finally got my solution where Roberto’s coded store procedure simply works for this.
    Really thanks to him for his great post and thanks to all for your response and your valuable time.
    http://gallery.technet.microsoft.com/scriptcenter/c1da9334-2885-468c-a374-775da60f256f
    Regards,
    Anil Maharjan

  • How to convert data when transferring from one table to another

    I have two tables and these are the structure of the tables
    create table E1(
    ID NUMBER
    ,NAME VARCHAR2(30)
    , DESIGNATION VARCHAR2(30)
    ,GENDER VARCHAR2(10));
    create table E2(
    ID NUMBER
    ,NAME VARCHAR2(30)
    , DESIGNATION VARCHAR2(3)
    ,GENDER NUMBER); Now I want to transfer records from one table to another using a master tables where data are compared because the datatypes in tables are different
    The first one is a gender table to match the gender and convert
    create table Gender(
    E1 varchar2(10),
    E2 number);The second is for the designation
    create table Designation(
    E1 varchar2(30),
    E2 varchar2(3);How to match and convert the data so that it can be transfered.

    Peeyush wrote:
    Can we do it with the help of a cursor.
    All SQL executed by the database are parsed as cursors and executed as cursors.
    I mean I have to insert data in bulk and I want to use cursor for it.The read and write (select and insert) are done by the SQL engine. The read part reads data and passes it to the write part that inserts the data.
    Now why would using PL/SQL and bulk processing make this faster? It will reside in-between the read part and the write part being done by the SQL engine.
    So the SQL engine reads the data. This then travels all the way to the PL/SQL engine as a bulk collect. PL./SQL then issues an insert (the write part to be done by the SQL engine). And now this very same data travels all the way from the PL/SQL engine to the SQL engine for insertion.
    So just how is this approach, where you add extra travel time to data, faster?
    and i want to commit the transaction after every 50 recordsWhy? What makes you think this is better? What makes you think you have a problem with not committing every 50 rows?

  • 10g express, scheduled copy of table from one db to another

    Hi,
    I don't know much about Oracle and was hoping if someone could shed some light on how we could implement our solution.
    Our scenario is as follows:
    For a new customer we are going to have 35million records per month coming into the database.
    What we had normally been doing in MSSQL, is creating a new table every month and writing the records in here (although we never had 35 million records before).
    The problem is, I want to archive these old monthly tables in order to save space. I don't know enough about the Oracle suite to see if there is already a program that we can schedule every month to move this table from one database to another. I was initially doing it by code, but this ends up taking 3 hours to copy... something we cannot afford.
    Is 35 million records too much to hold in a table? Should we be partitioning this down even more? I don't know where the threshold is before Oracle craps out.
    Or, maybe a better idea is to create a new database and just store new entries in a new database every month... this way we won't need to copy anything. To me, this sounds stupid though as i don't want to have 60 databases kicking around in five years.
    I'm a developer and no DBA, no one here is a DBA. We're trying to evaluate if our application is going to work on a Oracle platform all without knowing anything about it. Please help!
    Thanks,
    Kevin
    Message was edited by:
    user518940

    Kevin, you definately have the right database for 35M records/mth.
    From your post, it sounds like you need to retain the records in a database for 5 years (yes?). I don't know of any size limitation for Oracle outside of the OS. I don't think your solution should be multiple databases unless you have vastly different needs for the database that can not be satisfied with one instance - ie. OLTP vs. BATCH/OLAP...
    I don't fully understand what you are shooting for because it doesn't sound like you are going to save on any space just by moving the data from one database to another, the records will still require a similar amount of space unless compressed on another database. In either case, unless you can't, I would recommend a single database design. If you need high performance querying the data, and you query it by a specified period of time - ie month, I would recommend using enterprise edition with partitioning (seperately licensed). This would allow you to create a partitioned table where you could partition the table by month. As long as you don't create unnecessary global indexes, the performance should be quite similar to querying/inserting/appending into a table just containing 1 months records. Each partition can be placed in its own tablespace/datafile(s).
    If you absolutely must 'transport' the data to another instance (which I would strongly suggest that you should load it there in the first place unless business rules, performance limitations or something else simply don't allow it), you can use 'transportable tablespaces' and simply ftp the entire datafile to another Oracle database and attach it thus avoiding having to reload it. If it's truly historical you can just leave it ReadOnly. If you want to be tricky about it, you could try to make it part of a partitoned table on the new host.
    I hope I've helped just a little bit. If you need additional help, email me directly at LenLopez AT Yahoo DOT com

  • How to Move or Copy the Tables from One Database to Another Database ?

    HI,
          Can any one help me on this, How i can move or copy the tables from one database to another database in SQL server 2005 by using SQL query. Hope can anyone provide me the useful and valuable response.
    Thanks
    Gopi

    Hello,
    Maybe these links help you out
    http://www.microsoft.com/downloads/en/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en
    http://www.suite101.com/content/how-to-copy-a-sql-database-a193532
    Also, you can just detach the database make a copy and move it to the new server.

  • MySQL move date from one table to another

    I was wondering if there is a MySQL command that will let me move a selected row of data from one table to another. both tables have the same columns and declaration type (one table is actually an archived table on old data)
    example
    I wasnt to move all data in Table1 where the date is greater than 30 days old to Table 2
    -- so the result should be...import all rows to Table 2 where the date is greater than 30 days old..and delete all date from Table 1 that is greater than 30 days.
    currently..I'm doing three process
    1) get all row that is greater than 30 days  
        "SELECT * FROM Table1 WHERE TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"
    2) insert data into Table2
        while (res.hasNext())
              TableData data = ..... // .get row
              dataList.add(data);
              for (int i = 0; i < dataList.size(); i++){
                    pstm.setString.....
                    pstm.addBatch()
              pstm.executeBatch();
    3) delete data from Table1
        "DELETE FROM Table 1 WHERE  TO_DAYS(NOW()) - TO_DAYS(dateField) > 30"

    for this app..losing a few rows does not
    impact on how we analyze the data.That's what everyone always tells me too. But 99% of the time they come back and want to know why the cannot balance and/or validate the data between two runs taken only minutes from each other.
    I've seen people puzzle over data for days that they swear they ran the exact same utility for their tests, but they were in fact using live data, and additional data had accrued but since all they had to do was execute the a script without parameters (they didn't put in a stop time), they got two different answers and it always, and I mean always confuses people. Be safe, and put the option in for and end date/time, then when they waste days trying to figure out why the two different observations gave them different numbers, they cannot blame you (because you gave them the option)!
    My 2 cents for the day...

  • Copying large amount of data from one table to another getting slower

    I have a process that copies data from one table (big_tbl) into a very big archive table (vb_archive_tbl - 30 mil recs - partitioned table). If there are less than 1 million records in the big_tbl the copy to the vb_archive_table is fast (-10 min), but more importantly - it's consistant. However, if the number of records is greater than 1 million records in the big_tbl copying the data into the vb_archive_tbl is very slow (+30 min - 4 hours), and very inconsistant. Every few days the time it takes to copy the same amount of data grows signicantly.
    Here's an example of the code I'm using, which uses BULK COLLECT and FORALL INSERST to copy the data.
    I occasionally change 'LIMIT 5000' to see performance differences.
    DECLARE
    TYPE t_rec_type IS RECORD (fact_id NUMBER(12,0),
    store_id VARCHAR2(10),
    product_id VARCHAR2(20));
    TYPE CFF_TYPE IS TABLE OF t_rec_type
    INDEX BY BINARY_INTEGER;
    T_CFF CFF_TYPE;
    CURSOR c_cff IS SELECT *
    FROM big_tbl;
    BEGIN
    OPEN c_cff;
    LOOP
    FETCH c_cff BULK COLLECT INTO T_CFF LIMIT 5000;
    FORALL i IN T_CFF.first..T_CFF.last
    INSERT INTO vb_archive_tbl
    VALUES T_CFF(i);
    COMMIT;
    EXIT WHEN c_cff%NOTFOUND;
    END LOOP;
    CLOSE c_cff;
    END;
    Thanks you very much for any advice
    Edited by: reid on Sep 11, 2008 5:23 PM

    Assuming that there is nothing else in the code that forces you to use PL/SQL for processing, I'll second Tubby's comment that this would be better done in SQL. Depending on the logic and partitioning approach for the archive table, you may be better off doing a direct-path load into a staging table and then doing a partition exchange to load the staging table into the partitioned table. Ideally, you could just move big_tbl into the vb_archive_tbl with a single partition exchange operation.
    That said, if there is a need for PL/SQL, have you traced the session to see what is causing the slowness? Is the query plan different? If the number of rows in the table is really a trigger, I would tend to suspect that the number of rows is causing the optimizer to choose a different plan (with your sample code, the plan is obvious, but perhaps you omitted some where clauses to simplify things down) which may be rather poor.
    Justin

  • Moving time-dependant data from one table to another (archiving)

    Hello all
    I would like to know if there's an easier solution or a "best practice" to move data from one table to another. The context of this issue can be found within "archiving".
    More concretely: we have an application that uses several tables to log information to.
    These tables are growing like crazy, and we would like to keep only "relevant" data in those tables, so I was thinking about moving data from these tables that have been in there for, say 2 months, to "archiving" tables.
    I figured there must be some kind of "best practice" to get this done.
    I have already written a procedure that loops the table that has the time indicator and inserts the records from the normal tables into the archive tables (and afterwards delete this data), but it seems to be taking ages to get it done.
    Thanks in advance!
    Message was edited by:
    timschraepen

    There is nothing to do with PL/SQL.
    You can refer below links:
    http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96524/c12parti.htm
    http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10739/partiti.htm#i1006727

  • Insert old missing data from one table to another(databaase trigger)

    Hello,
    i want to do two things
    1)I want to insert old missing data from one table to another through a database trigger but it can't be executed that way i don't know what should i do in case of replacing old data in table_1 into table_2
    2)what should i use :NEW. OR :OLD. instead.
    3) what should i do if i have records exising between the two dates
    i want to surpress the existing records.
    the following code is what i have but no effect occured.
    CREATE OR REPLACE TRIGGER ATTENDANCEE_FOLLOWS
    AFTER INSERT ON ACCESSLOG
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    V_COUNT       NUMBER(2);
    V_TIME_OUT    DATE;
    V_DATE_IN     DATE;
    V_DATE_OUT    DATE;
    V_TIME_IN     DATE;
    V_ATT_FLAG    VARCHAR2(3);
    V_EMP_ID      NUMBER(11);
    CURSOR EMP_FOLLOWS IS
    SELECT   EMPLOYEEID , LOGDATE , LOGTIME , INOUT
    FROM     ACCESSLOG
    WHERE    LOGDATE
    BETWEEN  TO_DATE('18/12/2008','dd/mm/rrrr') 
    AND      TO_DATE('19/12/2008','dd/mm/rrrr');
    BEGIN
    FOR EMP IN EMP_FOLLOWS LOOP
    SELECT COUNT(*)
    INTO  V_COUNT
    FROM  EMP_ATTENDANCEE
    WHERE EMP_ID    =  EMP.EMPLOYEEID
    AND    DATE_IN   =  EMP.LOGDATE
    AND    ATT_FLAG = 'I';
    IF V_COUNT = 0  THEN
    INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT
                                ,TIME_IN ,TIME_OUT,ATT_FLAG)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
                 NULL,
                 TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),      -- TIME_IN
                 NULL ,'I');
    ELSIF   V_COUNT > 0 THEN
    UPDATE  EMP_ATTENDANCEE
        SET DATE_OUT       =  TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
            TIME_OUT       =   TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'), -- TIME_OUT
            ATT_FLAG       =   'O'
            WHERE EMP_ID   =   TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
            AND   DATE_IN <=  (SELECT MAX (DATE_IN )
                               FROM EMP_ATTENDANCEE
                               WHERE EMP_ID = TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
                               AND   DATE_OUT IS NULL
                               AND   TIME_OUT IS NULL )
    AND   DATE_OUT  IS NULL
    AND   TIME_OUT IS NULL  ;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN RAISE;
    END ATTENDANCEE_FOLLOWS ;
                            Regards,
    Abdetu..

    INSERT INTO SALES_MASTER
       ( NO
       , Name
       , PINCODE )
       SELECT SALESMANNO
            , SALESMANNAME
            , PINCODE
         FROM SALESMAN_MASTER;Regards,
    Christian Balz

Maybe you are looking for