Create Table  From a Having Count Select

Hello Folks, any ideas here, I need to create a table using the below 'Select' as the criteria.
I have the following table and its has duplicate records, identified by double Unique_seq. I want to create a table of these else where, then delete them from schema.tablename.
Schmea.tablename
field1
field2
field3
field4
Unique_Seq
SELECT Unique_Seq,COUNT(Unique_Seq)
FROM Schema.Tablename
GROUP BY Unique_Seq
HAVING ( COUNT(Unique_Seq) > 1
I want to create the table using all the fields from schema.tablename
Thanks

Thanks for the table script and insert statement.
here is what you are looking for
select * from tester_c;
AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
OP0021889/10                             OP0021889/10                            529832 NNCC00491362OP0021889/1025-JAN-10
                                         OP0021889/10                            529832 NNCC0049136225-JAN-10
                                         OP0022096/10                            539481 NNCC0060037812-JAN-10
OP0022096/10                             OP0022096/10                            539481 NNCC00600378OP0022096/1012-JAN-10
LI0192                                   IK735241                                 53925 PP54TH34120988
                                         KL1923836                                65478 BG7892534KL1923836
                                         KL1923836                                65478 BG7892534KL1923836
PQ8712346                                BN27345236                               64877 7234723642
8 rows selected.
Elapsed: 00:00:00.01Pushing duplicate data into a new table tester_c_dup
CREATE Table tester_c_dup as SELECT * FROM tester_c A WHERE a.rowid > ANY (SELECT  B.rowid FROM
        Tester_c B
     WHERE
        a.Unique_Seq = B.Unique_Seq)
select * from tester_c_dup;
AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
                                         OP0021889/10                            529832 NNCC0049136225-JAN-10
OP0022096/10                             OP0022096/10                            539481 NNCC00600378OP0022096/1012-JAN-10
                                         KL1923836                                65478 BG7892534KL1923836
Elapsed: 00:00:00.01Deleting duplicate data from tester_c table
DELETE FROM tester_c A WHERE a.rowid > ANY (SELECT  B.rowid FROM
        Tester_c B
     WHERE
        a.Unique_Seq = B.Unique_Seq)
select * from tester_c;
AD_ID                                    CD_ID                               UNIQUE_SEQ Z_MASTER_KEY
OP0021889/10                             OP0021889/10                            529832 NNCC00491362OP0021889/1025-JAN-10
                                         OP0022096/10                            539481 NNCC0060037812-JAN-10
LI0192                                   IK735241                                 53925 PP54TH34120988
                                         KL1923836                                65478 BG7892534KL1923836
PQ8712346                                BN27345236                               64877 7234723642
Elapsed: 00:00:00.00HTH,
Prazy

Similar Messages

  • Getting error while creating table from one database to other.

    Hi,
    We are getting below error while creating the table from one database to other.
    SQL> create table fnd_lobs parallel compress as select * from [email protected];
    create table fnd_lobs parallel compress as select * from [email protected]
    ERROR at line 1:
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    ORA-02063: preceding line from EEXIT2TEST
    ORA-01555: snapshot too old: rollback segment number 28 with name "_SYSSMU28$"
    too small
    Regards,
    Bhatia

    hi
    what are the apps version local and remote database???
    Snapshot too old errors occur because Oracle can 't reconstruct a consistent
    image of a block for the purposes of a consistent read.
    I feel at remote database, you are using UNDO, it will be rather easy to iincrease the undo retention time or increase the undo tablespace size.. if you are dealing with roll back segments, you may have rollback segments whose optimal values are too small...
    increase roll back segments size and select again then
    the following metalink notes might be helpful
    ORA-01555 "Snapshot too old" - Detailed Explanation Doc ID: 40689.1
    How To Avoid ORA-01555: Snapshot Too Old When Running PAAPIMP Doc ID: 603259.1
    OERR: ORA 1555 "snapshot too old (rollback segment too small)" Doc ID: 18954.1

  • Create table from view giving error

    i am trying to creating a table from view it is giving following error. can you please help
    create table jd as
    select * from A.ab_v where 1=2;
    error
    ORA-01723
    zero columns not allowed

    As others already pointed out you have NULL as view column(s). You need to either modify view and use CAST(NULL AS desired-type). For example:
    SQL> create or replace
      2    view v1
      3      as
      4        select  null new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
        select  *
    ERROR at line 3:
    ORA-01723: zero-length columns are not allowed
    SQL> create or replace
      2    view v1
      3      as
      4        select  cast(null as date) new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
    Table created.
    SQL> drop table tbl
      2  /
    Table dropped.
    SQL> create or replace
      2    view v1
      3      as
      4        select  cast(null as number) new_number
      5          from  dual
      6  /
    View created.
    SQL> create table tbl
      2    as
      3      select  *
      4        from  v1
      5  /
    Table created.
    SQL>  Or list individual view columns with NULL CASTing in CTAS:
    SQL> create or replace
      2    view v1
      3      as
      4        select  null new_date
      5          from dual
      6  /
    View created.
    SQL> create table tbl
      2     as
      3       select  cast(new_date as date) new_date
      4         from  v1
      5  /
    Table created.
    SQL> desc tbl
    Name                                      Null?    Type
    NEW_DATE                                           DATE
    SQL> set null NULL
    SQL> select  *
      2    from  tbl
      3  /
    NEW_DATE
    NULL
    SQL> SY.

  • Users are not able to create POs from PRs having Production Order (F)

    Hi Gurus
    Users are not able to create POs from PRs having Production Order (F) as creation indicator.
    Whenever we are trying to convert the PR to PO we are getting the error message "Requisition has different doc. type NB and item cat. >&<" based on the below OSS# 938154 condition for the creation indicator type F.
    Would you please investigate and advise what OSS notes are required to be able to use item category L (subcontracting) on a PO for a requisition generated from a network activity via Procurement Type = "Preliminary requisition for WBS element".
    Thanks,
    Sada.

    Hi Ajay & Andra
    Whenever we are trying to convert the PR to PO we are getting the error message "Requisition has different doc. type NB and item cat. >&<" based on the below OSS# 938154 condition for the creation indicator type  Production order (F).
    Our Business requirement as shown below.
    1).The problem - we currently have no way to "direct requisition" an item to be procured via      subcontracting - only itu2019s possible via MRP.
    2).These behaviors are inconsistent as the requisition process should not impact the procurement process.  Can we find a way to influence the creation indicator on the requisition so that it does not appear as a production order?
    Please suggest any alternate method for achieving this.
    Thanks & Regards
    Sada

  • "Create Table from select Query" Vs "Insert into"

    Hi
    Schenaio:
    My Select Query returns more than 10 million records, these records needs to be inserted into another table.
    Approach 1:
    I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
    Approach 2:
    I create table like,
    CREATE TABLE TABLE1 AS <SELECT QUERY>
    Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
    If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
    Thanks
    Nidhi

    Most "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
    Therefore, a FullTableScan is executed for each batch of 5000 rows.
    However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
    Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
    What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
    Hemant K Chitale

  • Question on Creating table from another table and copying the partition str

    Dear All,
    I want to know whether is there any way where we can create a table using another table and have the partitions of the new table to be exactly like the used table.
    Like
    CREATE TABLE TEST AS SELECT * FROM TEMP;
    The table TEMP is having range and hash partitions.
    Is there any way when we use the above command, we get the table partitions of TEMP to be copied to the new table TEST.
    Appreciate your suggestions on this one.
    Thanks,
    Madhu K.

    may this answer your question...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:595568200346856483
    Ravi Kumar

  • Create table from external data with dates

    I have a CSV that looks somewhat like this:
    abcuser,12345,5/12/2012,5,250.55
    xyzuser,67890,5/1/2012,1,50
    ghjuser,52523,1/1/1900,0,0
    When I create the external table, then query it I get a date error:
    CREATE TABLE xtern_ipay
    userid VARCHAR2(50),
    acctnbr NUMBER(20, 0),
    datelastused DATE,
    number_rtxns NUMBER(12, 0),
    amtused NUMBER(12, 0)
    organization external ( TYPE oracle_loader DEFAULT directory "XTERN_DATA_DIR"
    ACCESS parameters (
    records delimited BY newline fields terminated BY "," )
    location ('SubscriberStatistics.csv') ) reject limit UNLIMITED;
    Error I see in the reject log:
    Field Definitions for table XTERN_IPAY
    Record format DELIMITED BY NEWLINE
    Data in file has same endianness as the platform
    Rows with all null fields are accepted
    Fields in Data Source:
    USERID CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    ACCTNBR CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    DATELASTUSED CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    NUMBER_RTXNS CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    AMTUSED CHAR (255)
    Terminated by ","
    Trim whitespace same as SQL Loader
    error processing column DATELASTUSED in row 1 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    error processing column DATELASTUSED in row 2 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    error processing column DATELASTUSED in row 3 for datafile g:\externaltables\SubscriberStatistics.csv
    ORA-01858: a non-numeric character was found where a numeric was expected
    Any ideas on this? I know I need to tell oracle the format of the date on the external file, but I can't figure it out.

    Try this:
    CREATE TABLE xtern_ipay
       userid         VARCHAR2 (50)
    , acctnbr        NUMBER (20, 0)
    , datelastused   DATE
    , number_rtxns   NUMBER (12, 0)
    , amtused        NUMBER (12, 2)
    ORGANIZATION EXTERNAL
        ( TYPE oracle_loader DEFAULT DIRECTORY "XTERN_DATA_DIR"
    ACCESS PARAMETERS (
    RECORDS DELIMITED BY NEWLINE FIELDS TERMINATED BY "," MISSING FIELD VALUES ARE NULL
    (   userid
      , acctnbr
      , datelastused DATE 'mm/dd/yyyy'
      , number_rtxns
      , amtused)
    location ('SubscriberStatistics.csv') ) reject LIMIT unlimited;
    select * from xtern_ipay;
    USERID                                                ACCTNBR DATELASTU NUMBER_RTXNS    AMTUSED
    abcuser                                                 12345 12-MAY-12            5     250.55
    xyzuser                                                 67890 01-MAY-12            1         50
    ghjuser                                                 52523 01-JAN-00            0          0
    {code}
    Sorry I had to correct the previous statement again for the date format and for the column amtused that was defined without decimals.
    Regards
    Al
    Edited by: Alberto Faenza on May 31, 2012 6:34 PM
    wrong date format mm/dd/yy instead of dd/mm/yy
    Edited by: Alberto Faenza on May 31, 2012 6:40 PM
    Fixed again the date format and the amtused defined with 2 decimals                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • I can't create table from another table?

    Hi everyone!
    I have a problem that I don't known the reason why?
    I'm using Oracle version 8i and I want to create a table from another table, such as:
         CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
    But there is only a table that I can't created like that, such as:
         CREATE TABLE b_backup AS SELECT * FROM b;
    When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
    This is the first time I met this problem.
    Can Anyone help me to resolved it?
    Thanks in advance!

    xi`tin wrote:
    Hi everyone!
    I have a problem that I don't known the reason why?
    I'm using Oracle version 8i and I want to create a table from another table, such as:You realize, of course, that 8i is completely out of support .... Is your OS and hardware just as old as your rdbms software, or is it only the rdbms that your company refuses to upgrade?
         CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
    But there is only a table that I can't created like that, such as:
         CREATE TABLE b_backup AS SELECT * FROM b;
    When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
    This is the first time I met this problem.
    Can Anyone help me to resolved it?
    Thanks in advance!

  • Create table from query in Form

    I want to create table in Form 6i, on form I have :sdate , :edate and :dpt Item.
    PROCEDURE TableView IS
    BEGIN
    FORMS_DDL('drop table test');
    declare
    v_com varchar2(4000);
    BEGIN
    V_COM := 'Create table test as
           select * from emp
    where hiredate between :sdate and :edate
    and deptno = :dpt
    FORMS_DDL(V_COM);
    end;When I was tried in TOAD It is showing error
    ORA-01036: illegal variable name/number
    Edited by: Ahmed on Oct 19, 2011 11:11 PM

    you can't use bind variables within forms_ddl. An option would be to not do any ddl at all, and do something like this:
    delete from test;
    insert into test(a,b,c)
    select a,b,c from emp
    where hiredate between :sdate and :edate
    and deptno = :dpt;cheers

  • Create table from another table including constraints

    Hi,
    Is there a way to create a table from another table including constraints.
    CREATE TABLE COPY_EMP
    as
    SELECT *
    FROM EMP
    WHERE 1 =2 ;
    This creates the table, but the constraints are not copied over.
    I was reading about DBMS_REDEFINITION - can that be used for this scenario ?
    Thanks!
    Anand

    >
    I tried that, but the constraint names are posing a problem. And unfortunately our constraints are not named in a standard, so am finding it difficult to replace them.
    Was just wondering if there were any simpler approach to this.
    >
    No - there isn't.
    You will have to use new names for the constraints. That usually means extracting the DDL and manually changing the constraint names.

  • Create table from DBMS_SHARED_POOL.SIZES output

    How can I create a table from the output of DBMS_SHARED_POOL.SIZES output ... If possible at all?
    Thank you !

    Your conclusion is just wrong. dbms_shared_pool.keep is geared at procedures and functions which you are calling over and over again, and which you can't afford to be reloaded often.
    The only thing you avoid by pinning a procedure is the overhead of reloading.
    Secondly in both cases you perform 10000000 inserts instead of 1 bulk insert and this is taking time.
    What you should do is
    SQL> l
    1 insert into scott.test
    2 select trunc(dbms_random.value(10,40)), trunc(dbms_random.value(10,40))
    3 from dual
    4* connect by level <= 1000000
    I can insert 1 million rows in 14.51 seconds
    Your method is the slowest possible.
    And yes, you always should use a spfile, but this has nothing to do with the problem at hand.
    Sybrand Bakker
    Senior Oracle DBA

  • How to create table from another in pl/sql

    Hi I need to create a table from another in pl/sql
    How can I do this

    The proper way to do this, is not to do it in PL/SQL. But do it in SQL, something like:
    create table tbl
    as
    select *
      from other_tbl;Doing it in PL/SQL is really slow compared to SQL.
    Yes, if you really want to create a table using PL/SQL then you will need to use DBMS_SQL or EXECUTE IMMEDIATE (Native Dynamic SQL) to do this.

  • Question on Creating Table From Insert statement

    Hi,
    I want to create a table using a DBlink from another database using the create/insert statement. Will it also transfer the constraints or do I have to do it manually afterwards? Thanks.
    Create table T1
    SELECT a,b,c from T2 from DB@dblink;

    As discussed above, the constraints, indexes, triggers are not copied. Only NOT NULL constraints are copied.
    Look at this thread Re: Copying table structure.
    for copying triggers/indexes from source table to destination table.
    Thanks,
    Navaneeth

  • Create table from user scott

    Hi,
    Can you help me with this?
    I wrote this
    {declare
    cursor c1 is
    select *
    from
    all_objects
    where lower(owner) like 'scott'
    and lower(object_type)='table';
    i varchar2(50);
    begin
    for i in c1
    loop
    execute immediate 'create table '||i.object_name|| ' as select *
    from ' ||i.object_name;
    end loop;
    close c1;
    end;
    and I have the following errors:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at line 12
    Thank you

    Could you please show output of your generated code using dbms_output.put_line command?
    declare
    cursor c1 is
    select *
    from
    all_objects
    where lower(owner) like 'scott'
    and lower(object_type)='table';
    i varchar2(50);
    begin
    for i in c1
    loop
    dbms_output.put_line('create table '||i.object_name|| ' as select *
    from ' ||i.object_name);
    end loop;
    close c1;
    end;
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • How to see DDL script(create table) from view

    i want to view create table script(DDL command)
    can u suggest me any view for that.

    Hi
    There's no view where the DDL statement is directly available. It must be reconstructed from many views...
    If you use 9i the simpler way to do that is with DBMS_METADATA. Below and example....
    SQL&gt; SET LONG 1000000
    SQL&gt; SELECT dbms_metadata.get_ddl('TABLE','EMP') FROM dual;
    DBMS_METADATA.GET_DDL('TABLE','EMP')
    CREATE TABLE "SCOTT"."EMP"
    ( "EMPNO" NUMBER(4,0) NOT NULL ENABLE,
    "ENAME" VARCHAR2(10),
    "JOB" VARCHAR2(9),
    "MGR" NUMBER(4,0),
    "HIREDATE" DATE,
    "SAL" NUMBER(7,2),
    "COMM" NUMBER(7,2),
    "DEPTNO" NUMBER(2,0),
    CONSTRAINT "EMP_PK" PRIMARY KEY ("EMPNO")
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS" ENABLE,
    CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEPTNO")
    REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
    ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
    STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    Chris

Maybe you are looking for