Insert statement with loop function

Hello all,
I'm new with the loop function
What need to do is to use a select statement with a condition
This output needs to be inserted in a table
The values of the condition are stored also in a table
It will be something like this:
BEGIN
  FOR i IN (select nrs from table1)  LOOP
    INSERT INTO table_out_loop
    SELECT * FROM bigtable_vw
    WHERE nr = i
  END LOOP ;
END ;
I cant use a direct insert_into function in this case so I need the plsql to 'look' for the values 1 by 1 from the table1
Any help would be appreciated

Can't you just:
    insert into table_out_loop
    select *
    from   bigtable_vw
    where  nr in (select nrs from table1);
If not, then post a better example and/or rephrase the question...

Similar Messages

  • Error while replacing IF statements with DECODE function in procedure

    Hi All,
    I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
    Procedure:
    IF (var_int_sev = '0')
    THEN
    var_sev := '2';
    ELSE
    SELECT sev
    INTO var_int_sev
    FROM errorconfig
    WHERE errorcode = var_errorcode;
    var_sev := var_int_sev;
    END IF;
    I converted the above IF statement into DECODE function as mentioned below:
    var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
    But it throws below error at the select statement used inside DECODE.
    Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
    Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.

    instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
    read this:
    When your query takes too long ...

  • INSERT statement with JSP

              Does anyone know how to create an INSERT statement with JSP using
              variables??
              I can do the insert if I code the values of the variables in the statement,
              but when I try to use variables to do the insert it tries to insert the
              variable name and not the value of the variable into the table.
              Thanks,
              Doug
              

    "Doug Schaible" <[email protected]> wrote in message news:<bicO7.1279268$[email protected]>...
              > I can do the insert if I code the values of the variables in the statement,
              > but when I try to use variables to do the insert it tries to insert the
              > variable name and not the value of the variable into the table.
              Doug,
              I think you missed the <%= blahblah %> syntax.
              Regards
              drit
              

  • Query in Insert statement with JDBC Rx adapter

    Hi,
    This is a FILE to JDBC scenario.
    My target datatype is like this with sample payload values
    statement_s
    statement_s
       action='INSERT"
      access
        A=1234
        B=1002
    key
       A=1234
       B ="10%"
         compareOperation= LIKE
    A(1..1) is primary key in DB and B(0..1) colunm is an optional one.
    I want to know if such kind of Insert query with(LIKE operator) is possible.
    Please reply me ASAP.
    Edited by: ram pranav on Feb 18, 2009 10:28 PM

    Hi Ram,
    IN case of "UPDATE_INSERT", you can use the KEY tag in your structure. Also you can provide LIKE as an attribute to the KEY element as follows :
    <key1>
         <col4 compareOperation=u201DLIKEu201D>val%</col4>
    </key1>
    But when you are trying to insert the data_, the <key> tags will be ignored and only <access> will be considered._
    action=UPDATE_INSERT
    The statement has the same format as for the UPDATE action. Initially, the same action is executed as for UPDATE. If no update to the database table can be made for this action (the condition does not apply to any table entry), values of the table described in the <access> element are inserted in accordance with the description of the action INSERT. <key> elements are ignored in this case.
    The response document has the following format; one of the two values is always 0 because either an UPDATE or an INSERT action is always executed:
    Go through the link I have provided earlier.
    Thanks,
    Pooja Pandey

  • Insert statement with Date, time into Oracle

    Hi,
    I've got the following statement that I'm trying to insert into Oracle. Actually had to change up the format to dd-mm-yy to get it to insert the date correctly, not sure why, but I've got it "supposedly" formatted to also insert the hours, min., seconds into the db record, but it's not catching it.
    My code:
    INSERT INTO VOTETBL
    (CHANGE_CTRL_ID,BUSVP,BRANCH,VOTE,VOTE_TIMESTAMP)
    VALUES (?, ?,?,?,to_date(sysdate, 'dd-mm-yy hh24:mi:ss'));Shouldn't the sysdate capture all those elements sufficiently? The day, month, year get inserted correctly with this, but not so for the time portion.
    Any suggestions is welcomed.
    Thx.

    ok, thanks.
    I tried making a result set with the following:
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rst = stmt.executeQuery("select to_char(sysdate) from dual");
    Date dualtimestamp = (rst.getDate("sysdate"));But it makes the servlet blow up! Not sure why either, because if I enter that exact statement in Oracle, it pulls back the date and time just like I aim to. But not embedded in the result set statement within the servlet.
    It breaks up somehow and doesn't get that result!

  • Insert statement with timezone asking for parameter

    I have an insert statement in a file.
    When the whole file is executed it inserts around 300 rows in to table.
    One of the insert statement is failing. This insert statement inserts a query into column of a table.
    It is as following
    Insert into hr.TABLE_PATH
    (PATH, TABLE_OWNER_NAME, TABLE_NAME, PATH_NAME, TABLE_ACCESS_PATH_DESC, TABLE_PATH_SQL_TXT, PROCESS_CODE, DELETE_IND, ACCESS_ID)
    Values
    (290, HR, EMPLOYEES, 'Reconc', 'XYZ', 'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )', 'N ', 'N', 2);
    The problem is with this piece of insert:
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp
    : --> is being considered as parameter.
    Where as the whole sql thing needs to get inserted into the table.

    If you are inserting a string, then any quotes inside the string should be replaced with two single quotes,
    try this,
    INSERT INTO hr.TABLE_PATH (PATH,
                               TABLE_OWNER_NAME,
                               TABLE_NAME,
                               PATH_NAME,
                               TABLE_ACCESS_PATH_DESC,
                               TABLE_PATH_SQL_TXT,
                               PROCESS_CODE,
                               DELETE_IND,
                               ACCESS_ID)
    VALUES (
             290,
             HR,
             EMPLOYEES,
             'Reconc',
             'XYZ',
             'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )',
             'N ',
             'N',
             2
           );Note the
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp First off, How are you inserting the data? using sqlldr or utl_file?
    If you are inseting using a script from Sqlplus
    use
    SET DEFINE OFFjust to make sure nothing is treated as a parameter.
    G.
    Edited by: Ganesh Srivatsav on Apr 6, 2011 5:20 PM

  • Help with Loop Function

    I am trying to automate converting Pages documents to Word. Maybe later to reopen them in Pages but with the options set to create flat files.
    I select the files I want and they open ok. The export goes ok and I click the file close button,
    Maybe this close does not work as I get twice as many files open after each loop.
    How do I stop the loop function bringing all the files in again each time.?
    Get Selected Items
    Open Finder Items
    Watch Me Do:
    Click "Pages" in the Dock
    Click the "File" menu
    Export
    Click the "Next..." button
    Click the "<fill the title>" button
    Loop (use the current results as input)
    Your help would be welcome!
    Message was edited by: putnik

    Thanks again,
    The "Dispense Items Incrementally" seems to work well enough. However, now the workflow stops at the end of the second loop. The file is closed but the "Watch Me" function seems to want something else to happen (it continues active). The only first file is still listed in the loop function.
    Get Selected Items
    Dispense Items Incrementally
    Open Finder Items
    Watch Me Do:
    Click "Pages" in the Dock
    Click the "File" menu
    "Export"
    Type '
    Type '
    <Cmd W>
    Loop (up to 10 times, use the current results as input)
    Note that I am learning to avoid mouse gestures where possible as things move about to much...
    Any idea what I need to do?

  • Re-write provide statement with loop

    Hello,
    I am a bit confused how to rewrite a provide statement but with loop instead.
    For example, how would the following code be written with 'loop at':
    PROVIDE * FROM P0001
              FROM P0016 BETWEEN '20020401' AND '20061001'
    ENDPROVIDE
    Thanks for your help.

    Data Retrieval from LDB
    1. Create data structures for infotypes.
    INFOTYPES: 0001, "ORG ASSIGNMENT
    0002, "PERSONAL DATA
    0008. "BASIC PAY
    2. Fill data structures with the infotype records.
    Start-of-selection.
    GET PERNR.
    End-0f-selection.
    Read Master Data
    Infotype structures (after GET PERNR) are internal tables loaded with data.
    The infotype records (selected within the period) are processed sequentially by the PROVIDE - ENDPROVIDE loop.
    GET PERNR.
    PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA
    If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif.
    ENDPROVIDE.
    Period-Related Data
    All infotype records are time stamped.
    IT0006 (Address infotype)
    01/01/1990 12/31/9999 present
    Which record to be read depends on the date selection period specified on the
    selection screen. PN/BEGDA PN/ENDDA.
    Current Data
    IT0006 Address - 01/01/1990 12/31/9999 present
    RP-PROVIDE-FROM-LAST retrieves the record which is valid in the data selection period.
    For example, pn/begda = '19990931' pn/endda = '99991231'
    IT0006 subtype 1 is resident address
    RP-PROVIDE-FROM-LAST P0006 1 PN/BEGDA PN/ENDDA.
    hope it will be of help to u.

  • Creating Multiple INSERT statements with SQL

    is there a way to create multiple INSERT staements with SQL .
    Example scenario : This is only example but i have lot of data in the real time.
    sql : Select Emplid from Table A where Emplid between 100 and 350 will retun me 50 rows . i want to insert those rows into another table.
    I am looking for output like below instead of Giving output just as EMPLIDs
    Insert into PS_LM_DATA ( EMPLID ) values ( 123 )
    Insert into PS_LM_DATA ( EMPLID ) values ( 234 )
    Insert into PS_LM_DATA ( EMPLID ) values ( 334 )
    and so on....
    thanks ,
    Karu

    If you are inserting into another table, you could use
    insert into PS_LM_DATA ( EMPLID ) 
    select Emplid from Table A where Emplid between 100 and 350Example:
    SQL> insert into emp2(empno) select empno from emp;
    14 rows created.
    SQL> insert into emp2(empno) select empno from emp where empno between 7369 and 7788;
    8 rows created.

  • Insert process with Loop

    Hello All,
    I have a procedure which will run when the information that has been entered is correct. Also, I have an insert process when the information is not correct, it will automatically insert the information to the log table after three times attempt. The processes are working fine, but my problem is, when the attempt is more than three times, the process will insert the information each time after the 3rd attempt.
    For example: I attempt 6 times with wrong information , and the insert process ignores the first three and then it will insert 3, 4, 5 and 6. in four rows. I actually want this process only insert the last one (6) in one row not 3,4,5,and 6 in four rows.
    Here is my process:
    BEGIN
    if (:P2_LOG_COUNT>=3) then
    INSERT
    INTO QUEST_LOG
    (USER_NAME, LOG_COUNT, DATE_CREATED, IP_ADDRESS)
    VALUES (:P2_USER_NAME, :P2_LOG_COUNT, SYSDATE,(select OWA_UTIL.get_cgi_env ('REMOTE_ADDR') from dual));
    end if;
    END;
    I appreciate your assistance.
    Thanks,
    Atousa

    You're doing it wrong, fix QUEST_LOG table to include a primary key.
    Either you can:
    * Just keep incrementing :P2_LOG_COUNT as you are already
    * Upon successful state, then if :P2_LOG_COUNT > 3 log it
    I suspect that isn't what you'll want however because the it will never log to QUEST_LOG if they never eventually succeed.
    The only other option is to have a primary or otherwise unique key you can use to identify the row in order to continue updating the count. If you can't identify the row added at attempt 4, and you aren't sure the user wont just walk away from the application at this point, how can you possibly ensure that one and only one row is added from this point onwards?

  • Update statement with Aggregate function

    Hi All,
    I would like to update the records with sum of SAL+COMM+DEPTNO into SALCOMDEPT column for each row. Can we use SUM function in Update statement. Please help me out this
    See below:
    Table
    CREATE TABLE EMP
    EMPNO NUMBER(4) NOT NULL,
    ENAME VARCHAR2(10 CHAR),
    JOB VARCHAR2(9 CHAR),
    MGR NUMBER(4),
    HIREDATE DATE,
    SAL NUMBER(7,2),
    COMM NUMBER(7,2),
    DEPTNO NUMBER(2),
    SALCOMDEPT NUMBER
    Used update statement :
    UPDATE emp e1
    SET e1.salcomdept= (select sum(sumsal+comm+deptno) from emp e2 where e2.empno=e1.empno)
    WHERE e1.deptno = 10
    commit
    Thanks,
    User

    Adding these columns makes no sense, so I'll assume this is just an exercise.
    However, storing calculated columns like this is generally not a good idea. If one of the other columns is updated, your calculated column will be out of sync.
    One way around this is to create a simple view
    SQL> CREATE view EMP_v as
      2  select EMPNO
      3        ,ENAME
      4        ,JOB
      5        ,MGR
      6        ,HIREDATE
      7        ,SAL
      8        ,COMM
      9        ,DEPTNO
    10        ,(nvl(sal,0) + nvl(comm,0) + nvl(deptno,0)) SALCOMDEPT
    11  from   emp;
    View created.
    SQL> select sal, comm, deptno, salcomdept from emp_v;
                     SAL                 COMM               DEPTNO           SALCOMDEPT
                     800                                        20                  820
                    1600                  300                   30                 1930
                    1250                  500                   30                 1780
                    2975                                        20                 2995
                    1250                 1400                   30                 2680
                    2850                                        30                 2880
                    2450                                        10                 2460
                    3000                                        20                 3020
                    5000                                        10                 5010
                    1500                    0                   30                 1530
                    1100                                        20                 1120
                     950                                        30                  980
                    3000                                        20                 3020
                    1300                                        10                 1310
    14 rows selected.

  • Error Running SQL Insert Statement with & in it

    Eclipse: 3.5 Galileo on Window Vista
    OEPE: 11gR1 11.1.14
    I get "invalid character" error when running this query in Eclipse:
    INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take&ndash;out joint can compare!', 1);
    I've tried multiple ways trying to escape the & character, but nothing worked. What is the right way of executing SLQ via OEPE plugin that have special characters in them.
    FYI, the following worked fine in Oracle 10g iSQL*Plus:
    SET DEFINE ~;
    INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take&ndash;out joint can compare!', 1);
    Thanks,
    Dmitri.

    Very interesting case. I tried your insert stmt and got the same error. I finally got it to work by removing the ";" in the end. It looks like the jdbc driver choked up while there is ";" in the middle of the pl/sql statement and ";" in the end. If you remove ";" in the "No take&ndash;out joint can compare!" string and leave the ";" in the end, it also works!
    I don't quite understand why Oracle JDBC dirver behaves like that. I'll investigate it more and we may need to do some preprocessing on the pl/sql statement before sending it to the driver. At the mean time, just remove the ";" in the end if your string literal contains ";".
    Please let me know whether this workaround works for you. Thanks!
    Shenxue

  • Insert Statement with JAVA

    I'm trying to insert Data into an access table. Moreover, I'm able to retrieve data on the table (to prove that I'm connecting fine)... I just can't insert Data
    try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con = DriverManager.getConnection(url);
                   System.out.println("Connection Successful");
                   Statement st = con.createStatement();
                   ResultSet rs = st.executeQuery("INSERT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
                   rs.close();
                   processQuery(con, st); // does what is nessesary to complete the current request
                   st.close();
                   con.close();
              catch (ClassNotFoundException e)
                   System.out.println("failed to load OBCD driver. ");
                   System.out.println ("Class errros: " + e);
              }For some reason, I don't have any errors Its just not inserting the data to the table.. any help would be greatly appreciated

    try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection con = DriverManager.getConnection(url);
                   System.out.println("Connection Successful");
                   Statement st = con.createStatement();
                   //ResultSet rs = st.executeQuery("SELECT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
    Here use update query "executeUpdate("UPDATE TABLENAME SET COLUMN=VALUE,.........................WHERE CANDITION );
    rs.close();
                   processQuery(con, st); // does what is nessesary to complete the current request
                   st.close();
                   con.close();
              catch (ClassNotFoundException e)
                   System.out.println("failed to load OBCD driver. ");
                   System.out.println ("Class errros: " + e);
    U CHECK IT ,I THINK IT WILL WORK

  • Insert statement with using the value in struct

    Would like to clarify, i use cursor for selecting data from tableA and fetch the cusor into a struct. So the struct is holding all my data then i would like to insert all this data into tableB. Can i direct insert the data with the stuct?
    eg: INSERT INTO tableB VALUES (:mystruct);

    See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#i20479
    chapter Inserting PL/SQL Records into the Database
    BTW Update you should use cautiously, not to update all PKses and FKses see http://www.oracle-developer.net/display.php?id=418 for some examples.
    Gints Plivna
    http://www.gplivna.eu

  • QUESTION ON INSERT STATEMENT WITH SELECT

    Hi
    I have a table which contains three fields
    Table name : USERS
    ID NUMBER(10),
    NAME VARCHAR2(50),
    EMAIL VARCHAR2(50)
    SEQUENCE by name SEQ_ID
    I am trying to insert values into USERS from EMPLOYEE by virtue
    of insert into USERS (SELECT NAME, MAIL from EMPLOYEE) but i
    want to have one id for all the rows fetched from my inner
    query.
    I would like to know if here is a way, by which i can fetch a
    constant in my select statement which is not present in the
    table and use it like
    insert into USERS ( SELECT constant, NAME, MAIL FROM EMPLOYEE );
    where constant is some number unique for a given insertion.
    Thanks
    Arun

    Why not just try it? All you had to do was type
    insert into USERS SELECT 1, NAME, MAIL FROM EMPLOYEE ;
    and you would have had your answer immediately instead of
    waiting for me to tell you.
    rgds, APC

Maybe you are looking for

  • Not renaming attachment xml file name in receiver mail adapter

    Hi, I receive SOAP from GRC and need send to Partner an email. I have  SOAP to MAIL scenario where an xml file is picked up and transformed and zipped into the target format in XI which has to be sent as an attachement in an email on the receiver sid

  • Scripting with FCP and compressor

    Hi folks, I run a video transfer business, therefore, my projects are fairly streamlined in terms of the processes. After beginning a FCP export to a .mov file so i can compress into a m2v and aiff with bitvice, can i write a script to automatically

  • BPM CPM BI?

    BPM CPM BI?<BR><BR>What are Diff.between BP(Performance/Process)M CPM BI ?<BR><BR>Please explain me.<BR><BR>Thanks

  • Image rotator problem on Dreamweaver site

    Hi I am running into a problem on my main index site. If you look at the image rotator on the very top of the page http://oldfortestates.com/index.htm via firefox (only that browser) you will see that there is a flashback of some of the images before

  • TestStand - Reload Sequence Files On Start

    I have a question. I am mantaining a OI and some of the users would like to set ApplicationMgr.ReloadSequenceFilesOnStart to ReloadFile_All but some of them strongly prefer the ReloadFile_None option, as this is harcoded on the OI I would not like to