Procedure for inserting rows

dear members,
i have a table with some missing numbers in a col1.
how can i add rows containing missing numbers.
starting and ending number is given in the procedure.
let us say starting from 1 to 10.
table
id col1
1 2
2 3
3 4
4 9
Required Result after running the procedure.
table
id col1
1 2
2 3
3 4
4 9
5 1
6 5
7 6
8 7
9 8
10 10
can i have that procedure.
regards
teefu.
Edited by: user_teefu on Aug 23, 2010 2:19 PM

Hi,
I would do something like that :create or replace procedure t_addrows(
        p_min integer,
        p_max integer)
as
        l_inserted integer;
begin
        insert into t (id, col1)
        select
                idstart+rownum id,
                col1
        from (
                select idstart, p_min+level-1 as col1
                from (
                        select nvl(max(id),0) idstart
                        from t
                connect by level <= p_max-p_min+1
        ) n    
        where not exists (
                select null
                from t
                where t.col1=n.col1
        l_inserted := SQL%ROWCOUNT;
        dbms_output.put_line('inserted : '||l_inserted);
end;
/It gets the max(id) from the table to generate "following" ids.
it uses the connect by level to generate integers between min and max parameters provided.
it does a NOT EXISTS to avoid primary key errors.
Example :Scott@my10g SQL>select * from t;
        ID       COL1
         1          2
         2          3
         3          4
         4          9
Scott@my10g SQL>begin
  2  t_addrows(1,10);
  3  end;
  4  /
inserted : 6
PL/SQL procedure successfully completed.
Scott@my10g SQL>select * from t;
        ID       COL1
         1          2
         2          3
         3          4
         4          9
         5          5
         6          8
         7          1
         8         10
         9          6
        10          7
10 rows selected.
NB :_ I didn't include a COMMIT in the procedure. You decide wheither it should be there or not.

Similar Messages

  • Calling a stored procedure for each row returned

    I need to call a stored procedure for each row returned by a repeating frame. I called the stored procedure from the repeating frame format trigger, but that did not work( it did no populated the tables populated by the stored procedure)
    How can I call a stored procedure for each row returned by a repeating frame.
    Thank you

    Include it as a formula column in your data model.

  • Need to create procedure for insert tax line into ra_interface_lines_all

    Dear
    I need to create a procedure for insert a tax line into ra_interface_lines_all against the line type "LINE".
    after inserting the record i will run the auto invoice program to see the changes. kindly share how i can achieve through procedure.
    scenario:-
    after order dispatch workflow back ground run and data populated in ra_interface_lines_all where interface line id is null there i need to insert tax line against multiple orders.
    I know the join. when line type = 'LINE'  then tax line must have link_to_line_id of the line type line. my question is this when order number change how i can insert tax line against the line type line.
    regards,
    Fs
    Message was edited by: 832296

    Dear
    I need to create a procedure for insert a tax line into ra_interface_lines_all against the line type "LINE".
    after inserting the record i will run the auto invoice program to see the changes. kindly share how i can achieve through procedure.
    scenario:-
    after order dispatch workflow back ground run and data populated in ra_interface_lines_all where interface line id is null there i need to insert tax line against multiple orders.
    I know the join. when line type = 'LINE'  then tax line must have link_to_line_id of the line type line. my question is this when order number change how i can insert tax line against the line type line.
    regards,
    Fs
    Message was edited by: 832296

  • How to create stored procedure for insert update and delete operations with input output paramters?

    I  have the follwing table is called master table contain the follwing fields,
    So here i need to create  three Stored procedures 
    1.Insert operations(1 o/p paramter,and  14 input paramters)              - uspInsert
    2.Update operations(1 o/p paramter,and  14 input paramters)          - uspUpdate
    3.Delete Operations(1 o/p paramter,and  14 input paramters)          
     - uspdelte
    The following is the table ,so using this to make the three sp's ,Here we will use Exception machanism also.
    Location 
    Client Name
    Owner 
    ConfigItemID
    ConfigItemName
    DeploymentID
    IncidentID
    Package Name
    Scope 
    Stage
    Type 
    Start Date
    End Date
    Accountable 
    Comments
    So can u pls help me out for this ,bcz i knew to stored procedure's creation.

    I  have the follwing table is called master table contain the follwing fields,
    So here i need to create  three Stored procedures 
    1.Insert operations(1 o/p paramter,and  14 input paramters)              - uspInsert
    2.Update operations(1 o/p paramter,and  14 input paramters)          - uspUpdate
    3.Delete Operations(1 o/p paramter,and  14 input paramters)            - uspdelte
    The following is the table ,so using this to make the three sp's ,Here we will use Exception machanism also.
    Location 
    Client Name
    Owner 
    ConfigItemID
    ConfigItemName
    DeploymentID
    IncidentID
    Package Name
    Scope 
    Stage
    Type 
    Start Date
    End Date
    Accountable 
    Comments
    So can u pls help me out for this ,bcz i knew to stored procedure's creation.
    Why you have to pass 14 parameters for DELETE and UPDATE? Do you have any Primary Key?  If you do NOT have primary key in your table then in case you have duplicate information, SQL will update both or delete them together. You need to provide DDL of
    you table. What are the data types of fields?
    Best Wishes, Arbi; Please vote if you find this posting was helpful or Mark it as answered.

  • Procedure for inserting data

    With the following insert script, data is inserted into the flight_instance table:
    insert into flight_instance
    select flight_no, 1, 1, 'AAL','06:25','CPH','07:10','DH4', 70, 0,'0:45', 148,
    TO_DATE('20060101', 'YYYYMMDD')+ day - 1
    from days, flight_frequency
    where weekday = TO_CHAR(TO_DATE('20060101', 'YYYYMMDD') + day - 1, 'D')
    and flight_no = 'LH6001'
    and day <= 365;
    This must be done for each flight and there are about 800 flights that have to be inserted or updated.
    I need a procedure that will insert or update each record. Any ideas?
    Thank you!

    Hi,
    Is it a one time job / frequent job? Its good to use
    Anonymous block if it is one time job.
    Using cursor FOR LOOP as specified below
    FOR loopindex in (select flight 800 flights) LOOP
    Do update / Insert using each flight loopindex.flight
    END LOOP
    If inserted / updated rows are more than 10000, commit for every 10000 rows
    I guess it may help you!
    Thanks,
    Sankar

  • PL/SQL procedure for deleting rows

    We have to delete rows from a table by initiating parallel processes depending on no of connections, and also variable commit frequency. The procedure has to start by itself in case of failure of 1 or more parallel processes, by identifying the position where it stopped. Please some one help me what would be th elogic needed to write the [rocedure.
    Thanks in Advance
    Edited by: 864979 on Jun 9, 2011 10:02 PM

    Be careful of how this is designed and coded. It is very easy to do it horribly wrong, causing contention and problems.
    Have a look at DBMS_PARALLE_EXECUTE.
    If the package is not available on your Oracle version, then look at {message:id=1534900} for a manual approach.

  • Stored Procedure for insert in a table

    Hi everybody
    I have to insert a line into a table to initialize the supply of a datawarehouse.
    The table contains:
    Id_chargement Oracle sequence
    date_chargement sysdate
    status 'EN COURS'
    I read some message in this forum but I don't find the solution.
    Can I call a procedure in the workflow ? Or must be use the preprocessing of the first map to call this stored procedure ?
    But for the second solution, if I had a map before, I must change this call.So, it's not very interesting.
    Have you a idea
    Thank you for your help
    Frederic from France

    Hi Mahesh,
    I created a procedure as
    begin
    insert into <table name> values( <timestamp value>);
    end;
    i added this procedure in the process flow, and as you said i added 1- Success, 2 - warning, 3 - error.
    I am able to deploye the procedure and process flow,
    after that when execute the process flow, that just says completed with errors,
    no other information and oracle error messages are abilable in the
    result panel
    Job Final Status : Completed with errors
    Job Processed Count : 1
    Job Error Count : 0
    Job Warning Count : 0
    can you say , what could be the problem??
    Thanks & regards
    raja

  • Procedure for Insert to BULK COLLECT

    hi,
    I have 2 questions-
    1) Say I have below code. I want to call an insert procedure insead of INSERT INTO. If I do would it give any performance issue?
    CREATE OR REPLACE PROCEDURE test_proc (p_array_size IN PLS_INTEGER DEFAULT 100)
    IS
    TYPE ARRAY IS TABLE OF all_objects%ROWTYPE;
    l_data ARRAY;
    CURSOR c IS SELECT * FROM all_objects;
    BEGIN
    OPEN c;
    LOOP
    FETCH c BULK COLLECT INTO l_data LIMIT p_array_size;
    FORALL i IN 1..l_data.COUNT
    INSERT INTO t1 VALUES l_data(i);
    EXIT WHEN c%NOTFOUND;
    END LOOP;
    CLOSE c;
    END test_proc;
    CREATE OR REPLACE PROCEDURE insert_proc ( col1 table.col1%Type,
    col2 table.col2%Type,
    col20 table.col20%Type)
    BEGIN
    INSERT INTO HistoryTable (col1, col2, ...col20)
    VALUES(val1, val2, ...val 20);
    END;
    END;
    2) Is there any clean method to create insert procedure which has 20 columns which I can call in other proc to do bulk insert?

    It is good that you explained your requirements, but you did not give us some data to see with and work with.
    If you could, help us with below details, it might be possible to help you:
    1. Create table statements for your Tables (eg. Checking, Savings and history)
    2. Insert Into statements for Sample data for your Tables.
    3. validations that you need to perform
    4. Expected output based on the Sample data provided in step 2.
    Please do not forget to post your version number
    select * from v$version;Also, use {noformat}{noformat} tags, before and after SQL Statements, Expected Output to preserve spaces and make the post more readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Procedure for inserting a record in HANA

    Hi All
    I have created a table using .hdbtable definition. I have also created an .xsodata service to fetch the details of the table. The problem is when trying to insert data into the table.
    For this, I created a procedure. But when I tried to activate I am getting an error which says "Invalid column name".
    But the Column name which is provided is correct.
    I am stuck and not able to proceed. Please help.
    Thanks in advance
    Meenakshi

    Hi All
    Instead of using a procedure, I tried to achieve the same using server side js. I created a .xsjs file and tried to connect to DB to insert values. But here also no luck. There is an error popping in the insert statement.
    Here is the screenshot of the problem. Any suggestions ?

  • Using stored procedures for insert, update and delete

    Hello all;
    We have a question from our customer (who is the DBA), who has not in the past used TopLink, about whether it makes sense to tie TopLink into existing stored procedures to save and retrieve informations.
    Is it possible?
    Is there any circumstance under which it is a good idea?
    Thanks

    In TopLink any operation for which TopLink generates SQL, can be replaced by custom SQL, or a stored procedure call.
    Custom SQL or stored procedures can be used for each of the descriptor's CRUD operations, but also for mapping queries and named queries. The Mapping Workbench only supports defining custom SQL for the descriptor CRUD operations and named queries, so many of the stored procedures call from the descriptor and mappings will need to be done through amendment methods.
    Whether it makes sense or not depends on the application and the company and their requirements. It will add significant overhead to the development process to have to define and maintain all of the stored procedures, and the stored procedure calls in the descriptors. You may wish develop your application using TopLink generated SQL, and once you have the model and queries stabilized then switch to using stored procedures.
    Whether it is a good idea depends on the application and the company and their requirements. Stored procedures may give the DBA more freedom to change the data-model once in production, and may allow for adding database-level security checks. In general using stored procedures will not improve performance if the procedures contain the same SQL that would have be executed anyway, but they may allow for the DBA to tune the SQL better.

  • Using model 1 Architecture for inserting row into DB...

    The question is on the design of a JSP using Model 1 architecture.
    I have a html form with 3 fields taking input from user. I have made a java bean with 3 instance varibales in the name of the field names and with getter() setter() methods too.
    I dont want to hardcode the database access in the JSP. How do i acheive modularity or make use of object orientation concepts in the JSP to open aconnection and save the record into a database.
    I dont want the conventional way of harcoding like registering DriverManager... Creating Statement opject and OPening Connection...... and with Statement object to call executeUpdate() method...
    These all should be encapsulated in class and methods so that my JSP looks simple......
    Java Gurus, How do i get going.........

    Untill now, I have motsly written java web applications merely showing information; there's no insert or update available. nevertheless, the design pattern MVC or Model-View-Controller can work just as good for display-only web apps as for the rest.
    You're right if you don't want to have the database connection inside your JSP's. So how do you have to deal with it. The letters MVC already tell a part of the story. You have 3 kinds of objects :
    - Model : the so-called Java Beans; these objects refer to the concepts known to the usezr of the web app, like Client, Product, Order, Orderline, Invoice, Payment
    - View : these are the JSP's
    - Controller : this is the heart of the web app; Java uses the servlets to be the controller.
    But there's another kind of object you will need, namely the DAO or Data Access Object. These objects define the contact with the database, contain the SQL-statements and make objects of the Model type.
    I'll give 2 examples. The first is the GeneralDao which you define just once. This GeneralDao contains the database driver you're using.
    /** Java class "GeneralDao.java" generated from Poseidon for UML.
    * Poseidon for UML is developed by Gentleware.
    * Generated with velocity template engine.
    package org.gertcuppens.dao;
    // import java.util.*;
    import java.util.ResourceBundle;
    import java.sql.*;
    /* import org.apache.log4j */
    import org.apache.log4j.Logger;
    public abstract class GeneralDao {
    // operations
    * de GeneralDao is de algemene klasse waar alle andere DAO's of Data Access
    * Objects van erven. Het is de bedoeling om in deze klasse ��nmaal de
    * getConnection te defini�ren
    * <p>
    * getConnection() connecteert met de databank afhankelijk van de JDBC-driver
    * die voorhanden is. Deze methode zorgt ervoor dat alle afgeleide DAO's van
    * dezelfde driver gebruik maken terwijl er toch maar op ��n plaats de naam
    * van de driver gedefinieerd is.
    * </p>
         protected Connection getConnection()
              throws java.sql.SQLException
         Connection dbconn = null;     
         ResourceBundle resBundle;
         Logger mopoLogger = Logger.getLogger("mopo.log");               
         mopoLogger.debug("start connectie databank " );      
              try
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              resBundle = ResourceBundle.getBundle("gcoConfig");
              mopoLogger.debug("ophalen resourceBundle (gcoConfig) " );
              String dbConnectie = resBundle.getString("databaseconnection");
              mopoLogger.debug("lezen databaseconnection in resourceBundle " );
              //dbconn = DriverManager.getConnection("jdbc:mysql://localhost/gco");
              dbconn = DriverManager.getConnection(dbConnectie);
              mopoLogger.debug("maken connectie databank " );
              } catch (InstantiationException e)
                   System.out.println("GeneralDao - Fout bij getConnection - instantiation " );
                   mopoLogger.fatal("GeneralDao - Fout bij getConnection - instantiation " );
                   e.printStackTrace();
              } catch (IllegalAccessException e)
                   System.out.println("GeneralDao - Fout bij getConnection - illegal acces " );
                   mopoLogger.fatal("GeneralDao - Fout bij getConnection - illegal acces " );
                   e.printStackTrace();
              } catch (ClassNotFoundException e)
                   System.out.println("GeneralDao - Fout bij getConnection - class not found " );
                   mopoLogger.fatal("GeneralDao - Fout bij getConnection - class not found " );
                   e.printStackTrace();
              return dbconn;
    } // end GeneralDao
    Each object of the Model type should have a corresponding DAO. In my webapp I had 3 kinds of model objects, so I've defined 3 DAO's. All these DAO's are children of the GeneralDao. I'll give an example of this.
    package org.gertcuppens.dao;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import org.gertcuppens.general.Gebruiker;
    /* import org.apache.log4j */
    import org.apache.log4j.Logger;
    public class GebruikerDao extends GeneralDao {
    * Zoekt de gebruiker op aan de hand van de opgegeven naam en wachtwoord
    * @return Gebruiker
    * @param _naam
    * @param _wachtwoord
    public Gebruiker findGebruiker(String naam, String wachtwoord)
    throws SQLException
         Logger mopoLogger = Logger.getLogger("mopo.log");               
         mopoLogger.debug("start findGebruiker" );      
    StringBuffer zoekString = new StringBuffer();
    zoekString.append ("select * from gebruiker ");
    zoekString.append("where naam=? and wachtwoord=? ");
         Connection con = getConnection();
    PreparedStatement ps = con.prepareStatement(zoekString.toString());
    ps.setString(1,_naam);
    ps.setString(2,_wachtwoord);
    ResultSet rs = ps.executeQuery();
    if (rs.next() )
    Gebruiker gebruiker = new Gebruiker(rs);
    rs.close();
    ps.close();
    con.close();
    mopoLogger.debug("gebruiker gevonden " + gebruiker.getNaam());
    return gebruiker;      
    else {
                   ps.close();
                   con.close();
                   mopoLogger.debug("geen gebruiker gevonden");
                   return null;
    } // end findGebruiker
    } // end GebruikerDao
    Want to know more about this ? Just give me a sign.

  • Inserting row in a able

    I have three table in voucher saving .
    1. header table
    2. item table.
    3. ac table
    my problem is when any field incrises in a window(front end). I have to incrises the column in item table.
    I am using procedure for insert data.
    due to this mantaining very dificult and take time for saving.
    any body know how to insert data without incrising column in a table ,solve this problem.
    thanks in advance
    regards
    pravin

    How it can be possible ?? its impossible .. you have to decide the column length once with respect to your requirments.
    if you daily change your column size .. then it will also effect the underlying index.

  • Inserting rows in ALV

    Hi Experts,
           Which part of the program in BCALV_EDIT04 is responsible for inserting a row in the grid? there is code to handle the data in the inserted line, to check the cells modified using the protocol, and event handler too. Can you please explain which fm or subroutine or step adds a new row to the grid when teh insert button in tool bar is pressed.
    I also want some guidance reg the event handler thing. Is mouse click on the cell makes the methods of the protocol to be called? ( I am a java student.. learning SAP slowly.. can you please help me?)

    methods:
          get_inserted_rows
               exporting
                  inserted_rows type sflight_keys.
    This part of the code is responsible for inserting rows in a grid. We call this method to insert records in the Grid.
    There is no such function module implemented here. We implement the above functionality using <b>Classes and Methods</b>.
    Just go to transaction SE24. You'll have a list of Classes in that transaction. Also, we can implement methods using those classes.
    Regards,
    Pavan.

  • Inserting rows in table control(Module pool)!!

    Hi,
    Pls provide me with some code sample for inserting rows in a table control (module pool)...
    Regards
    Gunjan

    HI
    Y dont u create a TABLE CONTROL using wizard and copy the coding-
    TRY THIS-
    WHEN 'INSR'.                      "insert row
           PERFORM FCODE_INSERT_ROW USING    P_TC_NAME
                                             P_TABLE_NAME.
    FORM fcode_insert_row
                   USING    P_TC_NAME           TYPE DYNFNAM
                            P_TABLE_NAME             .
    &SPWIZARD: BEGIN OF LOCAL DATA----
       DATA L_LINES_NAME       LIKE FELD-NAME.
       DATA L_SELLINE          LIKE SY-STEPL.
       DATA L_LASTLINE         TYPE I.
       DATA L_LINE             TYPE I.
       DATA L_TABLE_NAME       LIKE FELD-NAME.
       FIELD-SYMBOLS <TC>                 TYPE CXTAB_CONTROL.
       FIELD-SYMBOLS <TABLE>              TYPE STANDARD TABLE.
       FIELD-SYMBOLS <LINES>              TYPE I.
    &SPWIZARD: END OF LOCAL DATA----
       ASSIGN (P_TC_NAME) TO <TC>.
    *&SPWIZARD: get the table, which belongs to the tc                     *
       CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
       ASSIGN (L_TABLE_NAME) TO <TABLE>.                "not headerline
    *&SPWIZARD: get looplines of TableControl                              *
       CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
       ASSIGN (L_LINES_NAME) TO <LINES>.
    *&SPWIZARD: get current line                                           *
       GET CURSOR LINE L_SELLINE.
       IF SY-SUBRC <> 0.                   " append line to table
         L_SELLINE = <TC>-LINES + 1.
    *&SPWIZARD: set top line                                               *
         IF L_SELLINE > <LINES>.
           <TC>-TOP_LINE = L_SELLINE - <LINES> + 1 .
         ELSE.
           <TC>-TOP_LINE = 1.
         ENDIF.
       ELSE.                               " insert line into table
         L_SELLINE = <TC>-TOP_LINE + L_SELLINE - 1.
         L_LASTLINE = <TC>-TOP_LINE + <LINES> - 1.
       ENDIF.
    *&SPWIZARD: set new cursor line                                        *
       L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.
    *&SPWIZARD: insert initial line                                        *
       INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.
       <TC>-LINES = <TC>-LINES + 1.
    *&SPWIZARD: set cursor                                                 *
       SET CURSOR LINE L_LINE.
    ENDFORM.                              " FCODE_INSERT_ROW
    HOpe this helps u
    Regds,
    Seema.

  • Inserting row in ALV

    hi  experts ..
    I want to add a row in the alv when i click on add button..
    I know there is insert row and append row buttons available in alv but i dont want those names ..
    Can i change the name of standard buttons or is there sm class that i can use to develop this functionality.
    jagruti.

    Hi Jagruti,
    You just have to add a new button with whatever name you want, and map it to the existing functionality in ALV. It will work and you dont need to do anything else.
    The code will be:
    data:
    lr_button type ref to cl_salv_wd_fe_button,
    lr_function type ref to cl_salv_wd_function.
    CREATE OBJECT lr_button.
    lr_button->set_text( 'Your text' ).
    lr_button->set_tooltip( 'Your tooltip' ).
    lr_function = l_alv_model->if_salv_wd_function_settings~create_function( id = 'INSERT' ).
    <b>lr_function->set_function_std( IF_SALV_WD_C_STD_FUNCTIONS=>EDIT_APPEND_ROW ).</b>
    lr_function->set_editor( lr_button ).
    The method set_function_std sets your funcion to take the behaviour of the standard ALV function for inserting rows. So it would work automatically. You have only changed the text.
    <b>If your problem is solved, please award points and close the threads. Couple of your previous threads are still open, please close them</b>
    Regards,
    Nithya

Maybe you are looking for

  • Servlet to gather information about clients computer

    I was wondering if there is a way using servlets to gather information about a persons computer when they run the servlet. for example, their ip address, name of their computer, etc..

  • Skype won't allow new contact to be added. I am ru...

    Is there a fix for this? Chuck Salem, Oregon

  • Multimapping with Condition

    Hi, Can anyone tell me how to do 1:n multimapping wherein, depending upon one key node of the input file , it has to be posted to different receivers? Input FILE <main data> </main data> <local data> <key1>key</key1> <data1></data1> <data2></data2> <

  • I tunes sinq error message

    as soon as i turn my computer on i will get an error message saying "the procedure entry point sqlite3_wal_checkpoint could not be located in the dynamic link library SQLite3.dll.??????????????? what does this mean? apple support hasnt been much help

  • Query item cost after revaluation

    Dear  All, I want to create inventory aging report with revaluation cost. Could I find all info. from OINM table? and How? Many thanks! Wing