Query slower in stored procedure(after upgrade to 16)

Hi all,
We are looking to upgrade our SQL Anywhere 9 database to 16. We thought version 16 is slower in update tables, but the reason of slowness are query's in stored procedures called from the trigger. One of the query's has a duration of 8 times the duration in version 9!! When I run the query in Interactive Sql(v16), they run fast like version 9. So the query runs slower in a stored procedure.
I thought parameter sniffing, but it's not MS Sql Server. I've no idea why it was good in v9 and bad in v16. Have someone a idea?
It's a query with subquery's in the where , a view in the from. In the view are unions. Looks not so special.
thanks

It may be more convenient for you to ask this question on the other forum: SAP SQL Anywhere Forum
Preamble...
It sometimes happens that (a) the same query will perform faster or slower in different versions because of different behaviors by the query optimizer. In most cases a minor change is necessary to restore good performance; in some rare cases, the changes are difficult.
It also sometimes happens that (b) the same query will perform faster or slower under different operating conditions; e.g., client request (ISQL) versus inside a BEGIN block (stored procedure). Again, minor changes all that's required in most cases, sometimes otherwise.
Details...
In order to help, we will need more information. Two graphical plans with statistics for the same problematic query, both using V16, one captured in ISQL, and the other one captured inside the stored procedure, is the best way to pass on the information; ALL OTHER forms are inadequate, especially prose descriptions and edited snippets of code (that way lies frustration for all parties).
There are a number of articles about graphical plans on this blog.

Similar Messages

  • Pages on my iPad3 has become very slow to open documents after upgrading to ios7. I've clicked on a folder 5 minutes ago and am still waiting. The work-around seems to be to force-close it, but I've needed to do this many times in the last few days.

    Pages on my iPad3 has become very slow to open documents after upgrading to ios7.
    I posted on here about this a few weeks back and someone suggested force-closing Pages -- and that does indeed enable me to open things -- but I have had to force-close many times in the last 24 hours, which is worrying. Are there any other suggestions?
    I am sometimes also finding that, when I have been writing something and then click on "documents" the screen goes blank, there is a wait of around a minute and then the same document is re-displayed, before clicking "documents" again lets me look at other documents -- which is a pain if I am trying to move between documents repeatedly. Again, words of wisdom on this would be great.
    Pages under iOS6 opened quickly, and there was an immediate loss of performance when I upgraded. I am finding this very frustrating because I don't feel that the new Pages has added to the facilities I was using, but a slowness to open documents is frustrating.
    Thanks
    Mark

    Pages on my iPad3 has become very slow to open documents after upgrading to ios7.
    I posted on here about this a few weeks back and someone suggested force-closing Pages -- and that does indeed enable me to open things -- but I have had to force-close many times in the last 24 hours, which is worrying. Are there any other suggestions?
    I am sometimes also finding that, when I have been writing something and then click on "documents" the screen goes blank, there is a wait of around a minute and then the same document is re-displayed, before clicking "documents" again lets me look at other documents -- which is a pain if I am trying to move between documents repeatedly. Again, words of wisdom on this would be great.
    Pages under iOS6 opened quickly, and there was an immediate loss of performance when I upgraded. I am finding this very frustrating because I don't feel that the new Pages has added to the facilities I was using, but a slowness to open documents is frustrating.
    Thanks
    Mark

  • Error : The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure.

    Hi all,
        I have created one SP for sending mail with formatting the HTML code inside script whenever i am individually declaring it and printing its expected but the problem at time of executing SP its giving error like this
    Msg 132, Level 15, State 1, Line 47
    The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure.
    what is the possibilities to overcome this problem follwing is my stored procedure code 
    ALTER PROCEDURE [dbo].[USP_DataLoadMailsend_essRules]
    AS
    BEGIN
    SET NOCOUNT ON;
    SET XACT_ABORT ON;
    BEGIN TRY
    ---BEGIN TRANSACTION T1
    DECLARE @packagelogid INT
    DECLARE @batchlogid INT
    DECLARE @packagestatus CHAR(2)
    select @batchlogid =19870
    --print(@batchlogid)
    DECLARE @script VARCHAR(MAX)
    DECLARE @tableHTML VARCHAR(MAX)
    DECLARE @mailheader VARCHAR(50)
    DECLARE @count INT
    DECLARE @recipients1 VARCHAR(50)
    DECLARE @subject1 VARCHAR(200)
    DECLARE @sql VARCHAR(MAX)
    Declare @UserId varchar(Max)
    Declare @Information varchar(max)
    Declare @TableHTML1 varchar(max)
    Declare @TableHTML2 varchar(max)
    SET @mailheader = ''
    SET @mailheader = (select case
    WHEN FileUpload = 'F'
    THEN 'BussinessRules is Aborted'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) > 0
    THEN 'BussinessRules is Processed with Errors'
    WHEN InRule = 'F'
    THEN 'BussinessRules is Failed'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) = 0
    THEN 'BussinessRules is Succeeded'
    end
    from abc..BatchStatus bts where BatchId=@batchlogid)
    /* Selecting Person Mail as Recipient */
    SELECT TOP 1 @recipients1 = EmailId FROM abc.PersonEmail
    WHERE PersonId = ( SELECT TOP 1 personid FROM abc.FileUploadSummary WHERE BatchId = @batchlogid )AND EmailTypeId = 1
    /* Selecting UserId*/
    select top 1 @UserId=loginid from abc.FUS where BatchId=@batchlogid
    /*Selecting Information about the Status */
    Set @Information=
    (select case
    WHEN FileUpload = 'F'
    THEN 'BussinessRules is Aborted'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) > 0
    THEN 'BussinessRules is Processed with Errors'
    WHEN InRule = 'F'
    THEN 'BussinessRules is Failed'
    WHEN (InRule = 'S')
    AND (
    SELECT sum(isnull(ErrorRecords, 0)) tot
    FROM abc.FileUploadSummary z
    WHERE z.BatchId = bts.BatchId
    GROUP BY BatchId
    ) = 0
    THEN 'BussinessRules is Succeeded'
    end + N' <br> <B>BatchId= '+ convert(varchar(250),(select @batchlogid)) +'</B>'
    from abc..BatchStatus bts where BatchId=@batchlogid )
    /*Selecting the Error Reason*/
    if exists (select 1 from BatchStatus where BatchId=@batchlogid and ( InRule='f'))
    begin
    set @TableHTML1 = '<table border=1><tr><th>Sr.No.</th><th><P>Error Reason :</th></tr>'+
    cast((select td= ROW_NUMBER()over (order by (select 1)),'',
    td=isnull(e.ErrorDescription, '')
    from abc.x.tbPackageErrorLog e --50594
    join abc.x.tbPackageLog p -- 10223
    on p.PackageLogID=e.PackageLogID
    where p.BatchLogID= @batchlogid FOR XML PATH('tr'), TYPE )
    as NVarchar(max)) +'</table>'
    -- print @tableHTML
    if not exists (select 1 from BatchStatus where BatchId=@batchlogid and ( InRule='f'))
    set @TableHTML2 = 'Error Reason :N/A'
    end
    -- insert into #tmp values ( @TableHTML1)
    --select * from #tmp
    Set @tableHTML= 'Hello '+@UserId+', <br>Information:'+isnull(@Information,'') +
    '<Table Border=1><Tr><th>Sr No</th><th>Uploaded files </th>:'+
    CAST ((select td= ROW_NUMBER()over(order by f.FileUploadId), '',
    td = f.TableName , ''
    from abc.FileUploadSummary F where BatchId=@batchlogid
    FOR XML PATH('tr'), TYPE ) AS NVARCHAR(max) )
    +'</table>'+
    'Error Reason :'+isnull(isnull(@TableHTML1,'')+ isnull(@TableHTML2,''),'N/A')+ --concat (isnull(@TableHTML1,''),isnull(@TableHTML2,'')
    '<br> Please login to Your Account for further Details..!'
    +'<br>@Note: This is system generated message, Do not reply to this mail. <br>Regards,<br>'+
    'Admin'
    print @tableHTML
    SET @sql = ' EXEC msdb.dbo.sp_send_dbmail @profile_name = ''DBA_mail_test''
    ,@recipients = ''' + isnull(@recipients1,'''') + ''',@subject = ''' + isnull(@mailheader,'''') + ''',
    @body = ''' +isnull(@tableHTML,'''')+ ''',
    @body_format = ''HTML'''
    Exec(@sql)
    END TRY
    BEGIN CATCH
    PRINT error_message()
    -- Test whether the transaction is uncommittable.
    -- IF (XACT_STATE()) = - 1
    -- ROLLBACK TRANSACTION --Comment it if SP contains only select statement
    DECLARE @ErrorFromProc VARCHAR(500)
    DECLARE @ErrorMessage VARCHAR(1000)
    DECLARE @SeverityLevel INT
    SELECT @ErrorFromProc = ERROR_PROCEDURE()
    ,@ErrorMessage = ERROR_MESSAGE()
    ,@SeverityLevel = ERROR_SEVERITY()
    --INSERT INTO dbo.ErrorLogForUSP (
    -- ErrorFromProc
    -- ,ErrorMessage
    -- ,SeverityLevel
    -- ,DateTimeStamp
    --VALUES (
    -- @ErrorFromProc
    -- ,@ErrorMessage
    -- ,@SeverityLevel
    -- ,GETDATE()
    END CATCH
    END
    please help me to solve this problem
    Niraj Sevalkar

    This is no string http in your procedure. Then again the error message points to a line 47 outside a stored procedure. I can't tell it is outside, since there is no procedure name.
    But I see that you have this piece of dynamic SQL:
    SET @sql = ' EXEC msdb.dbo.sp_send_dbmail @profile_name = ''DBA_mail_test''
    ,@recipients = ''' + isnull(@recipients1,'''') + ''',@subject = ''' + isnull(@mailheader,'''') + ''',
    @body = ''' +isnull(@tableHTML,'''')+ ''',
    @body_format = ''HTML'''
     Exec(@sql)
    Why is this dynamic SQL at all? Why not just make plain call to sp_send_dbmail?
     EXEC msdb.dbo.sp_send_dbmail @profile_name = 'DBA_mail_test'
    ,@recipients = @recipients1, @subject = @mailheader, @body = @tableHTML
    Erland Sommarskog, SQL Server MVP, [email protected]

  • WiFi Breaking and getting slow in MacBook Pro after upgrading to OS X Yosemite

    WiFi Breaking and getting slow in MacBook Pro after upgrading to OS X Yosemite

    WiFi Breaking and getting slow in MacBook Pro after upgrading to OS X Yosemite

  • I need return the result of a query on a stored procedure

    I need return the result of a query on a stored procedure, I mean when I execute a stored procedure it returns a result set as a select query.
    Best regards...

    If you want some pl/sql code that can be used in a query as it were a table you may be interested in table functions:
    SQL> create or replace type
      2  t_emp is object (
      3  name            varchar2(30),
      4  hire_date date,
      5  salary       number);
      6  /
    Tipo creato.
    SQL> create or replace type
      2  t_emptab is table of t_emp;
      3  /
    Tipo creato.
    SQL> create or replace function tab_fun(p_dept in number)
      2  return t_emptab is
      3  e t_emptab;
      4  begin
      5    select t_emp(ename,hiredate,sal)
      6      bulk collect into e
      7      from emp
      8     where deptno=p_dept;
      9
    10    return dip;
    11  end;
    12  /
    Funzione creata.
    SQL> select *
      2  from table(tab_fun(20));
    NAME                           HIRE_DATE  SALARY
    SMITH                          17-DIC-80        800
    JONES                          02-APR-81       2975
    SCOTT                          09-DIC-82       3000
    ADAMS                          12-GEN-83       1100
    FORD                           03-DIC-81       3000A procedure cannot be used in a select statement.
    Max
    http://oracleitalia.wordpress.com

  • Typing has become slow in ipad mini after upgrade to Io7

    typing has become slow in ipad mini after upgrade to io7.
    everywhere in Browsers, mail & everywhr.

    Reset all settings
    Settings>General>Reset>Reset All Settings

  • Can not delete data from table which is queried in my stored procedure

    Hi,
    Anyone knows how to fix it:
    I have a table. In a stored procedure, I have a simple query running on this table.
    When I want to delete one record from that table, I got error message:
    ORA-04091: table *** is mutating, trigger/function may not see it.
    Thanks first.

    Rick, the only time you should get a mutating table error is when a trigger is involved. FK problems have separate error codes (and would be a different problem than the one that started this thread). Using a DBA id check all the tables subject to DML by your function and by whatever calls your function for triggers. Only the owner or a DBA can see the existence of triggers on a non-owned table. This has caused some of the developers I work with to think tables that had triggers do not have them since they do not work under the owning or a DBA ID.
    By your description of what you are trying to do in the function we do that all the time without problem.
    How large is the function? How/When is it called?
    Mark D Powell

  • Query Timeout on stored procedure executed from Access 2010

    I am trying to delete old jobs from a SQL 2008 R2 database. I created a stored procedure on the server that deletes all Jobs over 1 year old. The delete can take several minutes to run as it deletes record on several related tables. I am getting a error
    "2147217871 - [Microsoft][ODBC SQL Server Driver]Query timeout expired". The query runs fine on the Server. I have tried setting Client timeout to 300 sec but it times out way before 5 min. I am not sure what else I
    can do to fix this problem. I am hoping someone has seen this and figured out a fix.
    Here is there code
    Public Sub Cleanup_Database()
    On Error GoTo CleanUp_Err
        Dim cmd As ADODB.Command
        Set cmd = New ADODB.Command
        ODBC_conn = "ODBC;Description=testbox2;DRIVER=SQL Server;" & _
                    "SERVER=O2GMSAPPTEST\SQL122DEVL;Trusted_Connection=Yes;" & _
                    "APP=Microsoft Office 2010;DATABASE=IMB_TraceData;StatsLog_On=Yes"
        cmd.ActiveConnection = ODBC_conn
        cmd.CommandType = adCmdStoredProc
        cmd.CommandText = "DataBase_Cleanup"
        cmd.Execute
    CleanUp_Err:
        Dim i As Long
        Dim str As String
        str = ""
        For i = 0 To Errors.Count - 1
            str = str & Errors(i).Number & "-" & Errors(i).Description & " " & vbNewLine
        Next i
        If str = "" Then
            str = Err.Number & " - " & Err.Description
        End If
        MsgBox str, , "Trace Update"
    End Sub
      

    You didn't say how you were setting the client timeout, but this has worked for me in an adp.
    'Temporarily increase query timeout, which is an application-wide setting
    'CurrentProject.Connection.CommandTimeout = 60 'Too late to change this setting- no effect
    Const cstrTimeoutOptionName As String = "OLE/DDE Timeout (Sec)"
    Const clngTimeoutSecondsForQuery As Long = 300
    strQueryTimeOutOriginal = Application.GetOption(OptionName:=cstrTimeoutOptionName)
    Application.SetOption cstrTimeoutOptionName, CStr(clngTimeoutSecondsForQuery)
    Paul

  • SQL query statement  for stored procedure / function listing ...

    Hi everyone,
    Is there a SQL query to list all the stored procedures and functions of an user in an Oracle 8 database?
    I have this idea:
    select * from USER_SOURCE where TYPE = 'PROCEDURE' or TYPE = 'FUNCTION'
    but I am not too sure whether this is correct.
    Thanks in advance,
    Eric

    Yeah
    I agree with you Garcia , my above posting was a correction to the query mentioned in the question only.
    you are correct
    If you only want the name of the object,
    SELECT Object_Name from User_Objects where object_type in ( 'PROCEDURE' ,'FUNCTION');
    is much faster than Selecting (distinct) from User_Source.

  • Slow Mac Mini Server after upgrading to OS X Yosemite

    I Have a Mac Mini Server mid 2010. With 2.66Ghz intel Core 2 Duo and 4Gb DDR3 and after upgrading to OS X Yosemite the computer is really slow and get stuck very often. Please help me figuring out what’s the problem and to make it run faster.

    EtreCheck version: 2.1.8 (121)
    Report generated 29 במרץ 2015 בשעה 21:15:38 GMT+3
    Download EtreCheck from http://etresoft.com/etrecheck
    Click the [Click for support] links for help with non-Apple products.
    Click the [Click for details] links for more information about that line.
    Hardware Information: ℹ️
        Mac mini Server (Mid 2010) (Technical Specifications)
        Mac mini - model: Macmini4,1
        1 2.66 GHz Intel Core 2 Duo CPU: 2-core
        4 GB RAM Upgradeable
            BANK 0/DIMM0
                2 GB DDR3 1067 MHz ok
            BANK 1/DIMM0
                2 GB DDR3 1067 MHz ok
        Bluetooth: Old - Handoff/Airdrop2 not supported
        Wireless:  en1: 802.11 a/b/g/n
    Video Information: ℹ️
        NVIDIA GeForce 320M - VRAM: 256 MB
            HDMI     spdisplays_1080p
    System Software: ℹ️
        OS X 10.10.2 (14C109) - Time since boot: 0:13:17
    Disk Information: ℹ️
        ST9500420ASG disk0 : (500.11 GB)
            EFI (disk0s1) <not mounted> : 210 MB
            adrian (disk0s2) / : 499.25 GB (352.51 GB free)
            Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
        ST9500420ASG disk1 : (500.11 GB)
            EFI (disk1s1) <not mounted> : 210 MB
            roy (disk1s2) /Volumes/roy : 499.76 GB (499.32 GB free)
    USB Information: ℹ️
        Apple Inc. MacBook Air SuperDrive
        Microsoft Microsoft® Nano Transceiver v2.0
        Apple Inc. BRCM2070 Hub
            Apple Inc. Bluetooth USB Host Controller
        NOVATEK USB Keyboard
        Apple Computer, Inc. IR Receiver
    Gatekeeper: ℹ️
        Mac App Store and identified developers
    Kernel Extensions: ℹ️
            /Library/Extensions
        [not loaded]    com.lge.driver.LGAndroidmdmcontrol (4.12 - SDK 10.9) [Click for support]
        [not loaded]    com.lge.driver.LGAndroidmdmdata (4.12 - SDK 10.9) [Click for support]
        [not loaded]    com.lge.driver.LGAndroidndiscontrol (4.12 - SDK 10.9) [Click for support]
        [not loaded]    com.lge.driver.LGAndroidndisdata (4.12 - SDK 10.9) [Click for support]
        [not loaded]    com.lge.driver.LGAndroidserial (4.12 - SDK 10.9) [Click for support]
        [not loaded]    com.lge.driver.LGAndroidusbbus (4.12 - SDK 10.9) [Click for support]
    Launch Daemons: ℹ️
        [loaded]    com.adobe.fpsaud.plist [Click for support]
    User Launch Agents: ℹ️
        [loaded]    com.bittorrent.uTorrent.plist [Click for support]
        [loaded]    com.google.keystone.agent.plist [Click for support]
    User Login Items: ℹ️
        iTunesHelper    יישום  (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
        uTorrent    יישום  (/Applications/uTorrent.app)
    Internet Plug-ins: ℹ️
        Silverlight: Version: 5.1.10411.0 - SDK 10.6 [Click for support]
        FlashPlayer-10.6: Version: 17.0.0.134 - SDK 10.6 [Click for support]
        Flash Player: Version: 17.0.0.134 - SDK 10.6 [Click for support]
        Flip4Mac WMV Plugin: Version: 3.0.0.126   - SDK 10.8 [Click for support]
        QuickTime Plugin: Version: 7.7.3
        Default Browser: Version: 600 - SDK 10.10
    Safari Extensions: ℹ️
        AdBlock
        Adblock Plus
        SafariRestore
        New Tab Button
    3rd Party Preference Panes: ℹ️
        Flash Player  [Click for support]
        Flip4Mac WMV  [Click for support]
    Time Machine: ℹ️
        Time Machine not configured!
    Top Processes by CPU: ℹ️
             7%    WindowServer
             2%    uTorrent
             0%    AppleSpell
             0%    mds_stores
             0%    fontd
    Top Processes by Memory: ℹ️
        228 MB    Google Chrome
        146 MB    Finder
        103 MB    ocspd
        90 MB    WindowServer
        69 MB    mds_stores
    Virtual Memory Information: ℹ️
        56 MB    Free RAM
        1.63 GB    Active RAM
        1.59 GB    Inactive RAM
        723 MB    Wired RAM
        1.78 GB    Page-ins
        3 MB    Page-outs
    Diagnostics Information: ℹ️
        Mar 29, 2015, 09:00:49 PM    Self test - passed

  • Extremely Slow Time Machine Backup after upgrading to 10.8.3

    Time machine backups are taking an extremely long time on my retina MacBook Pro 13 inch after upgrading to 10.8.3. It's taking many minutes just for a kilobyte to be backed up. I've tested transferring something to the disk and it's lightening fast so there's nothing wrong with the disk.
    Is anyone having similar issues or know of a fix?

    I had the same problem with slow backups. Called Apple 5 times and went through all the hoops checking plists, airport, and then erasing using my airport utility and the first backup of about 25-30 gigs went fine, but the second backup would take between 1-2 hours. By the time it was finished it was ready to do another backup.
    After looking at community fixes I found that my Comcast Norton Anti Virus was the problem. Upon speaking for the 6th time to Apple I was told that should have been the first thing they asked, since antivirus programs check each file going to the time capsule. Even unchecking the scan external drives did not help.
    I removed the Norton AV from my system and replaced it with the IAV from apple store (free) and my backups are back to normal. I timed a 100 meg using Ethernet/LAN and it took 9 minutes 32 seconds from clicking backup now, searching for backups, preparing backup, backingup, and cleanup. My Wifi connection on 10 megs took only 1 minute 29 seconds.
    Now my backups run so fast I don't even see them working. Also the constant updates to Norton were casuing my backups to be 100 megs or more each time due to daily Norton updates. Now I get backups in the order of 10-20 megs - depending up what I have put on the machine. If I put music on it increases the size of the files installed.
    I recommend anyone having this slow time capsule problem to turn off your full antivirus program no matter what you are using and watch the difference in speed. I am so happy! No more 2 hour backups and 45 minutes to 1 hour preparing backup! good luck

  • Parameter in Query manager running stored procedure

    Hi Experts!
    I have a stored procedure, which is waiting a parameter.
    I would like to write a query in sap with parameter using sap language:
    exec sp_leltar [%0]
    The parameter is numeric, but when running the query above, it is giving an error:"Userdefined errors".
    Any idea?Thats not a way to write the parameter value on editor field.

    I have tried to run the following:
    select from dbo.omaleltfej t0/
    declare @leltid numeric OUTPUT
    /* where*/
    set @leltid = /* t0._leltfejid */ [%0]
    exec omaleltareredmeny2 @leltid
    Error message:"...Can not use the output option in declare or create function statement..."
    I gave up to solve it, because this is not an SAP table, it is not possibble to do.
    Thank you for your effort.

  • Send SQL query or call stored procedure, which is best???

    hello experts!!
    i would like to ask what will be the best implementation on querying a database using Java, send a SQL query(insert into table values...) or call stored procedure(just pass parameters)?? and also in stored procedure does "autoCommit/rollback" applies/make sense??

    I searched google for this:
    Stored Procedures vs. SQL
    and found this useful link:
    http://www.karlkatzke.com/stored-procedures-vs-sql-calls/
    I thiink you should also read up on other articles based on such google searches
    to get other opinions. Also, read the links provided by that article.
    Personnally, I think stored procedures should be avoided unless there is a definite
    advantage as specified in the above article. Especially not used for CRUD operations.
    Also, no matter where you put the SQL, it should be documented. I've seen too many stored procedures that aren't documented.

  • Exit stored procedure after UPDATE

    Hello,
    I have written a LOOP that calls a second Stored Procedure.
    In the second Stored Procedure I have 3 INSERTS each SELECT's values limited with a WHERE clause.
    Example:
    begin
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012' --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012'
    execute immediate dynsql;
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'  --if not condition not met, no insert
    execute immediate dynsql
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'
    execute immediate dynsql;
    dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
    SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012'  --if not condition not met, no insert
    execute immediate dynsql;
    dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between  '01.JUN.2012 and '01.JUL.2012'
    execute immediate dynsql;
    end;
    commit;What do I do?
    I update the existing "old" row with a new date and then I am basically duplicating that row but adding it with a new DATE, the ID and NAME is "copied" as it is.
    The big problem is that the rows result in recursive updates. if the first statement updates a date it might make the conditions for the second and first update become "true".
    Which is not what I want. Initially, only one of the statements is true, ever. The problem with my code is that after the first update and date setting, another "might" become true.
    This should stop. After one of the updates occured, I need to stop the stored procedure.
    How do I stop it after upate?

    metalray wrote:
    Hello BlueShadow, that makes sense. Thanks.
    Can you tell me when sql&rowcount is reset, after an execute immediate, after a commit?It doesn't get 'reset' in the strict sense. When a PL/SQL program unit is initiated the implicit "SQL" cursor space is defined and exists in the scope of that program unit. At that point it is like any variable that is declared with it's value undefined (null). When you issue any DML statement (insert, update, delete, merge etc.), these will explicitly set the ROWCOUNT attribute within the SQL cursor space. Other SQL statements are also issued from PL/SQL through the SQL "space" (interface), and as such, they may (it's not defined anywhere) effect the values of attributes within it, including the ROWCOUNT, but we cannot say exactly in what way. Therefore, the only thing that can be definitely determined is that a) when it's first instantiated, the SQL%ROWCOUNT will be null, and also, )_immediately_ after any appropriate DML statement the SQL%ROWCOUNT will contain the number of rows effected. If the SQL%ROWCOUNT value is examined at any other point, the value is indeterminate so, for example, after a commit statement, we cannot be sure what value it has or what that value refers to.
    I loop through each tax no. need to do either an update, update or delete, delete, each with different WHERE clauses. the danger is that
    I update and then the where clause for the deletion becomes true, but my process should not do the deletion if an update happened. its a sequential check and ones true and update/deletion made, the loop stored procedure should terminate. right now I check for sql&rowcount to "not" get into a update or delete if one already happened but I fail to grasp the logic of when sql&rowcount gets which value . I have the feeling that the parent stored procedure that calls my second one with the update and deletes sets the sqlrowcount to 1 because it has an insert. (I use 11g)After your insert/update you should immediately get the value of SQL%ROWCOUNT into a variable, so that you have the value before it is effected by other statements.
    You can then use that value in your variable to determine program logic e.g. whether the delete should process or not, regardless of whether you issued further code between the insert/update and the check to see if you should delete. Don't rely on things 'resetting' the ROWCOUNT attribute, only rely on things setting it.

  • Check Stored Procedures after Migration from MS SQL Server 2008 to Oracle11

    I successfully migrated my application database (azteca) from MS SQL Server 2008 to Oracle 11g R2. After migration, I found there are few stored procedures are not valid. How do I check these invalid stored procedures and find what is wrong with them by using SQL Developer? Thanks for your help.
    Kevin

    Hi Kevin,
    You posted quite a bit today, so perhaps you have already worked this out. If not...
    1. View -> Reports -> Data Dictionary Reports -> All Objects -> Invalid Objects [for a specific schema name]
    2. Next, for each invalid stored procedure listed in (1)...
    a. Open in the code editor from the Connections navigator tree
    b. Click on the Compile icon (two gears meshed together) in code editor tool bar.
    c. Look in the Compiler log pane for errors.
    d. Correct the errorsOf course, success in addressing any errors depends on your skill level dealing with Oracle PL/SQL.
    Also, it may be helpful to read over section *3.2 Stored Procedures* in the supplementary migration guide:
    http://docs.oracle.com/cd/E35137_01/doc.32/e18462/trig_stored_proc.htm#CHDEIGBC
    Regards,
    Gary
    SQL Developer Team

Maybe you are looking for

  • Time Machine for clients + Network Home folders?

    I currently use Retrospect to back up my client machines, but frankly I don't like it that much. I'd really like to have Time Machine working for all of the client machines so that the users can easily grab copies of their own backups, rather than ha

  • Index.html - SWF file not working in browser

    The navigation button on my Flash/SWF intro page (www.benscarrillustration.com) isn't working in web browsers. What am not doing correctly. I have the following 3 files in my cPanel File Manager.... 1. index.html 2. Ben Scarr Illustration.swf 3. Ben

  • Can't make jpeg in Photoshop CC

    I have Photoshop CC (with Windows 8). I can't make jpeg and pdf in Photoshop CC. Is this normal or there is something wrong with my computer? (Very annoying, please help!) Thanks

  • HT201250 Why time machine returns an error message that says "unable to open version"?

    I am using Neat for Mac (a scanner software), but it looks like time machine is not doing the backup for it. Every time I open time machine and I have that application opened time machine shows a message that says "unable to open version". Does anybo

  • Original asset  Field  in Asset Master

    Hi Viewers, Field Original asset in origin Tab is available for some asset classes.  Few is asset classess that field is not available. Can any one tell me where to activate that field. I have checked in the screen layout of the asset master data. It