Procedure executes statement and exists prematurely

I have been getting so much incredible help, I figure why stop now!
I have the following procedure. It runs perfectly until it gets to the line marked "--THIS LINE GETS EXECUTED AND THEN THE ROUTINE EXITS". I suspect this has something to do with all the begin..end statements but without them I get invalid sql statements errors. Any advice on how I can make this work?
PROCEDURE INTERPRET_LOOP
    p_MasterTable   IN  VARCHAR2,
    p_PrimaryIDField IN VARCHAR2)
AS
    cursor TableName_Tab IS
        select distinct DBTABLENAME from DATASPECIFICATIONS;
    v_TableName VARCHAR2(25);
    CURSOR FieldNames_Tab (cv_TableName VARCHAR2) IS
        select distinct SHORTNAME, QCTYPE, LOWVALUE, HIGHVALUE from DATASPECIFICATIONS where DBTableName = cv_TableName;
    v_FieldName VARCHAR2(25);
    v_QCType VARCHAR2(100);
    v_High VARCHAR2(25);
    v_Low VARCHAR2(25);
    v_SQL VARCHAR2(2000);
BEGIN
    OPEN TableName_Tab;
    Loop
        Fetch TableName_Tab into v_TableName;
        Exit when TableName_Tab%NOTFOUND;
        --interpret each field based on data type
        --select list of fields and types to loop through
        OPEN FieldNames_Tab(v_TableName);
        Loop
            Fetch FieldNames_Tab into v_FieldName, v_QCType, v_High, v_Low;
            Exit when FieldNames_Tab%NOTFOUND;
            If (instr(UPPER(v_QCType), 'RANGE') > 0) Then
                v_SQL:= 'HT_QCINTERPRET.INTERPRET_'||UPPER(v_QCType)||'('''||UPPER(v_FieldName)||''', '''||v_Low||''||', '''||v_High||''||', '''||UPPER(v_TableName)||''');';
            ElsIf (instr(UPPER(v_QCType), 'DATA') > 0) Then
                v_SQL:= 'HT_QCINTERPRET.INTERPRET_'||UPPER(v_QCType)||'('''||UPPER(v_TableName)||''');';
            Else
                v_SQL:= 'HT_QCINTERPRET.INTERPRET_'||UPPER(v_QCType)||'('''||UPPER(v_FieldName)||''', '''||UPPER(v_TableName)||''');';
            End If;
            v_SQL := 'BEGIN '||v_SQL||' END;';
            execute immediate v_SQL;    --THIS LINE GETS EXECUTED AND THEN THE ROUTINE EXITS
        End Loop;
        --update DATAINFO table.  insert interpretation failures
        If v_TableName <> p_MasterTable Then
            v_SQL := 'insert into DATAINFO select p.'||UPPER(p_PrimaryIDField)||', 1, t.RECORDID, '''||UPPER(v_FieldName)||''', '||CURRENT_DATE||', p.DATAVRSN, '''||UPPER(v_QCType)||'''';
            v_SQL := v_SQL||' from '||UPPER(v_TableName)||' t left join '||UPPER(p_MasterTable)||' p on t.'||UPPER(p_PrimaryIDField)||' = p.'||UPPER(p_PrimaryIDField);
            v_SQL := v_SQL||' where t.'||UPPER(v_FieldName)||' is NULL and t.'||UPPER(v_FieldName)||'_IN is NOT NULL';
        Else
            v_SQL := 'insert into DATAINFO select p.'||UPPER(p_PrimaryIDField)||', 1, p.RECORDID, '''||UPPER(v_FieldName)||''', '||CURRENT_DATE||', p.DATAVRSN, '''||UPPER(v_QCType)||'''';
            v_SQL := v_SQL||' from '||UPPER(v_TableName)||' p ';
            v_SQL := v_SQL||' where p.'||UPPER(v_FieldName)||' is NULL and p.'||UPPER(v_FieldName)||'_IN is NOT NULL';
        End If;
        v_SQL := 'BEGIN '||v_SQL||' END;';
        execute immediate v_SQL;
        close FieldNames_Tab;
    End Loop;
    close TableName_Tab;
    commit work;
END INTERPRET_LOOP;Thanks!!!!

Hmmm,
Interesting. Never typed a >< in here.
Btw, try doing a dbms_output.put_line(V_SQL) before the execute immediate. i.e
        v_SQL := 'BEGIN '||v_SQL||' END;';
        dbms_output.put_line(v_SQL);
        execute immediate v_SQL;and see if that gets printed properly (and also as expected)
-Arun
Edited by: Arunkumar Ramamoorthy on Oct 22, 2009 1:08 AM

Similar Messages

  • Sql - execute statement problems

    I have a "try" with a "catch" that contains an sql execute statement, and some statements after that, but it doesn't execute any of the following statements. It successfully compiles and has no errors when I run it. It just doesn't insert the information and it stops every command that follows. When I remove the execute state (the one with the asterist next to it), the following statements execute fine. Any information on what I might be missing would be greatly appreciated. Thanks.
    try{
    new JdbcOdbcDriver();
    String url = "jdbc:odbc:javadb";
    String user = "";
    String password = "";
    Connection con =
    DriverManager.getConnection(url, user, password);
    Statement stmt = con.createStatement();
    System.out.println("Made the Connection");
    *stmt.executeUpdate("INSERT INTO tbl VALUES ('bradley')");
    System.out.println("Made the Connection");
    JOptionPane.showMessageDialog(this, "Data Inserted");
    }catch(Exception e)
    e.printStackTrace();
    }

    Look in your log file. When you perform "e.printStackTrace()" the stack is sent to the System.out, which JSP has already redirected to the log.
    If you're having trouble finding the log (it depends on what webserver you're using), try changing that to:
    out.println("<h3>We have an error: " + e + "</h3>");
    (Notice the absense of "System." here. We're using the pre-defined JSP "out" object that's going to the client browser.)
    That will print the error message, plus the reason for the error, on your client as 2nd level header.
    Personally, I always print out my error messages in this manner. I find that having a full, complete, extensive stack trace is next to useless. It's like asking for the definition of the word "Java", and having the Oxford Unabridged Dictionary dropped in your lap.

  • DDL statements and dynamic  sql  in stored procedure

    I created a stored procedure to create and drop tables, using dynamic sql.
    When I try to do the inserts using dynamic sql, i.e
    v_string := 'INSERT statement';
    EXECUTE IMMEDIATE v_string;
    I get the following error message:
    ERROR at line 1:
    ORA-00942: table or view does not exist
    ORA-06512: at line 63
    Line 63 happens to be the line that the EXECUTE IMMEDIATE v_string; statement is in.
    I am able to describe the table that the inserts are being made into, so I know that the table exists.
    Any idea why I'm getting this error message would be appreciated.

    Yes I do and I have been able to create other tables using dynamic sql.
    The table that I am having problems with SELECTs data from another table to get its column values; within the SELECT statement, the CAST function is used:
    ie. CAST(CASE SUBSTR(CAST(E_MOD AS VARCHAR(7)),2,3)
    WHEN 'AAA' THEN 'A55'
    ELSE ............
    I get the following error message:
    ERROR at line 18: (this line starts the CAST statement)
    ORA-06550: line 18, column 13:
    PLS-00103: Encountered the symbol "AAA" when expecting one of the following:
    . ( * @ % & = - + ; < / > at in is mod not rem return
    returning <an exponent (**)> <> or != or ~= >= <= <> and or
    like between into using || bulk
    When I remove the quotes or add another single quote, the same error cascades to 'A55'.
    After doing the same for the next error, I get the error message below:
    ERROR at line 1: (this line has the EXECUTE IMMEDIATE statement)
    ORA-00936: missing expression
    ORA-06512: at line 6
    Any idea what the problem could be?
    Also is there another way to have DDL statements as stored procedures other than using dynamic sql or the DBMS_SQL package?

  • MS SQL Server 7 - Performance of Prepared Statements and Stored Procedures

    Hello All,
    Our team is currently tuning an application running on WL 5.1 SP 10 with a MS
    SQL Server 7 DB that it accesses via the WebLogic jConnect drivers. The application
    uses Prepared Statements for all types of database operations (selects, updates,
    inserts, etc.) and we have noticed that a great deal of the DB host's resources
    are consumed by the parsing of these statements. Our thought was to convert many
    of these Prepared Statements to Stored Procedures with the idea that the parsing
    overhead would be eliminated. In spite of all this, I have read that because
    of the way that the jConnect drivers are implemented for MS SQL Server, Prepared
    Statments are actually SLOWER than straight SQL because of the way that parameter
    values are converted. Does this also apply to Stored Procedures??? If anyone
    can give me an answer, it would be greatly appreciated.
    Thanks in advance!

    Joseph Weinstein <[email protected]> wrote:
    >
    >
    Matt wrote:
    Hello All,
    Our team is currently tuning an application running on WL 5.1 SP 10with a MS
    SQL Server 7 DB that it accesses via the WebLogic jConnect drivers.The application
    uses Prepared Statements for all types of database operations (selects,updates,
    inserts, etc.) and we have noticed that a great deal of the DB host'sresources
    are consumed by the parsing of these statements. Our thought was toconvert many
    of these Prepared Statements to Stored Procedures with the idea thatthe parsing
    overhead would be eliminated. In spite of all this, I have read thatbecause
    of the way that the jConnect drivers are implemented for MS SQL Server,Prepared
    Statments are actually SLOWER than straight SQL because of the waythat parameter
    values are converted. Does this also apply to Stored Procedures???If anyone
    can give me an answer, it would be greatly appreciated.
    Thanks in advance!Hi. Stored procedures may help, but you can also try MS's new free type-4
    driver,
    which does use DBMS optimizations to make PreparedStatements run faster.
    Joe
    Thanks Joe! I also wanted to know if setting the statement cache (assuming that
    this feature is available in WL 5.1 SP 10) will give a boost for both Prepared Statements
    and stored procs called via Callable Statements. Pretty much all of the Prepared
    Statements that we are replacing are executed from entity bean transactions.
    Thanks again

  • How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?

    Hi 
    I have a stored procedure. It can be executed like this
    exec test @p = 1;
    exec test @p = 2
    exec test @p = n;
    n can be hundred.
    I want the sp being executed in parallel, not sequence. It means the 3 examples above can be run at the same time.
    If I know the number in advance, say 3, I can create 3 different Execution SQL Tasks. They can be run in parallel.
    However, the n is not static. It is coming from a table. 
    How can I execute Stored Procedures in PARALLEL and DYNAMICALLY ?
    I think about using script task. In the script, I get the value of n, and the list of p, from the table, then running a loop with. In the loop, I create a threat and in the threat, I execute the sp like : exec test @p = p. So the exec test may
    be run parallel. But I am not sure if it works.
    Any idea is really appreciated.

    Hi nam_man,
    According to your description, you want to call stored procedures in parallel, right?
    In SSIS, we can create separate jobs with different stored procedures, then set the same schedule to kick the jobs off at the same time. In this way, we should be careful to monitor blocking and deadlocking depending on what the jobs are doing.
    We can also put all stored procedures in SSIS Sequence container, then they will be run in parallel.
    For more information about SSIS job and Sequence container, please refer to the following documents:
    http://www.mssqltips.com/sqlservertutorial/220/scheduling-ssis-packages-with-sql-server-agent/
    https://msdn.microsoft.com/en-us/library/ms139855(v=sql.110).aspx
    If you have any more questions, please feel free to ask.
    Thanks,
    Wendy Fu
    Wendy Fu
    TechNet Community Support

  • Remote procedure call failed and did not execute response after changing contents

    Hey Hey!
    I have reviewed the other posts related to this issue but have not found a solution.
    I have done myself quite a mischief and hope someone here can help me out!
    I'm running an old ACER laptop with Windows 7. This PC belonged to an old colleague and therefore all of the folders and user names were still under his name, so I decided to try to change them all to my name. The main issue was the USER folder which had
    the locked symbol next to it but it wasn't locked at all. I googled how to delete this folder and one bright spark suggested I create a new folder with my name, copy all of the folders from the other 'locked' user's folder into my folder, and then delete the
    old user's folder. 
    That was fine. All seemed well. When I tried to delete the old folder the computer sat around thinking saying it was 'moving' but not doing anything. So, I cancelled the operation in the Task Manager. When I attempted to open any folder from the start menu
    or desktop or task bar I was presented with a bunch of numbers and letters and the message "REMOTE PROCEDURE CALL FAILED AND DID NOT EXECUTE."
    I quickly googled the message realising I'd made a major error and the first response was to type in services.msc or something to that effect, so I typed that into the Start Menu search bar and hit enter and nothing came up. So, I tried again, but now I
    couldn't type anything into the search bar, I could not even select any programs from the Start Menu. 
    So, I can't access the Start Menu, search bar, or any of the folders unless I open uTorrent, select open containing folder, and from there I can access what I need.
    I'm too afraid to reboot the PC. I can't locate my copy of Windows 7 anywhere. I'm freaking out!!
    Before I pour my lowly student wage into getting a professional to fix it, could someone please offer some suggestions??
    Greatly appreciated in advance. 
    Paris, Texas. 

    Hi,
    Based on your description, for this question is more related to NetQueryDisplayInformation() API, in order to get better help, we may ask for suggestions in the following MSDN forum.
    MSDN Forum
    https://social.msdn.microsoft.com/Forums/en-US/home
    Besides, we can try to use a script to get all domain users. Regarding this point, the following script can be referred to as reference.
    How to list all active directory users in a particular domain using PowerShell
    https://gallery.technet.microsoft.com/office/How-to-list-all-active-0d9be7ce
    In addition, for scripts, we can also ask for help in the following forum.
    The Official Scripting Guys Forum
    https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    Best regards
    Frank Shen 

  • Difference between execute as statement and execute as script in Toad

    Hi
    I want to know difference between execute as statement and execute as script in Toad ..while i am running a query execute as statement is taking about 3 seconds and if i run with execute as a script its taking long time..Which one i need to consider.

    user632733 wrote:
    I want to know difference between execute as statement and execute as script in Toad ..while i am running a query execute as statement is taking about 3 seconds and if i run with execute as a script its taking long time..Which one i need to consider.Firstly, this is not a TOAD forum. TOAD is a 3rd party tool developed by Quest Software, so really your question does not belong here.
    However...
    When you execute a query as a statement then toad itself opens the cursor against the database and issues the statement, fetching the rows as they are needed to display in it's interface. You say it takes only about 3 second to run, but the chances are that you haven't scrolled the result window down to the last record, for which I'm sure you'd find it takes a little longer.
    When you execute a query as a script, TOAD passes the query out to be run in SQL*Plus rather than from within TOAD itself. With SQL*Plus, it runs the whole statement fetching all the rows before returning control, the same as if you had scrolled to the end of the result set in TOAD.
    In reality there should be no difference in the time it takes to execute the statements to completion in either environment.

  • JDBC: Closing Connection does it close statement and resultset

    In my application I am facing ORA-0100 Maximum open cursors exceeded problem. We are executing quite a few queries and stored procedures before we close the connection object. But in few places statements and resultsets are not closed. Can these be a problem? Shouldn't they be automatically closed when the connection is closed?
    We are executing this block of code in a loop.

    in few places statements and
    resultsets are not closed. Can these be a problem?Yes.

  • Error when executing statement for table/stored proc

    Hi All,
          I am getting this error when executing IDOC to JDBC (Stored Procedure) Scenario.
         In my stored procedure I have three insert statements to insert rows in to 3 tables.
        This stored procedure is working fine for two insert statements i.e, 
             For this I have created data type for stored procedure with 10 elements and executed the scenario and was successfully running.
        when I added 3rd insert statement to stored procedure ie., when i added 5 more elements to the datatype (totally 15 elements) it starts giving the bellow error in Message Monitoring.
    <i><b>Exception caught by adapter framework: Error processing request in sax parser: Error when executing statement for table/stored proc. 'COGRP_TMP_PROC_1' (structure 'Statements'): java.sql.SQLException: General error</b></i>
    <i><b>Delivery of the message to the application using connection JDBC_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'COGRP_TMP_PROC_1' (structure 'Statements'): java.sql.SQLException: General error</b></i>
       Note:- I have run the stored procedure  with three insert statements in Sql Server, and also by calling an external program also, and was working fine.
    <i><b> Note : Is there any structure needs to be follow when working with IDOC to Stored procedure.</b></i>
    I am struck up with the error, can any body resolve this issue.
    Thanks in Advance,
    Murthy

    Hi narasimha,
                      This seems to be any error due to incorrect query formation.In your receiver jdbc channel set the parameter logSQLstatement = true.you can find this parameter in the advanced mode. Using this parameter you will be able to see the sql query which is generated at runtime in the audit log in RWB.
    Regards,
    Pragati

  • Execution of subquery of IN and EXISTS clause.

    Hi Friends,
    Suppose we have following two tables:
    emp
    empno number
    ename varchar2(100)
    deptno number
    salary number
    dept
    deptno number
    location varchar2(100)
    deptname varchar2(100)
    status varchar2(100)
    Where dept is the master table for emp.
    Following query is fine to me:
    SELECT empno, ename
    FROM emp,dept
    WHERE emp.deptno = dept.deptno
    AND emp.salary &gt;=5000
    AND dept.status = 'ACTIVE';
    But I want to understand the behaviour of inline query (Used with IN and EXISTS clause) for which I have used this tables as an example (Just as Demo).
    1)
    Suppose we rewrite the above query as following:
    SELECT empno, ename
    FROM emp
    WHERE emp.salary &gt;=5000
    AND deptno in (SELECT deptno FROM dept where status = 'ACTIVE')
    Question: as shown in above query, suppose in our where clause, we have a condition with IN construct whose subquery is independent (it is not using any column of master query's resultset.). Then, will that query be executed only once or will it be executed for N number of times (N= number of records in emp table)
    In other words, how may times the subquery of IN clause as in above query be executed by complier to prepared the subquery's resultset?
    2)
    Suppose the we use the EXISTS clause (or NOT EXISTS clause) with subquery where, the subquery uses the field of master query in its where clause.
    SELECT E.empno, E.ename
    FROM emp E
    WHERE E.salary &gt;=5000
    AND EXISTS (SELECT 'X' FROM dept D where status = 'ACTIVE' AND D.deptno = E.deptno)
    Here also, I got same confusion. For how many times the subquery for EXISTS will be executed by oracle. For one time or for N number of times (I think, it will be N number of times).
    3)
    I know we can't define any fix thumbrule and its highly depends on requirement and other factors, but in general, Suppose our main query is on heavily loaded large transaction table and need to check existance of record in some less loaded and somewhat smaller transaction table, than which way will be better from performance point of view from above three. (1. Use of JOIN, 2. Use of IN, 3. Use of EXISTS)
    Please help me get solutions to these confusions..
    Thanks and Regards,
    Dipali..

    Dipali,
    First, I posted the links with my name only, I don;t know how did you pick another handle for addressing it?Never mind that.
    >
    Now another confusion I got.. I read that even if we used EXISTS and , CBO feels (from statistics and all his analysis) that using IN would be more efficient, than it will rewrite the query. My confusion is that, If CBO is smart enough to rewrite the query in its most efficient form, Is there any scope/need for a Developer/DBA to do SQL/Query tuning? Does this means that now , developer need not to work hard to write query in best menner, instade just what he needs to do is to write the query which resluts the data required by him..? Does this now mean that now no eperts are required for SQL tuning?
    >
    Where did you read that?Its good to see the reference which says this.I haven't come across any such thing where CBO will rewrite the query like this. Have a look at the following query.What we want to do is to get the list of all teh departments which have atleast one employee working in it.So how would be we write this query? Theremay be many ways.One,out of them is to use distinct.Let's see how it works,
    SQL> select * from V$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    SQL> set timing on
    SQL> set autot trace exp
    SQL> SELECT distinct  D.deptno, D.dname
      2        FROM     scott.dept D,scott.emp E
      3  where e.deptno=d.deptno
      4  order by d.deptno;
    Elapsed: 00:00:00.12
    Execution Plan
    Plan hash value: 925733878
    | Id  | Operation                     | Name    | Rows  | Bytes | Cost (%CPU)| T
    ime     |
    |   0 | SELECT STATEMENT              |         |     9 |   144 |     7  (29)| 0
    0:00:01 |
    |   1 |  SORT UNIQUE                  |         |     9 |   144 |     7  (29)| 0
    0:00:01 |
    |   2 |   MERGE JOIN                  |         |    14 |   224 |     6  (17)| 0
    0:00:01 |
    |   3 |    TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 0
    0:00:01 |
    |   4 |     INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 0
    0:00:01 |
    |*  5 |    SORT JOIN                  |         |    14 |    42 |     4  (25)| 0
    0:00:01 |
    |   6 |     TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 0
    0:00:01 |
    Predicate Information (identified by operation id):
       5 - access("E"."DEPTNO"="D"."DEPTNO")
           filter("E"."DEPTNO"="D"."DEPTNO")
    SQL>
    SQL> SELECT distinct  D.deptno, D.dname
      2        FROM     scott.dept D,scott.emp E
      3  where e.deptno=d.deptno
      4  order by d.deptno;
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
    Elapsed: 00:00:00.04
    SQL>So CBO did what we asked it do so.It made a full sort merge join.Now there is nothing wrong in it.There is no intelligence added by CBO to it.So now what, the query looks okay isn't it.If the answer is yes than let's finish the talk here.If no than we proceed further.
    We deliberately used the term "atleast" here.This would govern that we are not looking for entirely matching both the sources, emp and dept.Any matching result should solve our query's result.So , with "our knowledge" , we know that Exist can do that.Let's write teh query by it and see,
    SQL> SELECT   D.deptno, D.dname
      2        FROM     scott.dept D
      3          WHERE    EXISTS
      4                 (SELECT 1
      5                  FROM   scott.emp E
      6                  WHERE  E.deptno = D.deptno)
      7        ORDER BY D.deptno;
        DEPTNO DNAME
            10 ACCOUNTING
            20 RESEARCH
            30 SALES
    Elapsed: 00:00:00.00
    SQL>Wow, that's same but there is a small difference in the timing.Note that I did run the query several times to elliminate the physical reads and recursive calls to effect the demo. So its the same result, let's see the plan.
    SQL> SELECT   D.deptno, D.dname
      2        FROM     scott.dept D
      3          WHERE    EXISTS
      4                 (SELECT 1
      5                  FROM   scott.emp E
      6                  WHERE  E.deptno = D.deptno)
      7        ORDER BY D.deptno;
    Elapsed: 00:00:00.00
    Execution Plan
    Plan hash value: 1090737117
    | Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Ti
    me     |
    |   0 | SELECT STATEMENT             |         |     3 |    48 |     6  (17)| 00
    :00:01 |
    |   1 |  MERGE JOIN SEMI             |         |     3 |    48 |     6  (17)| 00
    :00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT    |     4 |    52 |     2   (0)| 00
    :00:01 |
    |   3 |    INDEX FULL SCAN           | PK_DEPT |     4 |       |     1   (0)| 00
    :00:01 |
    |*  4 |   SORT UNIQUE                |         |    14 |    42 |     4  (25)| 00
    :00:01 |
    |   5 |    TABLE ACCESS FULL         | EMP     |    14 |    42 |     3   (0)| 00
    :00:01 |
    Predicate Information (identified by operation id):
       4 - access("E"."DEPTNO"="D"."DEPTNO")
           filter("E"."DEPTNO"="D"."DEPTNO")Can you see a keyword called Semi here? This means that Oralce did make an equi join but not complete.Compare the bytes/rows returned from this as well as cost with the first query.Can you notice the difference?
    So what do we get from all this?You asked that if CBO becomes so smart, won't we need developers/dbas at that time?The answer is , what one wants to be, a monkey or an astranaut? Confused,read this,
    http://www.method-r.com/downloads/doc_download/6-the-oracle-advisors-from-a-different-perspective-karen-morton
    So it won't matter how much CBO would become intelligent, there will be still limitations to where it can go, what it can do.There will always be a need for a human to look all the automations.Rememember even the most sofisticated system needs some button to be pressed to get it on which is done by a human hand's finger ;-).
    Happy new year!
    HTH
    Aman....

  • SQL server 2000 Procedure executing very slower in SQL 2012

     
    Hi,
    I've migrated my database from SQL 2000 to SQL 2012 using SQL2008 as intermediate. After migration, I found that one of my procedure is timing out from web site. When I run that procedure in Management Studio, it takes 42 seconds to display result. The same
    query is executed in 3 seconds in SQL 2000 version (in first run it takes 10 seconds in SQL 2000 and second run it took 3 seconds only). But in SQL 2012 second and third time also it took 36 seconds. Can anyone explain why the query takes longer time instead
    of less time after the upgrade? 
    Our prod deployment date is approaching so any quick help is appreciated. 
    Thanks in advance.

    You need to compare the execution plans of queries running in 2000 and 2012 to pin point why there is a difference.
    However, have you made sure that you have reindexed the indexes and updated the stats and you still see the difference? If not, please do that and test again.
    Could you post the execution plans?
    Also read this -
    http://blogs.msdn.com/b/psssql/archive/2015/01/30/frequently-used-knobs-to-tune-a-busy-sql-server.aspx
    Regards, Ashwin Menon My Blog - http:\\sqllearnings.com

  • Procedure with IN and OUT date parameters

    Hello Guys,
    could you please tell me where i am doing wrong, i want to get or return the date from the below procedure. It is throwing below error when i try to execute it, appreciate your help.
    Execute Statement:
    exec get_nxt_trd_dt('09/03/2010')
    Error Message:
    PLS-00306: wrong number or types of arguments in call to 'GET_NXT_TRD_DT'
    Procedure Body:
    CREATE OR REPLACE PROCEDURE GET_NXT_TRD_DT
    (INPUT_DT IN DATE,OUTPUT_DT OUT DATE) IS
    BEGIN
    SELECT MIN(DATES) INTO OUTPUT_DT FROM (SELECT DISTINCT DATES FROM (
    SELECT * FROM
    SELECT TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'yyyymmdd'),'Y')+ROWNUM -1 DATES FROM
    SELECT 1
    FROM Dual
    GROUP BY CUBE (2, 2, 2, 2, 2, 2, 2, 2, 2)
    WHERE ROWNUM <= ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD'),'Y'),24) - TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD'),'Y')
    WHERE TO_CHAR( DATES, 'DY') NOT IN ('SAT','SUN')
    MINUS
    SELECT DISTINCT HOLIDAY_DATE FROM HOLIDAY )
    WHERE DATES BETWEEN TO_DATE('08/01/2010','MM/DD/YYYY') AND TO_DATE('09/30/2010','MM/DD/YYYY')
    WHERE DATES > TO_DATE(INPUT_DT,'MM/DD/YYYY');
    END;

    That worked thank you. Could you please help on the below, how to execute the same plsql block defined as function?? Thank you.
    Execute stmts used:
    (1)
    DECLARE
    DT DATE;
    BEGIN
    GET_NXT_TRD_DT(TO_DATE('09/03/2010','MM/DD/YYYY'),DT);
    END;
    Error Message: PLS-00221: 'GET_NXT_TRD_DT' is not a procedure or is undefined
    (2)
    DECLARE
    BEGIN
    GET_NXT_TRD_DT(TO_DATE('09/03/2010','MM/DD/YYYY'));
    END;
    Error Message: PLS-00306: wrong number or types of arguments in call to 'GET_NXT_TRD_DT'
    Function Body:
    CREATE OR REPLACE FUNCTION GET_NXT_TRD_DT
    (INPUT_DT IN DATE,OUTPUT_DT OUT DATE) RETURN DATE IS
    BEGIN
    SELECT MIN(DATES) INTO OUTPUT_DT FROM (SELECT DISTINCT DATES FROM (
    SELECT * FROM
    SELECT TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'yyyymmdd'),'Y')+ROWNUM -1 DATES FROM
    SELECT 1
    FROM Dual
    GROUP BY CUBE (2, 2, 2, 2, 2, 2, 2, 2, 2)
    WHERE ROWNUM <= ADD_MONTHS(TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD'),'Y'),24) - TRUNC(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD'),'YYYYMMDD'),'Y')
    WHERE TO_CHAR( DATES, 'DY') NOT IN ('SAT','SUN')
    MINUS
    SELECT DISTINCT HOLIDAY_DATE FROM HOLIDAY )
    WHERE DATES BETWEEN TO_DATE('08/01/2010','MM/DD/YYYY') AND TO_DATE('09/30/2010','MM/DD/YYYY')
    WHERE DATES > INPUT_DT;
    RETURN(OUTPUT_DT);
    END;
    /

  • Please help - Can not use stored procedure with CTE and temp table in OLEDB source

    Hi,
       I am going to create a simple package. It has OLEDB source , a Derived transformation and a OLEDB Target database.
    Now, for the OLEDB Source, I have a stored procedure with CTE and there are many temp tables inside it. When I give like EXEC <Procedure name> then I am getting the error like ''The metadata  could not be determined because statement with CTE.......uses
    temp table. 
    Please help me how to resolve this ?

    you write to the temp tables that get created at the time the procedure runs I guess
    Instead do it a staged approach, run Execute SQL to populate them, then pull the data using the source.
    You must set retainsameconnection to TRUE to be able to use the temp tables
    Arthur My Blog

  • ESS ERP2005: total compensation statement and salary statement errors

    Hello everyone,
    I am facing two problems with ESS on NW04s J2EE SP10 w. Portal and ERP2005 Backend. Both have been discussed here but some time ago and no sufficient answer has been found so I'd like to do a recap:
    1) Salary Statement (and Time Slip also).
    Even if the PAY_SLIP_XY form in hrforms is correct, working within ERP transaction (PY-HF) and customized in IMG HRFOR, the iview producdes the error "<myForm>" not found. When I change <myForm> the change is recognized so obviously the customizing is correct. The same is about Time_Slip forms.
    Anyway, can anyone point me to a link to integrate Adobe DS at this point, should I, or isn't this possible yet?
    2) Total Compensation Satement ivew throws an ArrayIndexOutOfBoundsException -1. The first few stack trace lines are:
    at com.sap.mw.jco.JCO$Record.getString(JCO.java:12778)
        at com.sap.aii.proxy.framework.core.JcoBaseTypeData.getElementValueAsString(JcoBaseTypeData.java:669)
        at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.getAttributeValueAsString(DynamicRFCModelClass.java:427)
        at com.sap.xss.hr.rep.model.rfwmodel.Hrxss_Ser_Rfw_Rfc_Get_Form_Output.getHeight(Hrxss_Ser_Rfw_Rfc_Get_Form_Output.java:179)
        at com.sap.xss.hr.rep.fcrfw.FcRepFramework.callRfcGetForm(FcRepFramework.java:395)
    Restarting the server doesn't help, the server was newly started as the error occured.
    Maybe I missed some IMG activity? I went through the Company Compensation Management and added some values to compensation type, the structure is definied, but not sure if this is all.
    Pls can anyone help. I'm just implementing the standard BP for the moment, no individual app.
    Regards
    Carsten

    Hi Patrick,
    no unfortunately not and as you can see we've got no answers.
    But I'm still in the need to fix it. It's not very urgent, but to know the solution would be great.
    In general we still have problems with print forms in ESS/MSS webdynpro implementation. The HRFORM is defined and well customized in IMG, so I think this is not the point.
    As I pointed out in another post I am confused if Adobe Document Services is needed to render (PDF) print forms since ESS/MSS 600 (for ERP 2005) or what else.
    Do you know?
    Did you get other print forms like salary statement working?
    I went through the entire post installation procedure regarding Adobe DS but it did  not help.
    I always get ther failure "The form  is the form customized for ESS in IMG and the form does exist and is tested within HRFORM transaction.
    Except the time slip (and as well total compensation), where we get this "ArrayIndexOutOfBounds" exception.
    Regards
    Carsten
    Message was edited by:
            Carsten Schön
    Message was edited by:
            Carsten Schön
    correction: error also in total conpensation statement

  • Difficulties with execute immediate and 'in' clause

    Hello all,
    I have some SQL that will have to run dynamically, which I can get to work by building a long statement, then getting it hard-parsed
    example:
    sql_stmt VARCHAR2(256) :=
    'select distinct some_id from table1
    where lname = ''Smith''
    and fname in(''Joe'', ''Joey'', ''Joseph'')
    and ssn = 111223333';
    execute immediate sql_stmt into new_id_value;
    the above state executes fine and returns the desired result.
    HOWEVER, when I try to use bind variables (this statement will be called several million times), I get a no rows returned error.
    I use bind variables as follows:
    sql_stmt VARCHAR2(256);
    vlname VARCHAR2(50) := 'Smith';
    vssn NUMBER := 111223333;
    vfname VARCHAR2(100) := '''Joe'', ''Joey'', ''Joseph''';
    sql_stmt :=
    'select distinct some_id from table1
    where lname = :vlname
    and fname in(:vfname)
    and ssn = :vssn;
    execute immediate sql_stmt into new_id_value
    using vlname, vfname, vssn;
    I know the issue involves the 'in' clause because I've substituted hardcoded values in and it has worked.
    any suggestions?

    Well maybe its all a little confusing, does an end to end demo make it any clearer Mr Bidness?
    SQL> create or replace type tabstr_t as table of varchar2(4000)
      2  /
    Type created.
    SQL> create or replace function tabstr (
      2      p_str in varchar2,
      3      p_sep in varchar2 default ','
      4      )
      5  return tabstr_t
      6  is
      7      l_str long := p_str || p_sep;
      8      l_tabstr tabstr_t := tabstr_t();
      9  begin
    10      while l_str is not null loop
    11          l_tabstr.extend(1);
    12          l_tabstr(l_tabstr.count) := rtrim(substr(
    13                  l_str,1,instr(l_str,p_sep)),p_sep);
    14          l_str := substr(l_str,instr(l_str,p_sep)+1);
    15      end loop;
    16      return l_tabstr;
    17  end;
    18  /
    Function created.
    SQL> var s varchar2(100)
    SQL> exec :s := 'king,turner,ward'
    PL/SQL procedure successfully completed.
    SQL> select ename, sal from emp
      2  where ename in (
      3    select upper(column_value) from
      4    table(cast(tabstr(:s) as tabstr_t))
      5    );
    ENAME             SAL
    KING             5000
    TURNER           1500
    WARD             1250
    SQL> exec :s := 'jones,blake,clark'
    PL/SQL procedure successfully completed.
    SQL> /
    ENAME             SAL
    BLAKE            2850
    CLARK            2450
    JONES            2975

Maybe you are looking for

  • Editing Assistants and Templates

    I am using a G4Powerbook with OS X 10.4.9. How on earth do I edit the assistants and templates in "starting points"? Most of these are ugly and just clutter the thing. (I have created a few templates, and they are hard to find because of all the othe

  • Fuzzy vector graphics when exporting to PDF?

    Hi all, I've switched to Fireworks from Omnigraffle because I work in a Windows environment and there isn't a Windows-compatible version of Omnigraffle available. I've noticed that when I export mockups/wireframes that I create in Fireworks to PDF, t

  • Mail ccs all outgoing email even though its turned off in preferences

    Recently mac mail started creating "ccs" for all my outgoing mail (several accounts). I have gone to preferences and "automatically cc/bcc myself" is unchecked. I have checked it and then unchecked it and still I get ccs and I don't want them.

  • Ora 8i & Developer 6i Installation

    Have been medically laid up for about a year and want to get back to Oracle database learning on Personal Oracle. I can remember a three issues from my first install. 1) An issue re Developer and Oracle homes requiring DIFFERENT homes in different di

  • CS6 Spell check error: The operation cannot complete because of an unknown error [CANT]

    Hi Everyone, Has anyone else encountered this error when trying to spell check? Is there a way around it?