Need feedback on how to tune that procedure

I have this procedure:
PROCEDURE need_a_tune IS
CURSOR c_tran IS
SELECT c1,c2,c3
FROM t1
WHERE c1 <= sysdate -7 FOR UPDATE;
BEGIN
FOR v_tran IN c_tran LOOP
BEGIN
INSERT INTO t2@another database (c1,c2,c3)
VALUES (v_tran.c1, v_tran.c2, v_tran.c3);
DELETE FROM t1 WHERE CURRENT OF c_tran;
END LOOP;
COMMIT;
END need_a_tune;
That procedure transfer data from database a to database b, then purge the table t1 in database a.
The cursor returns about 5millions rows. That procedure runs for about 2 hours.
I want to change this slow serial process to a fast batch process.
The guy who wrote that procedure is of course not here anymore. And i have no clue why he lock the table in the cursor. Since right after the transfer is completed, he delete the row in t1. So why the lock? Even if he lock then release the lock after the transfer, the rows are not there anymore, so no update/delete on t1 for those row anyway.
1) is it possible to change this code so it is done in sql rather than in pl/sql?
2) if not, how do i change this to a forall statement?

nice idea, but you can't use returning into with
insert as select:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table exm(id primary key) as select object_id from all_objects
  2  where rownum <=100;
Table created.
SQL> declare
  2  type num_tbl is table of number;
  3   ll_num_tbl num_tbl;
  4   begin
  5   insert into exm(id)
  6  (select object_id * 100 from all_objects where rownum
  7   <=100) returning id into ll_num_tbl;
  8  end;
  9  /
<=100) returning id into ll_num_tbl;
ERROR at line 7:
ORA-06550: line 7, column 9:
PL/SQL: ORA-00933: SQL command not properly ended
ORA-06550: line 5, column 2:
PL/SQL: SQL Statement ignoredAmiel

Similar Messages

  • Need urgent help - how to call a procedure from sql returning a rowset

    Hello,
    I need to send a SQL Query from a VB application to let it execute on the oracle DB. This query needs to call a procedure/function, which returns a resultsets, so that i can to a (Where x in ( <call procedure> )). Would result in Where x in (50,100,3094).
    Is this possible in oracle, and how?
    Thanks.
    Daniel Meyer

    Hi Daniel,
    I had a similiar problem yesterday.
    Thanks to the nice people in this forum I was able to figured that out.
    So here is a PL/SQL Oracle 9i code for your reference.
    You can create and test it using the SQL Plus console.
    I used this stored procedure in my VB .NET and worked fine!
    I am enclosing the VB code in this reply as well.
    One last note: in order to test it in the VS .NET, don't forget to download the Oracle ODP driver for .NET
    Good luck!
    Amintas
    create or replace package pkg_emp
    AS
    type rc_emp is ref cursor;
    end;
    create or replace
    procedure SP_GetEmpData(v_empno IN emp.empno%Type,
    v_ename IN emp.ename%Type,
    emp_cur OUT pkg_emp.rc_emp)
    is
    begin
    if v_empno is not null and v_ename is null then
    OPEN emp_cur for
    select empno,ename,sal
    from emp
    where empno=v_empno;
    elsif v_ename is not null and v_empno is null then
    OPEN emp_cur for
    select empno,ename,sal
    from emp
    where ename like v_ename ||'%';
    end if;
    end;
    /* Testing the stored procedure */
    /*#1 */
    var myresultset refcursor;
    execute SP_GetEmpData(7900,null,:myresultset);
    print myresultset;
    /*#2 */
    var myresultset refcursor;
    execute SP_GetEmpData(null,'A',:myresultset);
    print myresultset;
    -x-x-x-x-x-x-x-x-x VB .NET CODE x-x-x-x-x-x-x-xx-x-
    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcurar.Click
    Dim dr As Oracle.DataAccess.Client.OracleDataReader
    Try
    If txtEmpNo.Text <> "" Then
    dr = GetData(CInt(Val(txtEmpNo.Text)), "")
    Else
    dr = GetData(0, UCase(txtEname.Text))
    End If
    txtEmpNo.Text = ""
    txtEname.Text = ""
    Catch ex As Exception
    Response.Write(ex)
    End Try
    drgTest.DataSource = dr
    drgTest.DataBind()
    End Sub
    Private Function GetData(ByVal v_empno As Integer, ByVal v_ename As String) As Oracle.DataAccess.Client.OracleDataReader
    Dim cn As New Oracle.DataAccess.Client.OracleConnection(ConfigurationSettings.AppSettings("ConnectionString"))
    Dim cmd As New Oracle.DataAccess.Client.OracleCommand
    Dim dr As Oracle.DataAccess.Client.OracleDataReader
    cmd.Connection = cn
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = "SP_GetEmpData"
    cmd.Parameters.Add("v_empno", Oracle.DataAccess.Client.OracleDbType.Int32).Value = IIf(v_empno = 0, System.DBNull.Value, v_empno)
    cmd.Parameters.Add("v_ename", Oracle.DataAccess.Client.OracleDbType.Varchar2, 40).Value = IIf(v_ename = "", System.DBNull.Value, v_ename)
    cmd.Parameters.Add("rc_emp", Oracle.DataAccess.Client.OracleDbType.RefCursor).Direction = ParameterDirection.Output
    Try
    cn.Open()
    dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
    Catch ex As Exception
    Throw ex
    Exit Function
    End Try
    Return dr
    End Function

  • I tried to take a screenshot with the command,shift,3 and it worked like for a while and now my macbook wont screenshot at all and i need to know how to fix that like now please?

    its not that i dont know how to take a screenshot its that whenever i try to it doesnt work at all. I have took lots of screenshots on this macbook before and didnt have a problem but now i cant take any at all. Please help me

    The first step is to try this Microsoft fixit:
    http://support.microsoft.com/mats/Program_Install_and_Uninstall
    If that doesn't work we will have to try something more complicated. It is a could not open file error message from the installer.

  • I want to transfer lots of vhs home movies to dvd, need advice on how to do that.

    i was looking at a roxio vhs to dvd product for mac, but i'm not sure it's compatible with the new imac i just bought.  Any advice?

    Rather than the Roxio product, I would recommend that you look at the products from El Gato.
    I used the EyeTV Hybrid and it worked great. It attaches to the Mac via USB and attached to the VHS deck through composite cables (rca jacks). The EyeTV Hybrid will import your VHS, but it will also turn your Mac into an HD TV if you add a rabbit ears antenna. You can record and edit TV shows.
    If you use this option, you can import the VHS into the EyeTV software. You can them import it into iMovie if you like to do editing. Then transfer to iDVD to burn a DVD.
    El Gato makes the hardware (but not the software) for the Roxio product. They also make their own version of the VHS capture product with their own software.  I have no opinion on whether it is any good or not, but I have seen posts by others who had a difficult time with it.
    El Gato EyeTV website.
    If you go up a few hundred dollars in price, a company called Grass Valley makes some Digital Analog Converters which will also capture VHS. You attach via RCA cables to the VHS deck, and attach to Mac via Firewire, so make sure your Mac has Firewire. People have tried the ADVC 300 and the ADVC 110 with good results.
    One more thing, if you have a brand new iMac, it may not come preinstalled with iDVD. You may need to purchase iDVD or Toast from Roxio to be able to make DVDs. You can also buy Compressor from Apple to make DVDs. The Roxio option includes a basic version of Toast.
    Finally, here is a movie I made after capturing with the EyeTV Hybrid so you can get a feel for the quality. It is not great, because the quality of a VHS is not even as good a standard definition TV, but it still came out pretty good. I would not expect it to look great on a big screen TV, though.

  • Tune stored procedures

    Hi
    I have some questions ,whenver i am going to interview ,i unable to answer these questions in confidencially
    1)How to tune the stored procedures,functions?
    2)What is bit map indexes why it mostly used in datawarehousing envornment ,please brief about architecture of bit map indexes?
    3)is it update materilized view ?
    4)I have a view ,it has contains columns from tables ,is it possible to update that view?
    5)What is difference between materilized view and view?
    Regards
    Mohan

    RTFM A harsh and unhelpful but nonetheless accurate assessment of Mohan's needs.
    Mohan
    Your questions are pretty wide ranging and most of them require only basic understanding of Oracle databases. Only the headline question - how to tune stored procedures - would take more than a couple of sentences to answer.
    So, I have to ask, what sort of jobs are you being interviewed for? I fear you need to read up on the documentation. Even if you memorised the answers we could give here that wouldn't help you answer the other leftfield questions that are going to hit you.
    Firstly, read all of the Concepts Manual: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/toc.htm
    Only then should you move on to these bits.
    1)How to tune the stored procedures,functions?
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/12_tune.htm#870
    2)What is bit map indexes why it mostly used in datawarehousing envornment ,please brief about architecture of bit map indexes?
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96520/indexes.htm#97322
    3)is it update materilized view ?
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96567/repmview.htm#51010
    4)I have a view ,it has contains columns from tables ,is it possible to update that view?
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96524/c11schem.htm#19229
    5)What is difference between materilized view and view?
    A view is basically a stored query. It occupies no space and it cannot be used to enforce integrity constraints. A materilialized view is more like a table - it requires storage, can have keys and foreign key references - but it's data is derived from data in actual tables. Read the Concepts manual.
    Cheers, APC

  • How to execute the procedure in sap b1

    Hai to all,
                 I done a procedure in sql server .but i don't know how to execute that  procedure in sap b1?
    can anyone help me immediately.
    Regards,
    Ramya.S

    Dear Ramya.S,
    You could execute the store procedure by using Recordset object in SDK DI code. It is like:
    Dim myRecordSet As SAPbobsCOM.Recordset
    myRecordSet =                                   
    SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecord
    set)
    myRecordSet.Command.Name = "TestStoredProcedure"
    myRecordSet.Command.Parameters.Item("@ItemLike").Value = "IT%"
    myRecordSet.Command.Parameters.Item(2).Value = "C0001"
    myRecordSet.Command.Execute()

  • How to validate that only one check box is checked in detail block

    Hi All,
    I am using oracle Forms 10G on windows.
    I need help on how to validate that only one check box is checked in detail block. I have multiple records in the detail block and I have check boxes for each record in the detail block.
    I have a button to select the values from the detail records where the check box is checked. But I want to make sure that only one record is check not more than one.
    How do I validate this on a push button trigger?
    Thanks

    When I've done this kind of thing, I create a Form level variable of TYPE number and then add or subtract to this variable as I check and uncheck the checkboxes. If the value of the variable is 1, then you know that only one checkbox is selected. If the value is greater than 1, then you know the user has selected more than one check box. You could also add code to your When-Checkbox-Changed trigger to test the variable and instruct the user to un-check selected record before selecing a new record.
    With respect to the Form level variable, you can use a GLOBAL, PARAMETER or Program Unit package specification. I prefer to use the PU Package Spec as this method has a smaller memory footprint. For example, in the Program Unit node of the object navigator create the following;
    /* Form variables package spec */
    PACKAGE Form_Vars IS
      CheckBox_Cnt     NUMBER := 0;
    END;Now in your When-Checkbox-Changed trigger...
    BEGIN
       IF ( Form_Vars.CheckBox_Cnt = 0 ) THEN
          Form_Vars.CheckBox_Cnt  := Form_Vars.CheckBox_Cnt  + 1;
       ELSE
          /* it's assumed the value is greater than 0 */
          Message('Please uncheck selec ted record before choosing a new record.');
          RAISE Form_Trigger_Failure;
       END IF;
    END;Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.
    Edited by: CraigB on Feb 3, 2011 10:15 AM

  • How to call a procedure designed in Report Builder?

    Hi everyone,
    The Problem?
    I set up a procedure and would like to call this procedure in reports builder 6.0. I need to know how to call a procedure in reports builder.
    Thanks
    Tom Gilmore

    You can call
    procedures from a formula column's PL/SQL code.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Thomas Gilmore ([email protected]):
    Hi everyone,
    The Problem?
    I set up a procedure and would like to call this procedure in reports builder 6.0. I need to know how to call a procedure in reports builder.
    Thanks
    Tom Gilmore<HR></BLOCKQUOTE>
    null

  • How to call Stored procedure in SMP 2.3 ?

    HI Experts,
    I have stored procedure in SQL Server, in that i have Select query with WHERE Condition, how to call that procedure in SMP Application .

    Do you want to create mbo from that stored procedure?  Not sure if this document helps you Example: Parameters and Stored Procedures

  • Need a confirmation pop up in a procedure...Is it possible...please help

    We are calling a procedure in Java servlet through oracle apps..We need a confirmation pop up in that procedure present in java servlet..Is this possible ???
    for an Understanding:
    Apps ==> Java Servlet ==> Oracle Procedure.
    in Oracle procedure is it possible to put confirmation box?
    Will appreciate your help.
    Thanks in advance...

    Thank you!
    Actually I Tried to display an alert box through Htp.p('<script>alert("hi");</script>');
    but it's thoruh-up error. As i am calling Servlet from oracle Apps. I tried through this way. Now I understand this is not possible. I will go some other way to do this.

  • Need tutorial on how to produce video

    I can't find this anywhere. I need to find a tutorial of some kind that will teach me how to produce video using still images and vector art among other non-video things.
    It needs to be from the ground up as I've really only been poking around in it (and Premiere and Soundbooth) for about a week.
    Windows XP
    CS3 Master Collection
    computer designed and built for the software

    Man, I was hoping you wouldn't say CIB. I have the Flash one and while it's a little informative, I can't say I'm impressed with it. However, it may give me the foundation I'm looking for here.
    I'm already fairly well versed in Illy; will just need to learn how to take that knowledge and apply it to video resolutions (this aspect ratio thing of 0.9 and 1.2 has got me spinning when I can't figure out how to properly view a finished product as it will be seen on something other than a computer screen).
    Six weeks may be a bit too long. What I need first is basically something a tad better than a decent Powerpoint presentation for DV. I don't need to produce something right off the bat that we'll use for TV commercials; I just need to show the higher-ups that the money they invested in this software (that we were on schedule to buy last September instead purchased last month) was worth it.
    I have no doubt that experience is a major factor here. But I'm barely treading water here. If I don't find a surfboard soon, I'll drown. However, based on what's been done for us by "professionals" in the past, the bar isn't set very high for me.
    I haven't bothered with any of the GTA games. They don't make that for PCs, do they? I'm not a gaming console guy.
    Dropping stuff in the project window I have down no problem; it's knowing what needs to be done beforehand to the files I'll drop there and how to accurately preview them that's raising my blood pressure.
    Knowing I won't knock anything out of the park any time soon, I've started small: a 2.5 second "signature" to be placed at the end of a commercial or segment. Black screen, PS-treated background element with a minor scaling effect, and logo with a short wave file. I thought I had that relatively simple thing figured out, but I can't seem to find a way to view it as it would appear on a widescreen TV. It's just stretched and I can't tell if it just looks like that on my computer screen because of how that displays aspect ratio and it will look fine on our widescreens in the stores or not.
    If I can figure out that 2.5 spot, I may just have a chance at figuring out how to create the rest of it.
    Thanks for the good luck... I know I'll need it.

  • I would like to know how to insure that all track from a CD I rip into i-tunes all go into the same file regardless of the artist on the CD. I was recdently importing an All Time Low CD into i-Tunes for my daughter and because one track featured a guest a

    i would like to be able to insure that when i import a CD into i-Tunes that all tracks from that CD go into a single file for that album in their proper order regardless of whether or not there is a featured artist on one or two tracks or whatever. i recentl;y imported an All Time Low CD into i-Tunes for my daughter and because one song featured a guest artist i-Tunes placed that song in a seperate folder and so when i synced my daughters i-Pod Touch that one track is not with the rest of the tracks form the album and has to be listened to seperately. The song is from the same album and should be where it belongs with the rest of that album so she can listen to the entire album with the tracks in the proper order. I am sure that this can be done i just don't know how.

    Edit the Name of the problem song to Name [Feat. Guest]
    Change the Artist of that song to All Time Low
    marley2012 wrote:
    ... and i want to make sure that from now on all songs from any CD I import into i-tunes all go into the same album file if they are on that album originally. i do not want i-tunes seperating songs from my CD's for any reason. hopefully this is more clear.
    What you want cannot be done. iTunes has its quirks, and the above is the kind of workaround needed to make the media display sensibly on any device. The article I pointed you to has others that you may find useful in future.
    tt2

  • How do you download albums to i tunes that are compilations and keep them together as a album

    how do you download albums to i tunes that are compilations and keep them together as an album i have several discs that have downloaded singley the i tunes is a mess

    Steve MacGuire aka turingtest2 - iTunes & iPod Hints & Tips - Grouping Tracks Into Albums - http://www.samsoft.org.uk/iTunes/grouping.asp (older post on Apple Discussions http://discussions.apple.com/message.jspa?messageID=9910895)
    Quick answer:  Select all the tracks on the album, File > get info, and either give them all a single "album artist", or check the "compilation" flag (as in https://discussions.apple.com/message/17670085).
    If these are from multiple-CD sets you may also need to enter the appropriate information in the disc number fields.

  • My ipad is locked after entring wrong pasword more than 10 times and i did not back up my ipad. now my device is not able be conncted with i tunes to restore or update, i need a help how can i unlock it?

    my ipad is locked after entring wrong pasword more than 10 times and i did not back up my ipad. now my device is not able be conncted with i tunes to restore or update, i need a help how can i unlock it?

    You have to restore the iPad by syncing to the original computer that you synced to.
    This article explains the process.
    http://support.apple.com/kb/ht1212

  • Cracking the procedure-Need Feedback!

    Hellow everyone...this is my Q, i got basic code put together, need some help to complete the following procedure(i'm working on my programming skills with pl-sql) kindly guide me...if i'm wrong !
    write a function/procedure that will take a year parameter(e.g 2007)
    and will go through all AP Invoices (with invoice_date falling within that year)
    for the Vision Services organization (org_id=458) and output all
    project numbers that are associated with any of these invoices.
    Also output the count of project related invoices and a count of non-project related invoices
    ----basic information of columns and tables necessary to write procedure--
    SELECT ppa.segment1 project_numbers
    FROM pa_projects ppa
    ,ap_invoices_all api
    WHERE api.org_id='458'
    AND invoice_date BETWEEN '01-JAN-2007' AND '31-DEC-2007'
    AND api.project_id = ppa.project_id
    -----My procedure- (It has to be corrected--)--will appreciate some feedback
    create or replace procedure year_parameter (p_year in varchar2,
    p_out out number)
    as
    v_year varchar2(10);
    v_out number ;
    cursor c1(p_year in varchar2) is
    select project_id,invoice_date
    from ap_invoices_all api
    where api.org_id='458'
    and substr(invoice_date,7,10):= p_year;
    --and to_char(invoice_date,'YYYY')='2007';
    BEGIN
    c_rec is c1%rowtype;
    for c_rec in c1
    loop
    select pa.segment1 into v_out
    from pa_projects pa
    where pa.project_id=c_rec.project_id;
    dbms_output.put_line(v_out);
    end loop;
    END;

    This is already your 3rd post abaout this "procedure thing"
    Need help with this procedure!
    Re: Need help with this procedure!
    OK, just a few comments:
    - use the data type of the values and do not let them implicitly convert
    - what means "outputting" inside a procedure as a procedure normally runs on the database server with no terminal connected?
    - if invoice_date is an Oracle date data type then the line
    AND invoice_date BETWEEN '01-JAN-2007' AND '31-DEC-2007'is just plain wrong as it is only working by accident. Ther correct condition would be
    AND invoice_date BETWEEN to_date('01-JAN-2007', 'dd-mon-yyyy') AND to_date('31-DEC-2007', 'dd-mon-yyyy')- if org_id is of type number why you compare it to the string '458'? Compare it against the number 458
    - for me, the year 2007 is either a date or a number but not a string. So the parameter should be defined as date or number resp.
    As I can not really figure out what you want to achieve with this procedure it is hard to comment.

Maybe you are looking for

  • Google maps in narrative report

    Hi, I'm trying to plot addresses on a google map in a report. I'm getting the addresses displayed but no map. Can anyone help? I'm not a javascript developer. I'm just trying to put this together from what I found on various websites. Thanks! Here's

  • Report Painter: Possible to show Report with Zero (not No records were sel)

    Report Painter: Possible to show Report with Zero (not No records were selected) Dear Guru,   is there any way to make Report Painter to show Report with Zero / 0 when there were no record were found. (No records were selected). Regards, Howard

  • DL link error

    I am frequently getting error message the '' Connect failed because target host or object does not" while connect remote database through DB link Please let me know how to resolve this Regrads Sathish S

  • How to combine below 4 queries into a single query?

    SELECT COUNT(*) AS NORMAL_PASS FROM ( SELECT MAINSERNO FROM SGSTUDENT.PPL_PRODUCT_TESTID2 WHERE (MONO = '5954556' AND TESTMODE =1 AND TESTFLAG =1) SELECT COUNT(*) AS NORMAL_FAIL FROM ( SELECT MAINSERNO FROM SGSTUDENT.PPL_PRODUCT_TESTID2 WHERE (MONO =

  • A few simple Logic questions...please help.

    I have a few probably simple Logic questions, that are nonetheless frustrating me, wondering if someone could help me out. 1. I run Logic 8, all of the sounds that came with logic seem to work except organ sounds. I can't trigger any organ sounds (MI