Inserting data into a table and insert many records into newtable

Hi all

I have table A and table b.
Suppose that if I insert the data into the table, this table is inserted, the number of records records Count I want to insert in the table B

I have to write a procedure for this cannot so any help on this.


Thanks in advance.


Sikora.

Hello

You can use this anonymous block and extend it to create the procedure. You can delete loop or leave it there and use the cursor loop

DECLARE
   j   NUMBER;
BEGIN
   FOR i IN 1 .. 100
   LOOP
      INSERT INTO A
      VALUES ('col1', 'col2', 'col3');

      j   := j+ sql%ROWCOUNT;
   END LOOP;

   INSERT INTO B   VALUES ('table name ', j);

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      ROLLBACK;
      DBMS_OUTPUT.put_line (SUBSTR (SQLERRM, 1, 200));
      RAISE;
END;

Published by: OrionNet on January 21, 2009 12:53 AM

Tags: Database

Similar Questions

  • Size of the data in a table and the size of the table

    I am trying to determine the size of the data in a table and also the overall table size. I use the following query:

    SELECT BOTTOM (a.owner) as owner,
    LOWER (a.table_name) AS table_name,
    a.tablespace_name,
    a.Num_Rows,
    ROUND ((a.blocks * 8 / 1024)) AS size_mb,
    a.Blocks,
    a.Blocks * 8 Blocks_Kilo_Byte.
    a.PCT_FREE,
    a.compression,
    a.Logging,
    b.bytes / 1024 / 1024
    From all_tables a, dba_segments b
    WHERE the a.owner AS SUPERIOR ("USER_TEST")
    AND a.table_name = "X_TEST_TABLE."
    AND b.segment_name = a.table_name
    AND b.owner = a.owner
    ORDER BY 1, 2;

    Is this the right way to go about finding the size of the data in a table? If this isn't the case, please give your suggestions.

    BTW, this in a 10g version.

    You probably want to use the DBMS_SPACE package. In particular, the procedures SPACE_USAGE and UNUSED_SPACE to get an accurate account of the use of space in a table. Your application may give you a relatively accurate estimate if the optimizer on your table's statistics are reasonably accurate estimates. But there is no guarantee that the optimizer statistics are accurate.

    If you want just an approximate answer and you're comfortable that your statistics are accurate, this query may be close enough. If you want a specific response, however, use the DBMS_SPACE package.

    Justin

  • Protect a document while allowing the insertion of data in a table and the points on a graph.

    I created a Word document that contains a table and a chart.  Can I protect document but allow data entry in the table and allow points appear in the table using Adobe?

    Hi brianh89327665,

    While you can apply a permissions password to a PDF file to prevent things such as printing and editing the document, you can not apply it selectively to parts of the PDF file.

    Best,

    Sara

  • Read data from the Table and load it into the csv file

    Hello

    I would like to read a table (select * from employees) and load the data into a csv file.

    What methods are available?

    Records will be at high volume.

    Thank you

    If it is to do a lot, use APEX.

    Create a new page with an interactive report based on the SQL code you want. When you go to download Excel, it is actually a CSV file.

    If it is large, you may need to go on the FILE_UTL road.

    If it is only once, use an interface such as SQL tool * or SQL * Developer.

    If it's a learning experience, you must do all three.

    MK

  • Select the data in a table and update in another table

    Dear experts,

    create the table TB_ENCRYPT

    (

    Identification number,

    Varchar2 (200) KEY

    );

    INSERT INTO TB_ENCRYPT VALUES(1,'HJUVHDUIFBSDGVU');

    SELECT * FROM TB_ENCRYPT;

    1 HJUVHDUIFBSDGVU

    create TABLE users)

    username, NUMBER of

    password VARCHAR2 (200)

    );

    Insert users

    values (1, 123 # "")

    Insert users

    values (2, 456 #')

    Select * from users;

    1 123 #.

    # 2 456

    I want to select the data KEY for table TB_ENCRYPT column and update in the column of tables for the respective key user password

    TB_ENCRYPT table contains only a single key value. Comparing this key, I want to update the old value of the key to the new value.

    For encryption and decryption I followed the java class method.no is worried about that.

    create or replace

    PACKAGE PCK_ENC AUTHID CURRENT_USER AS

    FUNCTION DECRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.decrypt (java.lang.String, java.lang.String) return java.lang.String ';

    FUNCTION ENCRYPT (VARCHAR arg0, arg1 VARCHAR) AS VARCHAR BACK LANGUAGE JAVA NAME 'Encrclass.encrypt (java.lang.String, java.lang.String) return java.lang.String ';

    END;

    SELECT PCK_ENC. ENCRYPT('1234','HJUVHDUIFBSDGVU') FROM DUAL;

    HERE,

    1234 - is the password of the users table column data

    HJUVHDUIFBSDGVU - represents the key of table TB_ENCRYPT column data.

    Comparing this key, I want to update the old value of the key to the new value.

    I tried with this method

    declare

    cursor c1 is

    Select the key

    of TB_ENCRYPT

    where id = 1

    update the id;

    Start

    for c1_rec looping c1

    update users

    password is PCK_ENC. Encrypt (Password, Key)

    the location being c1;

    commit;

    end loop;

    end;

    /

    Help, please

    You can use the MERGE statement.

    merge into users
    using tb_encrypt
       on (id = userid)
      when matched then
          update set password = PCK_ENC.ENCRYPT(password,key);
    

    And why you encrypt your password. This isn't a good idea. Just password hash.

  • data in multiple tables and columns

    Hello

    How to find if multiple tables are containing the same data?
    Text of the 'Apple' is in three different tables and under three different column names.
    Expected result
     
    fruits_one
    fruits_two 
    fruits_three
    Select name, quantity from fruits_one;
    Apple   1
    Orange  1
    Pear    1
    
    
    select flavour, desc from fruits_two;
    Red,   Apple 
    Blue, Berry
    
    select order,date,details  from fruits_three;
    101  11/11/2011    Grapes
    102  12/01/2010    Apple
    Thank you
    Sandy
    SQL> create table fruits_one (name varchar2(100), quantity number);
    
    Table created.
    
    SQL> insert into fruits_one
      2  select 'Apple'  name, 1 quantity from dual union all
      3  select 'orange'  name, 1 quantity from dual; 
    
    2 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> create table fruits_two (flavour varchar2(100), des varchar2(100));
    
    Table created.
    
    SQL> insert into fruits_two
      2  select 'Red' flavour,   'Apple' des  from dual union all
      3  select 'blue' , 'berry'  from dual ;
    
    2 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> set serveroutput on
    SQL> declare
      2  l_search varchar2(10) := 'APPLE';
      3  l_cnt number := 0;
      4  begin
      5
      6  for x in (select column_name, data_type, table_name from user_tab_cols where data_type in ('VAR
    CHAR2'))
      7  loop
      8
      9    execute immediate  'select count(*) from "' || x.table_name ||'" where upper("' || x.column_n
    ame || '") like ''%' || l_search || '%''' into l_cnt;
     10
     11    if l_cnt > 0  then
     12    dbms_output.put_line('table = "' || x.table_name ||'", column = "' || x.column_name ||'"');
     13    end if;
     14
     15  end loop;
     16
     17  end;
     18  /
    table = "FRUITS_ONE", column = "NAME"
    table = "FRUITS_TWO", column = "DES"
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    
  • Recon trust AD didn't write not shooting data in USR table and console UI.

    Hello

    When we AD Trusted reconciliation, IOM pulls all the information and write it in the UD_ADUSER table, but does not fill in USR table and the IOM UI console.

    I checked the Lookup.ActiveDirectory.UM.ReconAttrMap.Trusted and the Lookup.ActiveDirectory.UM.ReconAttrMap, these searches have all mappings.

    Should I check?

    any help would be appreicated.

    Thank you

    I refreshed the reconciliation profile by clicking on the button create a profile reconciliation in reconciliation of the Console Design tab.

    After that I may jobs recon... it perfectly pulled all the attributes.

    Thank you

  • Insertion of an expiration date in a table and have messages expire without breaking functionality

    I use Coldfusion 9,0,0,251028 on Windows 7 64 bit with a Microsoft Access 97 database.

    The code is for an application that supports a submitted message to a shape and publishes on a different page (breakingnews.cfm). Form of the values are inserted into the table 'news' on a database, including the date that the message was sent (mes_dat) as well as the date it should expire (exp_dat). 

    On the database, is_current and display columns have a default value of 0.

    The action of the form is new_process.cfm, which does two things:

    (1) does < cfset expdate = createdate (end_year, end_month, end_day) >.  End_year, end_month and end_day are the selectors to drop-down list which sets the expiration date.  A problem I've had is expdate cannot be inserted by post_breaking.cfm, but only when it is put online, on my local test server there seems to be no problem.

    (2) includes a model named 'post_breaking.cfm', which runs these queries:

    < name cfquery = "get_init_info" datasource = "#db #" >
    Select id
    News
    where is_current = 1
    < / cfquery >

    < name cfquery = "update_info_1" datasource = "#db #" >
    News Update
    Set is_current = 0, scrollshow = 0
    < / cfquery >


    < cfif get_init_info.recordcount NEQ 0 >


    < name cfquery = "update_info_2" datasource = "#db #" >
    News Update
    display value = 1
    where id = #get_init_info.id #.
    < / cfquery >

    < / cfif >


    < name cfquery = "put_in_info" datasource = "#db #" >
    Insert news
    (is_current, display, mes_dat, mes_tim, mes_sub, mes_text, scrollshow, exp_dat)
    values
    (1.0, #createodbcdate (now ()) # #createodbctime (now ()) # ' #subject # ', ' message # #', 1, #expdate #)
    < / cfquery >

    The message then appears on breakingnews.cfm if the is_current column on the news table is 1.  This is the code I inherited, so I don't know how it does, but the code allows only 5 messages both have is_current = 1.

    The part I'm trying to get moving is to have a query executes loading breakingnews.cfm which checks if the exp_dat is between now() and mes_dat to is_current value 1, while retaining only 5 items with a 1 is_current.

    When breakingnews.cfm is accessed, it executes these requests:

    < name cfquery = "get_info" datasource = "#db #" >
    Select *.
    News
    where
    < cfif not isdefined ("id") >
    is_current = 1
    < cfelse >
    ID = #id #.
    < / cfif >
    order of mes_dat /, mes_tim / / desc/desc
    < / cfquery >

    < name cfquery = "add_exp" datasource = "#db #" >
    News UPDATE
    SET is_current = 1
    WHERE now() BETWEEN mes_dat AND exp_dat
    < / cfquery >

    < name cfquery = "remove_exp" datasource = "#db #" >
    News UPDATE
    SET is_current = 0
    WHERE now() BETWEEN mes_dat AND exp_dat
    < / cfquery >

    This will cause messages that have an exp_dat between now() and mes_dat to be displayed and otherwise not display on breakingnews.cfm.

    However, when a new message is submitted, access to breakingnews.cfm the first time, only the newly submitted message.

    If the page is refreshed, the messages that have been filtered correctly will appear under the new message, but there are now six items to display on the page when there are only five.


    How can I get the exact amount of the messages and display the first time without needing a refresh?

    Google 'top n ms access query' and who will not be a problem.

  • Help in mandatory query - pulling data from two tables and inserting a

    Hi all

    I need your help for the modification of the query to get the desired result.
    I have two tables A and b. using source Insert and select the command, I need to extract data from tables A and B, then insert and C.
    Data and table structures are available below.

    Table (Source Table)

    Status of payment $
    MUL DC 20
    ONLY DC 20
    ONLY 40 PA
    MUL NY 50

    Table B (Source Table)

    State of lang units
    E DC 10
    S DC 10
    NY E 5
    PA S 5

    Based on query, I need the values in table C as mentioned below.
    Table C (Table of Destination) (necessary output query must also be as below)

    The State value

    PA 8
    DC 1

    My query is

    INSERT INTO C(STATE,VALUE)
    SELECT A.STATE, SUM ($) /SUM (UNITS)
    OF A, B
    WHERE PAYMENT = "SINGLE".
    AND A.STATE = B.STATE
    GROUP OF A.STATE, B.STATE

    But the output I get is

    PA 8
    DC 2

    Essentially to DC, I should get 1, i.e., for payment only $ DC is 20 and divided by 20 DC must be 1.
    Let me know where I'm missing.

    Hello

    It will work you need to add units in the group by clause

    SELECT a.state, SUM (dollars) / units
    FROM a, (SELECT state, SUM (units) units
             FROM b
             GROUP BY state) sub
    WHERE payment = 'SINGLE' AND a.state = sub.state
    GROUP BY a.state, units;
    

    Concerning

  • Cases of failure to load data files should ROLLBACK and error only records...

    Hi all

    In my loading of data from source to the target process, for example iam loading 100 records in this 50th record with error, once recording error occurred the total loading process take to fail, recordings must restore and record error need to move the table of errors... one can guide you on this process...

    Thanks in advance...

    30021986 wrote:
    Hi all

    In my loading of data from source to the target process, for example iam loading 100 records in this 50th record with error, once recording error occurred the total loading process take to fail, recordings must restore and record error need to move the table of errors... one can guide you on this process...

    Thanks in advance...

    Hello

    Test this...

    Control flow set to YES
    Set the maximum number of errors allowed on 0 (zero)
    Run the interface

  • How to get data from a database table and insert into a file

    Hello
    I'm new to soa, I want to create an xml with the data from database tables, I'll have the xsd please suggest me how to get the data in the tables and insert in a file
    concerning

    in your bpel process, you can use the db adapter to communicate with the database.
    with this type of adapter, you can use stored procedures, selects, etc to get the data from your database into your bpel workflow.

    When did it call in your bpel to the db adapter process it will return an output_variable with the contents of your table data, represented in a style of xml form.

    After that, you can use the second card (a file synchronization adapter) to write to the content of this variable in output to the file system

  • Insert data into the same table based on certain conditions

    Hello. I'm new to this forum.
    I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:

    Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:

    1. if PaidAmount > 0 & & CurrentInstallment < TotalInstallment then

    CurrentInstallment = CurrentInstallment + 1

    2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...

    So, I have to insert data by incrementing the month and year. for example:

    If currentdata is 11/2012 next data will be 12/2012

    But following will be 01, 2013
    I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit on each record selected and insert data and then turns them into table (MYTABLE) even.

    How to achieve that?

    Thank you.

    978184 wrote:
    Hello. I'm new to this forum.
    I have to write a stored procedure to insert data in a table MYTABLE say, having a structure like:

    Col1 Col2 Col3... TotalInstallments CurrentInstallment PaidAmount MonthYear
    I have to insert all the data that it is in the same table (MYTABLE) except change some fields based on certain conditions:

    1. if PaidAmount > 0 & CurrentInstallment

    CurrentInstallment = CurrentInstallment + 1

    2. in the field MonthYear I have data ex. 01/2012, 11/2012 formate(month/year)...

    So, I have to insert data by incrementing the month and year. for example:

    If currentdata is 11/2012 next data will be 12/2012

    But following will be 01, 2013
    I have to select all records that belongs to the previous month (across the field MonthYear) and put the audit & on each of the selected data record and insert then turns them into table (MYTABLE).

    You can do this way:

    This is not tested, but if you can provide the example of table structure and data (IN create table and insert scripts), it can be put to the test.

    insert into your_table
    (col1, col2, col3...current_installment, month_field)
    select col1, col2, col3..,
           current_installment +
           case when paidamount > 0 and current_installment < total_installment then
            row_number() over (
                                partition by column1, column2,.. columnn      -->You may choose partition if you want the
                                                                              --Increment of Current_installment to reset after particular combination ends
                                order by primary_key        -->Order the Increment, you may choose to add more columns to order by
                              )
          else
            0                                               --> if condition is not met, then Add 0
          end curr_installment,
          add_months(to_date(month_field, 'MM/YYYY'), 1) nxt_month
      from your_table;
    
  • 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.

  • Of the data in the table to get a tree using declarative and perform operations above.

    Hello

    I use Jdeveloper 11.1.2.4.

    I'm creating a declarative component. The component is supposed to display the data in a table and allow the user to remove entries of it.

    The table should be included in a pop-.

    From now on, I made a picture of the tree within a collection of panels. I'm creating a tree in the pagedefinition of the ViewController project file and passing the tree of the same model to the component attribute declarative. After binds the attribute passed to table component tree declarative, I am able to fill lines. First please let me know if my approach is correct or not. The user can select any row of the table and press delete. The button must remove the entry from the table. Is it possible to remove operation on the table in the declarative component.

    Thank you

    First of all, please let me know if my approach is correct or not.

    Seems ok

    The user can select any row of the table and press delete. The button must remove the entry from the table. Is it possible to remove operation on the table in the declarative component.

    You have several ways to do this:

    (a) similar to the declarative component attribute, you can bind methods, for example: ADF Essentials eCourse - declarative components ADF: work with methods

    (b) pass the name of the iterator to your component and then use it to remove programmatic in backing bean

    (c) create pageDef declarative component for, something similar to this: ADF practice: liaison for component container declarative

    Dario

  • Table and a Temperory table?

    Hello
    We develop banking applications, that is why we must always maintain the permissions on the changes. For example, suppose that,

    car sales of currency system maintains a list of available currency exchange rates. To store these exchange rate, we maintain a table. There fields 'currency_code, currency_rate, is_authorized.

    * "authority level" 1 user * is allowed to simply update the rate of the currency, and the app store in the database as an entry not verified. " This unverified currency_rate should not be displayed in the form of sales, until the agent level 2 authority checks the registration, the system must show users the previous rates.

    to do this, at the moment, our practice is
    (1) we create another table with the same fields, but with a different name

    for example: rates_table_master and rates_table_temp

    (2) when the authority level 1 user updates the rates, store us them in the array of _temp until verification.
    (3) when such a record is checked, the same record is inserted to the table as verified record master and is removed form the temporary table.

    If you have a better way to do this, please let me know.

    Thank you!

    NIghtbeat wrote:
    I thank very you much for the QUICK response. :-)
    The question is,

    I need to retain the values of the previous record to display in the form of the business user, until new values are checked.

    for example:

    cur_code |    rate | is_verified
    ------------------------------------------------------------
    USD | 114.1562 | THERE
    USD | 113.4512 | N

    Suppose that Y is finally checked rates and N for pending the new value.
    but for USD there are two values in this table. If I used cur_code as the primary key, I can't insert another record with USD.

    This is where your design is wrong. You simply need to use an internal number (typically generated by a sequence) as your primary key, and the cur_code should be just data (not only indexed if needed). It's a bad habit to use the data of the user as primary key, cos if a requirement of the company stipulates that some 'codes' should be changed i.e. "USD" should now be "USAD", then it ends that need to be changed on several tables that use it as a foreign key, rather than simply to change the data on one table and have the primary/foreign keys kept safe in their own country.

    ;)

Maybe you are looking for

  • Problem notifications Todoist on SWR30

    I have problem with notifications on Sony smartband SWR30. All other applications work fine and I can see notifications on my talk SWR300 smartband

  • Error code of Vista SP2 0xC004F055

    Original title: Vista S | P2 Vista sp2 said "could not install, undoing changes".  On reboot I get 0xC004F055 error code "the software licensing service reported that the Basic Reference is not available.  Then a notice of activation of Windows. No b

  • Impossible to burn discs on HP 6250

    When you try to burn pictures on an HP 6250 on disc (CD) I get all the way to burn disc, but when I select "Burn" nothing happens. However, if I transfer the images to a flash (of pors E or F) drive and then upload them to my HP laptop I can 'burn di

  • Completely lost and confused about this thing of VM...

    Hello... I'm eager to try this thing any virtual machine so that I can try windows 10. I can't just update windows 10 because I use my laptop for school and there are too many conflicts, glitches, or whatever you want to call them between the program

  • EliteBook fresh 8570p install readers

    Hey guys,. I downloaded windows 7 Home premium (64-bit) everything is there. I did a new install. My problem is that I have gave me this link drivers Do I have to download everything on this page. Also, why are there so many network keyrap. Thanks to