Using a cursor to copy data

I'm writing a script that will take the data in one table, and use a cursor to copy that data to another table. The reason I'm using a cursor is so that I can stagger the dates in a particular field, for testing purposes. I wrote a procedure that will manipulate the data in this table based on the date, so I'm just creating a good amount of data with staggered dates.
DECLARE
    my_row CUSTOMER%ROWTYPE;
    CURSOR my_cursor IS
        SELECT * FROM CUSTOMER;
    counter NUMBER;
BEGIN
    counter := 0;
    FOR my_row IN my_cursor LOOP
        INSERT INTO CUSTOMER_HISTORY
            (CUST_NAME, CUST_CITY, CUST_STATE, CREATE_DATE, ...)
            VALUES
            (my_row.CUST_NAME, my_row.CUST_CITY, my_row.CUST_STATE, TRUNC(SYSDATE - counter), ...);
        counter := counter + 1;
        IF (counter > 15) THEN
            counter := 0;
        END IF;
    END LOOP;  
END;Now, this code does work, and it does what I need it to do. However, what I'd like to know is if there is an easier way. I have to do this with 3 other tables, and some of these tables have 30+ columns, and I'm hoping there's an easier way to copy all of the rows, while changing one column. If not, it's not a huge deal, but that's a lot of column names to copy.
Thanks
Edited by: jjmiller on Jul 14, 2010 1:34 PM

you do not need a curosr loop to do this, a single insert statement will work just fine. something like:
INSERT INTO customer_history (cust_name, cust_city, cust_state, create_date, ...)
SELECT cust_name, cust_city, cust_state, TRUNC(sysdate - MOD(rownum, 15)), ...
FROM customerJohn

Similar Messages

  • I used Migration Assistant to copy data to an new MacBook Pro from an old via my Time Capsule. When asked if to inherit time machine history on the new Mac, I mistakenly said no. How do I go back one step to say yes?

    There isn't enough space on the Time Capsule to create a separate backup of the data on the new MacBook. And I am reluctant to delete old backups of the old MacBook to create space to backup the new machine. This occurred about 3 weeks ago so the data on the two machines are now out of sync. If I start over by formatting the new MacBook and rerunning Migration Assistant to pull data from the Time Capsule, how do i preserve the last 3 weeks of data on the new MacBook, considering that I didn't keep track of which files changed in the last 3 weeks?

    All the rest of the stuff is where it should be.  As best I can tell. I have been going through my programs one at a time to see what works.  With the change in the OS (Launchpad? What the heck?) I am finding a significant number of my old programs are not working. Some I have found upgrades.  But without a working mail program, the machine is pretty useless for work.
    The Apple techies had me run through 3 hours of 'stuff' (holding down keys and restarting, etc, etc).  It still does not launch. I think we are waiting for a 'miracle', but I need to know now if they should just come get this piece of junk or if they really are able to find a solution in a timely manner.

  • LV2009: Graph- Copy Data moves/removes cursors

    Using a right click->Copy Data seems to move or remove cursors from the image copied to the clipboard.  Anyone know of a workaround that doesn't involve screen cap and edit?
    PrtScn result:
    Copy Data result:
    Other results show the cursor changing its value, but only in the vertical axis.
    Thanks,
    Joe Z.

    This forum post is over three years old. In order for the community to better answer your question could you please post a new question and link this older post to it. This will allow it to appear nearer to the top of the postings. Have a great day.
    Alex D
    Applications Engineer
    National Instruments

  • Database Management Copy Data - Replace Option

    Can anyone provide info on how this works? we are using 9.2.1
    When using database management to copy data, when using the replace option, even if we only pick a few accounts to copy, it is erasing all data in the Target scenario. Does the replace option clear all data by default before copying in the selected data?
    we tried to use the Merge option but apparently that doesn't always work for some reason-could be user error. not sure.
    Thanks
    Wags

    Hey Wags- this is expected functionality of the Replace method. It clears all custom/account data for the load entity/year/period combo prior to do the load. For example, if there is P&L data in entity A in Jan 2010 and you load $500 to it in a Sales account, all the rest of the P&L data will be cleared and you'll just have $500 in the Sales account.
    Here's stuff from the guide:
    Several options are available for loading data into an application. You can merge, replace, or
    accumulate the data into the application. You select one of these options for each load process.
    Note:
    You cannot load calculated data into an application.
    Merge
    Select this option to overwrite the data in the application with the data from the file.
    For each unique point of view that exists in the data file and in the application, the value in the
    data file overwrites the data in the application.
    Note:
    If you have multiple values in the file for the same point of view, the system loads only the value
    for the last entry.
    If you select the Accumulate Within File option in conjunction with the Merge option, the system
    adds all values for the same point of view in the data file, and overwrites the data in the application
    with the total.
    For each unique point of view that is in the data file but does not have a value in the application,
    the value from the data file is loaded into the application.
    Replace
    For each unique combination of scenario, year, period, entity, and value in the data file, the
    system first clears all corresponding values from the application, then loads the value from the
    data file.
    Note:
    If you have multiple values in the file for the same unique combination of dimensions, the system
    loads only the value for the last entry.
    If you select the Accumulate Within File option in conjunction with the Replace option, the
    system clears the value from the application, adds all values for the same point of view in the
    data file, and loads the total.
    You can achieve the same result as using the Replace option with the Accumulate Within File
    option by using the Database Management module. You can organize the data in the file into
    groups based on Scenario, Year, Entity, Value, and Period.
    Use the Clear Data tab in the Database Management module to clear each unique combination
    of these dimensions, selecting all accounts including system accounts. Enter the data manually
    in a data grid, or load or copy the data into the application using the Merge or Accumulate load
    options. When you perform the Clear operation for a period in a subcube, data, cell text, and
    line item detail are cleared, but cell attachments are not cleared.
    Note:
    You may need to create several small files to load a data file using the Replace mode, especially
    if the data is very large or if the file contains ownership data. An error message is displayed if the
    file is too large when you try to load it.
    Replace by Security
    This option enables you to perform a data load in Replace mode even if you do not have access
    to all accounts. When you perform the Clear operation for a period in a subcube, only the cells
    to which you have access are cleared. Data, cell text, and line item detail are cleared, but cell
    attachments are not cleared.
    Accumulate
    For each unique point of view that exists in the data file and in the application, the value from
    the load file is added to the value in the application.
    Note:
    Data for system accounts is not accumulated.
    Accumulate Within File
    You can use the Accumulate Within File option in conjunction with the Merge and Replace
    options. This option accumulates the data in the file first and loads the totals into the application
    based on the load option selected.
    File Contains Ownership Data
    If the file contains ownership data, you must indicate this by selecting File Contains Ownership
    Data. If you do not select this option and the data file contains ownership or shares information,
    an error occurs when you load the file.

  • MC82 S076 Copy data - MA023

    Hi Guys,
    First time on this forum, so be gentle
    I am trying to copy data online into a product group in S076 using transaction MC82 (Extras > Copy data)
    I get a message ERROR WHILE COPYING DATA (MA023). I cannot find what this error code is caused by.
    when I do the copy in mass processing it copies but only the first 13 periods (W)?
    Can anybody explain either of these, please?
    Jim Longworth
    swantrix @ runbox.com

    Hi,
    Again, many thanks for your input.
    RMCSCORS has been run, as has RMCSISGN.
    I am using MC82 rather than MC94 since I am copying into the Product Group level of S076, for disaggregation; and MC8Q isn't appropriate since S076 is not "Consistent Planning", it is level-by=level as per standard.
    MC8G gives the same error, most of the time and I have been unable to work out the circumstances. When it does work, it populates with values whichj are not presetn int he source.
    S076 has been configured to be in weeks. The source LIS is in Fiscal periods, weeks and months. Neither S076 or the source have a factory calendar (calendar "XX" is not present, if that matters).
    ======================================================================================================
    Does anybody know what MA023 means or is it just a catchall message with no real meaning?
    Thanks in advance,
    Jim

  • Using one Cursor data in anothe rcursor

    Hi all,
    I have a requirement of processing the following.
    I have to select the rows for which few selected attributes are null. Then I need to take one more attribute for these rows and check that if the value of that row exists for any other row except this one. If that id exists for another row ,then I have to update two fields concatenate with the value.
    Ex:- suppose I have 3 rows for which all the three attributes are null. I have a value say CCN_ID which I have to check if that exists for any other row other than this. That means the CCN_IFD of these 3 rows should be checked for existence in any other rows in the same table. If any of the CCN_ID of these 3 rows exists, then I need to update that row with attribute (Sayx)CCN_ID concatenated by the CCN_ID.
    I wrote the following query to accomplish this.
    select CCN_ID from TEMP_ARTICLE_TABLE where ARTICLE_NO is null and COLOR_BOTTOM is NULL and COLOR_TOP is NULL and CCN_ID IN
    (SELECT DISTINCT CCN_ID from TEMP_ARTICLE_TABLE where CCN_ID in(select CCN_ID from TEMP_ARTICLE_TABLE where ARTICLE_NO is null and COLOR_BOTTOM is NULL and COLOR_TOP is NULL)
    and rowId not in(select rowId from TEMP_ARTICLE_TABLE where ARTICLE_NO is null and COLOR_BOTTOM is NULL and COLOR_TOP is NULL));
    But I was requested to write a Stored Procedure to do this. So, I am thinking of creating two cursors in which the first cursor's data is used in second one as follows.I am receiving compiling errors as follows while compiling t he code.Am I doing in the best possible approach? Is there any other better approach to accomplish my requirement?
    SP Code:-
    CREATE OR REPLACE PROCEDURE SP_ARTICLEDATA_CLEANING IS
    CURSOR Cur_CCNID is
    SELECT rowId,CCN_ID FROM TEMP_ARTICLE_TABLE WHERE ARTICLE_NO is null AND COLOR_TOP IS NULL AND COLOR_BOTTOM IS NULL;
    CURSOR Cur_ModCCNID IS
    SELECT DISTINCT CCN_ID FROM TEMP_ARTICLE_TABLE WHERE CCNID IN(Cur_CCNID.CCN_ID) AND rowId NOT IN(Cur_CCNID.rowId);
    BEGIN
    FOR rec in Cur_CCNID
    LOOP
    BEGIN
    UPDATE TEMP_ARTICLE_TABLE SET COLOR_TOP='FIX_'||rec.CCN_ID WHERE CCN_ID=rec.CCN_ID and rowId in(cur_CCNID.rowId);
    END;
    END LOOP;
    END;
    Errors:-
    [Error] PLS-00225 (5: 102): PLS-00225: subprogram or cursor 'CUR_CCNID' reference is out of scope
    [Error] ORA-00904 (5: 102): PL/SQL: ORA-00904: "CUR_CCNID"."ROWID": invalid identifier,
    [Error] PLS-00225 (11: 102): PLS-00225: subprogram or cursor 'CUR_CCNID' reference is out of scope,
    [Error] ORA-00904 (11: 102): PL/SQL: ORA-00904: "CUR_CCNID"."ROWID": invalid identifier
    Please guide me if there is abetter way or how to correct these errors.
    Thanks,
    Pavan.

    The basic answer to your problem is use SQL. A single SQL statement can very likely do the entire operation. There is no need for using row by row (called slow by slow) processing in PL/SQL.
    PL/SQL is inferior when it comes to crunching database data. That is the territory of the very powerful and very flexible SQL language. Or simply put: Maximise SQL. Minimise PL/SQL.*
    As for cursors - a cursor is the compiled and executable for a source code program (e.g. SQL statement). It is not a result set. This cursor/program outputs data. It even takes parameters in the form of bind variables. Which means the same cursor (executable) can be used repeatedly, even by different sessions, and executed with different parameters (called bind variables).
    Want to insert 10 million rows? Single SQL cursor (executable program). Called 10 million times. Each time with different parameters (bind variables). Via 10,000 different application sessions. At the same time.
    So a cursor calling a cursor - not really a sensible approach. Cannot be done the way you want in your code. Is used for unique processing requirements like running PL/SQL in parallel using pipe line table functions.
    Bottom line - whoever told you to write a stored proc to do this, is wrong. The correct solution is writing SQL to perform the processing and update you need. That SQL can then be placed inside PL/SQL in order to manage the execution of that SQL cursor and deal with validation of input parameters, handling errors, code instrumentation and so on.

  • Copy data from a UDO form to Goods Receipt PO using UI API

    Hi, all
    I tried to copy data from a UDO form to Goods Receipt PO using UI API through following codes.
    It works fine while copying to a Item-type Goods Receipt PO.
    But when the doctype is set to service, I got errors.
    I use for-loop to copy two items, Description and LineTotal, into the matrix of Goods Receipt PO form, but both failed.
    any suggestion?
    Edited by: Chao-Yi Wu on Aug 25, 2009 5:50 AM

    Hi  Chao-Yi Wu ,
    SBO_Application.ActivateMenuItem("2306")
    Dim oFormGR As SAPbouiCOM.Form = SBO_Application.Forms.ActiveForm
    Dim omtxIQC, omtxGR As SAPbouiCOM.Matrix
    Dim oedIQC, oedGR, oed As SAPbouiCOM.EditText
    Dim ocbIQC, ocbGR As SAPbouiCOM.ComboBox
    oFormGR.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE
    oedIQC = oFormIQC.Items.Item("13").Specific
    oedGR = oFormGR.Items.Item("4").Specific
    oedGR.Value = oedIQC.Value
    oedIQC = oFormIQC.Items.Item("21").Specific
    oedGR = oFormGR.Items.Item("24").Specific
    oedGR.Value = oedIQC.Value
    oedIQC = oFormIQC.Items.Item("edComments").Specific
    oedGR = oFormGR.Items.Item("16").Specific
    oed = oFormIQC.Items.Item("3").Specific
    oedGR.Value = oedIQC.Value + ", Goods Recript PO:" + oed.Value
    ocbIQC = oFormIQC.Items.Item("cbDocType").Specific
    ocbGR = oFormGR.Items.Item("3").Specific
    If ocbIQC.Selected.Value = "I" Then
         ocbGR.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)
    Else
         ocbGR.Select(1, SAPbouiCOM.BoSearchKey.psk_Index)
    End If
    omtxIQC = oFormIQC.Items.Item("mtx_0").Specific
    For i As Integer = 1 To omtxIQC.RowCount
    omtxGR = oFormGR.Items.Item("38").Specific
           If ocbIQC.Selected.Value = "I" Then
                oedIQC = omtxIQC.Columns.Item("c_ItemCode").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("1").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
                oedIQC = omtxIQC.Columns.Item("c_AQty").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("11").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
                oedIQC = omtxIQC.Columns.Item("col_19").Cells.Item(i).Specific
                oedGR = omtxGR.Columns.Item("14").Cells.Item(i).Specific
                oedGR.String = oedIQC.String
       Else  
    omtxGR = oFormGR.Items.Item("39").Specific
               oedIQC = omtxIQC.Columns.Item("c_Descrp").Cells.Item(i).Specific
               oedGR = omtxGR.Columns.Item("1").Cells.Item(i).Specific
               oedGR.String = oedIQC.String
               oedIQC = omtxIQC.Columns.Item("col_16").Cells.Item(i).Specific
               oedGR = omtxGR.Columns.Item("12").Cells.Item(i).Specific
               oedGR.String = oedIQC.String
      End If
                Next
    for items the matrix is 38 and for service the matrix is 39
    Rgds
    Micheal

  • How to update data returned using REF CURSOR

    Hi all,
    I am trying to update updated data in a gridview but the update button seem to do nothing as i retrieve data using REF CURSOR.
    Let me describe the architecture of my application first. I'm trying to implement best practice whenever possible. I am following the data access tutorial published in www.asp.net , the only difference is that i have an Oracle (10g) database. So I split my application into three layers, data access, business logic, and presentation layer. I'm also writing all queries in an Oracle package.
    So I have my Oracle packages that perform CRUD operations. Then I have an xsd file that define dataTable based on the package procedure. My business logic layer then calls functions defined in the xsd file. And finally a detailsView control that uses an ObjectDataSource to call business logic functions.
    In a nutshell, I am just trying to update records retrieved using REF CURSOR. Your help is very much appreciated. Please let me know if further details are required. Cheers,

    In the DataSet (xsd) where your DataTable is defined, you just need to add additional methods to the TableAdapter to handle insert, update and delete, either with SQL or by mapping to stored procedures.
    Alternatively in code, create an OracleDataAdapter and supply its InsertCommand, UpdateCommand and DeleteCommand.
    David

  • I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    Many thanks lllaass,
    The Touch Copy third party software for PC's is the way to go it seems and although the demo is free, if you have over 100 songs then it costs £15 to buy the software which seems not a lot to pay for peace of mind. and restoring your iTunes library back to how it was.
    Cheers
    http://www.wideanglesoftware.com/touchcopy/index.php?gclid=CODH8dK46bsCFUbKtAod8 VcAQg

  • Using CRUD procedures to update data and ref cursors to return data

    Hi:
    I am currently evaluating Apex 3.x to replace an existing app that uses lots of procedures to update and return data.
    1. Is it possible to return data from a function that returns a cursor (or from a procedure that has an input/output ref cursor parameter for that matter) ? Example: Let's say I have the following function in a package:
    function get_data return sys_refcursor
    is
    l_cursor sys_refcursor;
    begin
    open l_cursor for select sysdate as field from sys.dual;
    return l_cursor;
    end;
    Can I add a page with a table that is populated based on this function? Based on my research it is not possible, but I want an APEX expert to confirm it
    2. The old application uses CRUD procedures to update date, that is for each table there are 3 procedures, insert update and delete. Question: is it possible to channel all the update, inserts and deletes through these procedures? Furthermore, in lots of cases I use sequences to populate the primary keys, and the new value is returned as output parameter. Can I retrieve the output value and use it maybe in the next page I am branching to?
    In the samples that I've seen the same form is used for insert and update. How do I distinguish between the two modes?
    3. Can you please point me to some samples that show how to do 1 & 2. The standard samples that I've seen use the automatic row processing.
    4. Could you please recommend some good books about Apex or HTML db? I found the documentation unintuitive. It is hard to picture quickly how things tie together by reading this documention. I wish the documentation was more task oriented and presented 'how to...' implement generic patterns used in web apps.
    Thank you in advance

    Hi guys
    Check out the last 2 posts in this thread for ideas on how to implement 1.
    Report on user data from LDAP
    Varad

  • Problem on using Business Object Data Service Designer to copy data to HANA

    Expert,
    I want to use BODSD (v14) to copy tables from SQL server to HANA, so I create Job,  Workflow,  dataflow, source tables in SQL server, target tables in HANA and Querys, then execute the job.
    All tables have been successfully transferred to HANA expect those with Chinese Characters.
    I checked the HANA configuration and even created some Chinese lines into HANA, it is proved that HANA supports Chinese.
    So I suspect that I haven't activate UNICODE witin BODSD, but I don't know how.
    If anybody could offer any help on this problem, I extremely appreciate. Thank you.
    Here is one sector of error messages from BODSD:
    18964     17600     DBS-070401     10/26/2011 3:48:30 PM     Dataflow New_DataFlow|TVGAT
    18964     17600     DBS-070401     10/26/2011 3:48:30 PM     ODBC data source <HANA_hanabox1> error message for operation <SQLExecute>: <[SAP AG][SDBODBC DLL][HDB] General error;274
    18964     17600     DBS-070401     10/26/2011 3:48:30 PM     inserted value too large for column: 定单相关的项目>.
    Thank you.

    I found the answer by myself. post it here . I was using BODSD to transfer tables from ERP DB to HANA.
    The previous error is caused by definitely what the error message means, that the column of HANA table is too short.
    18964  17600  DBS-070401   10/26/2011 3:48:30 PM          Dataflow New_DataFlow|TVGAT
    18964  17600  DBS-070401   10/26/2011 3:48:30 PM          ODBC data source <HANA_hanabox1> error message for operation <SQLExecute>: <[SAP AG][SDBODBC DLL][HDB] General error;274
    18964  17600  DBS-070401   10/26/2011 3:48:30 PM          inserted value too large for column: 定单相关的项目>.
    For example, Table u201CTVGATu201D has one column named u201CVRGARXu201D with the type varchar(20), however, there are lines with long Chinese String like u201C定单相关的项目u201D.
    SQL Server can automatically append that column to hold these long strings, however HANA cannotu2026 so here is problem.
    Now my solution is change the column definition of these HANA tables to longer, varchar(60), then everything is ok.

  • TS4147 i have been using an iPhone 4 till date and now migrated to a iPhone 4s.The contacts are not copied in total from the other phone what should i do

    i have been using an iPhone 4 till date and now migrated to a iPhone 4s.The contacts are not copied in total from the other phone what should i do

    Welcome to the Apple Community.
    Please try the following…
    First check that all your settings are correct, that contact syncing is checked on all devices (system preferences > iCloud on a mac and settings > iCloud on a iPhone, iPad or iPod).
    Make sure the contacts you are adding are added to your 'iCloud' group and not an 'On My Mac', 'On My Phone' or other non iCloud group (you can do this by checking in groups), non iCloud contacts will not sync.
    If you are sure that everything is set up correctly and your contacts are in the iCloud group, you might try unchecking contact syncing in the iCloud settings, restarting your device and then re-enabling contact syncing.

  • Does Mac have a tool similar to snippy or snagit? Do not use Windows. Need to copy data off archived online newspapers.

    Does Mac have a tool similar to snippy or snagit?
    I do not have Windows.
    Need to copy data off archived online newspapers. Unable to do so with screenprint, etc.
    Heard windows has a tool called Snippy, looked at Snagit, but read free download agreement and it reads a bit 'fishy', as the download is only free for 30 days, etc and it talks about fees etc. 

    Mac does have two utilities:   Snagit for Mac and LittleSnapper.  There are a few others.  Snag it for mac is just a better "clippings" thing.  It will not scan your image.  There are OCR products available for Mac which might be able to take your clipping document and scan it back to text.
    Snagit Mac is here:  http://www.techsmith.com/snagit-mac-features.html
    To see OCR stuff do a google search for:  Mac OCR Software
    And you'll get quite a few.

  • Can not copy data within a realtime cube due to combination issues

    Hello all,
    I want to use a planning function on a realtime cube in order to copy data from from Co_area CO1 into Co_Area CO2. The Co_Are and the profit center are part of the realtime cube, but not the nav attribute of the profit center.
    When I test/run the planning function via a sequence in planning modeller I get an error message: The combination 'CO2/PCxy,#' is not valid, valid is 'CO2/PCxy,abcd': characteristic '0PROFIT_CTR' .
    Has this error something to do with the relationship of the master data of profit center and its nav attributes?
    Any help would be great.
    Best regards,
    Stefan form Munich/Germany

    I guess this problem is coming because of some wrong combination of records present in cube for controlling area 1. Make the below changes in the planning function. Dont include profit center in the level. Just include controlling area. Create a characteristic relationship of type derivation by master data attributes. Give source char as Controlling area and target as profit center. This will mantain consistency of char. combinations b/w controlling area and profit center in cube for the newly generated records.

  • ADF 11g can not select and copy data from cell of readonly table in IE

    hi,
    In ADF 11g, when render view object as readonly table with Single RowsSelection, using IE browser can not select and copy data from the cell, but it work in firefox.
    is it a bug?
    Edited by: kent2066 on 2009-5-18 上午8:46

    Hi Timo,
    Sorry forgot to mention versions.
    We are using 11.1.1.7 and IE 9.
    I tried in Google but could not get the solution.
    Kindly let me know solution for this.
    PavanKumar

Maybe you are looking for