inserting data in a column in an existing table

Hi the gems...

I have an existing table TABLE_1 which has more data in it. This table has no primary key. now, I added a new column 'ID' and want to make it a primary key for this table. currently it is not allowed because the column is null...

so I need to insert data into the column.
now, my plan is to fill the column with the data as well as rownumber.

means that if there are 15 records in this table, then the 'ID' column should contain data from 1 to 15. After that, I'll do the column as a primary key...

the script I wrote for this:

declare
number of v_rownum;

Start
Select max (rownum) in the v_rownum from TABLE_1;
because me in 1.v_rownum
loop
Update t set i = t.id TABLE_1 where rownum = i;
commit;
end loop;

end;



but it refreshes only the first record and the rest of the records are not updated.

Please help... Thanks in advance...

Select max (rownum) in the v_rownum from TABLE_1;

How many rows do you think that this query will retrieve?

Why not just

Update TABLE_1 t
the value t.id = rownum;

Tags: Database

Similar Questions

  • Inserting data from a query to an existing table

    How do I change my code to make it work correctly? It currently compiles I think because the program believes that the size of v_stats_5d_1 can be different from c_stats_5d_1. I have these errors:

    LINE/COL ERROR

    -------- ------------------------------------

    30/10 PL/SQL: statement ignored

    30/23 PL/SQL: ORA-00947: not enough values

    CREATE OR REPLACE PACKAGE IN THE PKG_RISK_MONITOR

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    );

    END PKG_RISK_MONITOR;

    /

    CREATE OR REPLACE PACKAGE BODY PKG_RISK_MONITOR AS

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    )

    IS

    l_ct NUMBER;

    CURSOR c_stats_5d_1

    IS

    SELECT MIND_ACCOUNTS. CLIENT_ID, MIND_ACCOUNTS. CLIENT_NAME, SUM (DATA. CREATED_TRANSACTIONS_NUMBER) AS SUM_CREATED_TRX_NUMBER, SUM (DATA. CREATED_refunds_NUMBER) SUM_CREATED_REFUNDS_NUMBER, SUM (DATA. CREATED_TRANSACTIONS_value * Conversion_rate) CREATED_TRX_EUR_VALUE, DATA. PROCESSING_DATE

    OF (MIND_ACCOUNTS INNER JOIN DATA ON MIND_ACCOUNTS. ACCOUNT_ID = DATA. CURRENCY_conversion INNER JOIN MERCHANT_CID) ON THE DATA. CURRENCY = CURRENCY_conversion. CURRENCY

    GROUP OF MIND_ACCOUNTS. CLIENT_ID, MIND_ACCOUNTS. CLIENT_NAME, DATA. PROCESSING_DATE

    (DATA. PROCESSING_DATE > = TO_DATE (P_CONTEXT_DATE, 'dd-mm-yyyy')-4) and DATA. PROCESSING_DATE < = TO_DATE (P_CONTEXT_DATE, ' dd-mm-yyyy "")

    ;

    v_stats_5d_1 "TMP_STATS_5D_1" % rowtype;

    BEGIN

    -Insert subquery data into an empty table

    OPEN c_stats_5d_1.

    LOOP

    SEEK c_stats_5d_1 INTO v_stats_5d_1;

    EXIT WHEN c_stats_5d_1% NOTFOUND;

    INSERT INTO 'TMP_STATS_5D_1 '.

    VALUES (v_stats_5d_1);

    END LOOP;

    END CREATE_STATS_5D;

    END PKG_RISK_MONITOR;

    /

    DISPLAY ERRORS

    THX. Managed to get there in the end:

    CREATE OR REPLACE PACKAGE IN THE PKG_RISK_MONITOR

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    );

    END PKG_RISK_MONITOR;

    /

    CREATE OR REPLACE PACKAGE BODY PKG_RISK_MONITOR AS

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    )

    IS

    l_ct NUMBER;

    v_sql VARCHAR2 (1000);

    BEGIN

    -Determine whether the table exists.

    Select count (*) in l_ct

    from user_tables

    where table_name = 'TMP_STATS_5D_1 ';

    -Remove the table if it exists.

    If l_ct = 1 then

    run immediately "drop table TMP_STATS_5D_1;

    end if;

    v_sql: = q'[CREATE TABLE 'TMP_STATS_5D_1' AS

    SELECT m.client_id,

    m.client_name,

    Sum (d.created_transactions_number) AS sum_created_trx_number,

    Sum (d.created_refunds_number) AS sum_created_refunds_number,

    Sum(d.created_transactions_value * conversion_rate) AS created_trx_eur_value,

    d.processing_date

    M 'MIND_ACCOUNTS '.

    INNER JOIN 'DATA' m.account_id d = d.merchant_cid

    INNER JOIN 'CURRENCY_CONVERSION' c ON d.currency = c.currency

    WHERE (d.processing_date > = To_date ('] '))

    || P_CONTEXT_DATE |

    q'[(', ' dd-mm-yyyy') (-4) AND d.processing_date]<=>

    || P_CONTEXT_DATE |

    q'[',' dd-mm-yyyy ")"]

    GROUP OF m.client_id, m.client_name, d.processing_date] ";

    immediately run v_sql;

    END CREATE_STATS_5D;

    END PKG_RISK_MONITOR;

    /

    DISPLAY ERRORS

  • I can add a column to an existing table with the data.

    Hello

    I'm working on
    The Version of database: Oracle 9i

    I can add a column to an existing table that already has data with below given command.

    ALTER TABLE table_name
    ADD the definition of the column_name column;

    Kind regards
    John

    Add to that:

    If your new column is NOT "null", you need the task in 3 steps:

    1. Add the column without a NOT NULL constraint
    2. the default value of the new column added.
    3. Add the NOT NULL constraint in the new column.

    concerning
    AJ

  • To find common data in 2 columns from two different tables.

    Hello

    Could someone help me with a querry to discover common data of 2 columns from two different tables?

    Thank you
    Rajesh

    Try as below.

    select col1 ,col2 from tab1
    intersect
    select col1 ,col2 from tab2;
    
  • Adding a sequential number column to an existing table.

    Greetings.

    I have an existing table of some 30 million lines.

    I would like to add an additional column (I did).

    I want to fill this new column with a sequential number.

    Have tried to create a sequence, I am at a loss on how to trigger the filling of the column.

    Any help would be received with gratitude.

    Thank you

    Published by: 896596 on May 16, 2012 09:05

    896596 wrote:
    Greetings.

    I have an existing table of some 30 million lines.

    I would like to add an additional column (I did).

    I want to fill this new column with a sequential number.

    Have tried to create a sequence, I am at a loss on how to trigger the filling of the column.

    Any help would be received with gratitude.

    Thank you

    Published by: 896596 on May 16, 2012 09:05

    Update new_col is set nextval.seq1;.

  • Add the column to an existing table-based user-defined type

    Hello guys,.
    I am compiling my function that returns a type defined by the user based on an existing table. Throughout the process of initialization so my query returns an additional column - SCORE (1). Here is my package:

    create or replace
    PACKAGE STAFF_AGENCY_PKG AS

    TYPE TYPE_SEEKER_TABLE IS TABLE OF THE DRAW. SEEKER % ROWTYPE;
    FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
    TYPE_SEEKER_TABLE RETURN PIPELINE;

    END STAFF_AGENCY_PKG;
    -------

    create or replace
    STAFF_AGENCY_PKG PACKAGE BODY
    AS

    FUNCTION GET_SEEKERS (IN_KEYWORD IN VARCHAR2)
    TYPE_SEEKER_TABLE RETURN PIPELINE
    IS
    R_TBL TYPE_SEEKER_TABLE; -to return
    BEGIN
    FOR R IN)
    SELECT Seeker.SEEKER_ID,
    Seeker.FIRSTNAME,
    Seeker.LASTNAME,
    Seeker.NATIONALITY,
    Seeker.ISELIGIBLE,
    Seeker.BIRTHDATE,
    Seeker.ISRECIEVEEMAILS,
    Seeker.HIGHESTDEGREE,
    Seeker.ETHNICITY,
    Seeker.GENDER,
    Seeker.ISDISABILITY,
    Seeker.DISABILITY,
    Seeker.CV,
    Seeker.PASSWORD,
    Seeker.PREFFERED_CITY,
    SEEKER. E-mail
    SEEKER. JOB_PREFERENCES_ID,
    SCORE (1)
    THE APPLICANT Seeker
    WHERE CONTAINS (CV, ' < query >)
    < textquery lang 'grammar' = 'context' = > ' |
    GET_RELATED_CATEGORIES (IN_KEYWORD) |
    ' < / textquery >
    < score datatype = "INTEGER" / >
    (< / query > ', 1) > 0
    )
    LOOP
    PIPE ROW (R); -Error (38,10): PLS-00382: expression is of the wrong type
    END LOOP;
    RETURN;

    END GET_SEEKERS;
    END STAFF_AGENCY_PKG;

    How do I change my user type to be sufficient?

    Oracle version 11.2.0.1.0
    Thanks in advance!

    >
    How do I change my user type to be sufficient?
    >
    You will need to create two new TYPEs. The one who has all the columns of the draw. The REQUESTOR table and the new column SCORE, then a TYPE which is an array of the first type.

    See example 12-22 using a Pipelined Table function for a Transformation in the PL/SQl language reference

    http://docs.Oracle.com/CD/B28359_01/AppDev.111/b28370/tuning.htm#i53120

    Here's the first part

    -- Define the ref cursor types and function
    CREATE OR REPLACE PACKAGE refcur_pkg IS
      TYPE refcur_t IS REF CURSOR RETURN employees%ROWTYPE;
      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;
     FUNCTION f_trans(p refcur_t)
          RETURN outrecset PIPELINED;
    END refcur_pkg;
    /
    
    CREATE OR REPLACE PACKAGE BODY refcur_pkg IS
      FUNCTION f_trans(p refcur_t)
       RETURN outrecset PIPELINED IS
        out_rec outrec_typ;
        in_rec  p%ROWTYPE;
      BEGIN
    

    Change

      TYPE outrec_typ IS RECORD (
        var_num    NUMBER(6),
        var_char1  VARCHAR2(30),
        var_char2  VARCHAR2(30));
      TYPE outrecset IS TABLE OF outrec_typ;
    

    to include all the columns you need. Unfortunately, you have to manually list all the columns in the draw. The REQUESTOR table. If you think you need this same structure in other places you must create them as SQL types instead of PL/SQL types.

    This example should be enough to show you how to modify your code to do something similar.

  • Change the Data Type of column on large partitioned Table Tablet

    Hello

    I was tasked to change a certain NUMBER of collar to a colonel VARCHAR2

    It is usually an easy task, but I ran into several challenges due to the size of the table, the second major problem is the compression of the table.

    To begin with, the Table and index are 4.4 to and hold around 11 lines billion. That the Table is compressed, not the index.

    The first option was to add a new collar of VCHAR, update from the Col de NUM, file and then drop the colonel NUM


    We ran this test in the Test environment and because discovered Compression Table that you can only mark the column is not used, and it can only be moved permanently from the Table if you unzip the whole Table and run «...» REMOVE the UNUSED COLUMNS'.

    The second way is to create a separate Table copy with the values of the source of neck, then write to null to the source of neck, change data Type when its empty and then update the source again with the copy Table values.

    The second option, that's what I'm testing, but I work with nearly 30 million lines by daily score, inserts take very long to fill.

    How can I make faster inserts between the Source and the copy Table?

    What other channels follow to accomplish the task above?

    Concerning

    Stephan

    Nowhere in your proposed solution was necessary for you to understand why the data source changes, its as simple that to take what is ons the table (all the facts in the original post) and offering the best way on the basis of previous experience or oracle skills acquired over time.

    If you spent so much time and thought to help with a solution that you did on WHY complain, you could have provided some feasible solutions already.

    No thanks to your information irrelevant and unnecessary, I've implemented a solution already.

    1 export the Source Table

    2. create a 'replica Table' using the DDL source using a temporary table name

    3. import all Partitions in the Table new

    4. before the Cut-Over, synchronize the changes from the Source to the replica Table

    5 rename the Source

    5 rename the Table of replica for the Original Source Table name

    6. slide the original Source Table

  • I need to insert data from the parent to the child table inheritance

    Hi everyone I m using jdeveloper 12

    I have this use EDC:

    I m trying to have mini-programm in which i

    create porject, used to create and assign an employee as the project manager:

    It is therefore my phyiscal using uml data model

    cap1.PNG

    cap2.PNG

    My problem is: I need to see the values in the employee table, choose an employee id s and with the form create in this table: Project Manager: insert the employee with the s project id id

    but when I navigate to the form it is already full of I don't know why

    I did not understand your problem clearly.

    Could you please explain the problem with some screen shots and step by step flow?

    See you soon

    AJ

  • How to add the not null columns to an existing table?

    I have a table with hundreds of row inside. I try to add a new column not null. It gives me the following error

    ALTER TABLE sys.xyz CHANGE xyz_no number 4 DEFAULT '1' NOT NULL;

    ORA-02296: impossible to activate (sys.) - found null values

    Also I tried to do the following

    ALTER TABLE sys.xyz CHANGE xyz_no number 4 DEFAULT '1';

    And then I tried to ALTER TABLE sys.xyz CHANGE xyz_NO number 4 NOT NULL; and I still gives me the same error. I took the tally for null values for the same column and has 1555.

    In this case how can I change my article with not null not?. Please help, I am a newbie in oracle.

    I cry out to you for creating a table as SYS. However, I'm going to fully support Sybrand making. Never, ever, create any object as SYS unless the source code received you from Oracle in a patch.

    Now to your question.

    SQL> CREATE TABLE test (
      2  col1 NUMBER,
      3  col2 NUMBER);
    
    Table created.
    
    SQL> INSERT INTO test VALUES (1,1);
    
    1 row created.
    
    SQL> INSERT INTO test VALUES (2,NULL);
    
    1 row created.
    
    SQL> ALTER TABLE test ADD (newcol NUMBER);
    
    Table altered.
    
    SQL> ALTER TABLE test
      2  MODIFY (newcol NOT NULL DISABLE);
    
    Table altered.
    
    SQL> SELECT * FROM test;
    
          COL1       COL2     NEWCOL
    ---------- ---------- ----------
             1          1
             2
    
    SQL> UPDATE test SET newcol = 3;
    
    2 rows updated.
    
    SQL> SELECT * FROM test;
    
          COL1       COL2     NEWCOL
    ---------- ---------- ----------
             1          1          3
             2                     3
    
    SQL> SELECT constraint_name
      2  FROM user_constraints
      3  WHERE table_name = 'TEST';
    
    CONSTRAINT_NAME
    ------------------------------
    SYS_C0036620
    
    ALTER TABLE test ENABLE CONSTRAINT SYS_C0036620;
    
  • How to remove some columns of an existing table?

    Let's say my table structure is as follows:

    Name of the table: EMPLOYEE
    Columns: Name, date of birth, sex, salary, birthplace, language and so on.

    There are data in the table. Now, I want to delete some columns, hometown and the language, and I don't like the loss of data. In addition, there is no constraint.
    What is the sql command to do this? Thank you!

    Name of the table: EMPLOYEE
    Columns: Name, date of birth, sex, salary, birthplace, language and so on.

    MHO%xe> desc employee
     Naam                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NAME                                               VARCHAR2(30)
     BIRTHDATE                                          DATE
     GENDER                                             VARCHAR2(1)
     SALARY                                             NUMBER
     HOMETOWN                                           VARCHAR2(255)
     LANGUAGE                                           VARCHAR2(30)
    
    MHO%xe> alter table employee
      2  drop column hometown;
    
    Tabel is gewijzigd.
    
    Verstreken: 00:00:07.28
    MHO%xe> alter table employee
      2  drop column language;
    
    Tabel is gewijzigd.
    
    Verstreken: 00:00:00.15
    MHO%xe> desc employee
     Naam                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     NAME                                               VARCHAR2(30)
     BIRTHDATE                                          DATE
     GENDER                                             VARCHAR2(1)
     SALARY                                             NUMBER
    

    Also say what version you have turned on, if it does not work ;)

  • Trigger to insert data on the null columns

    Hi all

    How can I create triggers to insert data into a column null, this column is a Varchar2.

    Thanks in advance.

    Something like this:

    create or replace the TRG_BI_MYTABLE before insert on MYTABLE for each line

    Start

    : new. MYCOLUMN: = nvl(:new.) MYCOLUMN, 'A value');

    end;

  • How to insert data into the BLOB column

    Hi all

    Can someone help me to insert data in the BLOB data type column?

    The structure of the table is
    CREATE TABLE XXATFL_DM_FORCAST_STG
    (
    TASK_ID NUMBER,
    USER_ID NUMBER,
    CREATED_BY NUMBER (15),
    CREATION_DATE DATE,
    LAST_UPDATED_BY NUMBER (15),
    DATE OF LAST_UPDATE_DATE,
    LAST_UPDATE_LOGIN NUMBER (15),
    RECORD_STATUS VARCHAR2 (1 BYTE),
    ERROR_MESSAGE VARCHAR2 (4000 BYTE),
    DATA_FILE BLOB
    )

    I want to insert data into the column DATA_FILE. and this insert statement inside a procedure.

    Please help me as soon as possible because it is very urgent for me

    Thank you and best regards,
    Charrier

    Charrier,

    If you form the string yourself, you can use the function utl_raw.cast_to_raw on your channel.

    http://download.Oracle.com/docs/CD/B12037_01/AppDev.101/b10802/u_raw.htm#997086

    sql> create table t(
      2    id number,
      3    l_blob blob
      4  );
    
    sql> insert into t values(1, utl_raw.cast_to_raw('SampleString'));
    
    1 row created.
    
    sql> commit;
    
    Commit complete.
    
  • Inserting data into one table to another table.

    Hi all

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

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

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

    Thank you

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

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

  • How to join two tables to retrieve the data from the columns in table two. Tables have primary and foreign key relationships

    Hello

    I want to join the two tables to retrieve the data from the columns of the two table passing parameters to the join query. Tables have primary and foreign key relationships

    Details of the table

    Alert-1 - AlertCode (FK), AlerID (PK)

    2 AlertCode-AlertDefinition-(PK)

    Help, please


    ----------

    Hi Vincent,.

    I think that you have not worked on adf 12.1.3.  In adf 12.1.3 you don't have to explicitly create the association. When you create the EO to your table, Association xxxxFkAssoc, will be created by ADF12.1.3 for you automatically. Please try this and do not answer anything... You can also follow the links below. I solved the problem by using the following link

    Oracle ADF Guide step by step - Oracle ADF tutorial: creating a relationship of the master / detail using Oracle ADF

    ---

  • Adding rows or cells to existing Tables in Dreamweaver CC

    Dear Sir/Madam,

    Why can't I add additional cells or columns to an existing table?

    I have a database that I've frequently updated, but I note that since I upgraded my software from Studio MX 2004 to Adobe Dreamweaver CS5.5 (try now Dreamweaver CC) and the table options (such as adding rows/columns) are not available.

    What is the best way to list the alphabetical links. Should I just list people without a table or I can use what I already designed (without having to create a new page, since it will age to enter all the data again)?

    I look forward to hearing from you soon.

    Concerning

    Suzanne

    Make sure that you are in Design view, not to live.

    The editor in Live mode does not give you the standard table options.

    EDIT: I forgot to mention, if your pages use a fluid grid, Fashion Design presentation won't be available if you use DW CC 20141, deleted Adobe Design view for GFL in this version. Here is a discussion which has a couple of workarounds: Re: is it possible to display the design view in the fluid grid pages? and here is the feature request to vote in the section ideas if you are using the latest version: provide "Design view" fluid grid Web pages

Maybe you are looking for