Procedure optimization

Hi, I made a oracle procedure which takes 30 mins to get executed, i tried a lot but could optimize it further. Each table used has avg data of 40,000 records, the code which i have written is
CREATE OR REPLACE PROCEDURE ESPF_ABPP.Testingperform AS
routing1 varchar2(140);
val varchar2(40);
routingid varchar2(150);
so_id VARCHAR2(10);
so_line_id VARCHAR2(10);
items varchar2(20);
operationseqn number(10);
ind varchar(20);
operation varchar2(40);
x number;
y number;
z number;
j number;
seq number;
sq number;
len number;
BEGIN
DELETE FROM sridhar_stg_routing_operation;
COMMIT;
FOR c1 IN (SELECT vbeln,
posnr,
routeind,REPLACE(process_path,'--','-') AS process_path
FROM sridhar_STG_ZPP03_PROC_PATH
WHERE process_path IS NOT NULL)
LOOP
operationseqn:=10;
c1.process_path:=c1.process_path||'-';
routing1:=c1.process_path;
ind:=c1.routeind;
so_id:=c1.vbeln;
so_line_id:=c1.posnr;
SELECT NVL(LENGTH(REPLACE(process_path,'--','-'))-LENGTH(REPLACE(REPLACE(process_path,'--','-'),'-',''))+1,0)
INTO j FROM sridhar_stg_zpp03_proc_path t
WHERE vbeln=c1.vbeln
AND posnr=c1.posnr
AND routeind=c1.routeind;
x:=1;
y:=1;
z:=2;
len:=0;
FOR k IN 1..j
LOOP
val:=substr(routing1,x,instr(substr(routing1,x),'-',1)-1);
len:=len+length(substr(routing1,x,instr(substr(routing1,x),'-',1)));
x:=len+1;
SELECT NVL(matnr,'NA') INTO items
FROM sridhar_stg_vbap RIGHT OUTER JOIN dual ON vbeln=so_id AND posnr=so_line_id;
SELECT NVL(operation_name,'NA') INTO operation
FROM sri_ud_workcenter_master_list RIGHT OUTER JOIN dual ON
work_center_name=val;
IF items IS NOT NULL THEN
routingid:=so_id||'-'||TO_CHAR(so_line_id)||'-'||items;
END IF;
IF val IS NOT NULL THEN
INSERT INTO sridhar_STG_ROUTING_OPERATION(routingid,operation,operationseq,workcenter)
VALUES (routingid||'-'||c1.routeind, operation, operationseqn, val);
commit;
END IF;
operationseqn:=operationseqn+10;
END LOOP;
END LOOP;
COMMIT;
FOR c3 IN (SELECT routingid,max(operationseq) op
FROM sridhar_STG_ROUTING_OPERATION
WHERE substr(routingid,1,10) IN (SELECT vbeln
FROM sridhar_stg_vbak
WHERE auart!='01')
GROUP BY routingid)
LOOP
seq:=10;
seq:=seq+c3.op;
INSERT INTO sridhar_STG_ROUTING_OPERATION(routingid,operation,operationseq,workcenter)
VALUES(c3.routingid,'DSPT',seq,'DSPT1');
COMMIT;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No Data Found');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error Occured'||SQLCODE||'-'||SQLERRM);
ROLLBACK;
END;
can any one help me in this
regards,

>
When you post, use code tags
>
I think you meant to use curly braces and not brackets. So use \ before and after the actual code.
You can get that to display properly without being interpreted by putting a single backslash before the left curly brace.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Big PL/SQL stored procedure optimization.

    Hi There,
    Can any one let me the basic steps for optimization or tuning of a PL/SQL stored procedure for better performance.
    DB: 11.2.0
    OS: Solaris 10
    looking forward.
    Regards,

    >
    Can any one let me the basic steps for optimization or tuning of a PL/SQL stored procedure for better performance.
    >
    Seriously - how do you expect anyone to give you any specific things to do when you don't provide any specific information about your procedure?
    A procedured is comprised of one or more steps. So to tune it you need to determine which steps are 'slow' and make them 'fast'! ;)
    There are several common causes of performance problems with PL/SQL are:
    1. Using PL/SQL when SQL should have been used. Don't use PL/SQL to begin with - always use SQL unless it just can't do the job required. The 'PL' in PL/SQL means 'Procedural Language' and should be used for transactional (multi-step) processing or when 'procedural' operations are needed that aren't available in SQL.
    2. Using slow-by-slow (row by row) processing instead of BULK processing.
    3. Using multiple nested LOOPs when a more complex query could have allowed a single loop to be used.
    4. Using COMMITs more frequently than required. Search this forum and you will find far too many questions about how to do a COMMIT after 10,000 rows (or some other number). A COMMIT should be performed AFTER a transaction has been completed, not during the middle of it. Frequent commits generally use more resources, degrade performance and risk the famous 'snapshot too old' message.
    The very first step of performance 'tuning' is to first verify that any 'tuning' is even required. Too many people suffer from CTD - compulsive tuning disorder.
    The second step is to identify what step, or steps, of the process are performing below par.
    Which means the best developers are proactive - they plan ahead.
    1. Create an explain plan BEFORE the code goes to production. Once the code has been tested and believed to perform properly an execution plan should be created and SAVED for future reference. That saved plan can then be used later, when you suspect a performance issue, to detect changes that might have affected performance: create a new plan and compare it to the baseline.
    2. Create explains for ALL key queries. As suggested by step #1 performance is all about comparison: performance 'now' COMPARED TO performance 'then'. If the don't know the performance 'then' it can be difficult to know if the performance has changed. If a query has a 'now' execution time of 2 minutes is that 'fast' or 'slow'? Well - compared to WHAT? You can't know 'fast' or 'slow' if you don't know 'then' and 'now'. How fast was it yesterday, last week or last month?
    3. Instrument your procedural code. That means measure, for EACH STEP, how long it took to execute and how much data it worked with. That information needs to be logged. Your logging and data collection can be static (it ALWAYS happens) or dynamic. Oracle's own code is HEAVILY instrumented. Some operations and activity are always logged and available in the data dicitionary views or various performance reports such as AWR.
    Other operations, such as the extended trace facility, only collect data on request.
    IMHO your first step should be to begin the 'proactive' steps above.

  • Flags needs to set to run stored procedure fast

    Hi,
    I need to understand what all flags that we need to set run stored procedure fast.
    e.g. set no count on command is one option, please redirect me to other command so that I can use those for each stored procedure.

    That is the only general option, however, no relationship to performance.  Other options may be appropriate depending on the program statements.
    To achieve good performance, optimize the stored procedure:
    http://www.sqlusa.com/articles/query-optimization/
    The underlying principles of stored procedure optimization:
    1. Each statement must be optimized
    2. Avoid unnecessary statements & excessive looping
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Database Design
    New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014

  • How to improve stored procedure performance?

    hi,
    Suppose I have a stored procedure which contains 30 insert/update statements. How do I know Stored Procedure is slowly running or don't have any performance issue? how to improve performance?
    Thanks in advance.
    Anujit Karmakar Sr. Software Engineer

    Stored Procedures Optimization Tips
    Use stored procedures instead of heavy-duty queries.
    This can reduce network traffic, because your client will send to server only stored procedure name (perhaps with some parameters) instead of large heavy-duty queries text. Stored procedures can be used to enhance security and conceal underlying data objects
    also. For example, you can give the users permission to execute the stored procedure to work with the restricted set of the columns and data.
    Include the SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.
    This can reduce network traffic, because your client will not receive the message indicating the number of rows affected by a Transact-SQL statement.
    Call stored procedure using its fully qualified name.
    The complete name of an object consists of four identifiers: the server name, database name, owner name, and object name. An object name that specifies all four parts is known as a fully qualified name. Using fully qualified names eliminates any confusion about
    which stored procedure you want to run and can boost performance because SQL Server has a better chance to reuse the stored procedures execution plans if they were executed using fully qualified names.
    Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset.
    The RETURN statement exits unconditionally from a stored procedure, so the statements following RETURN are not executed. Though the RETURN statement is generally used for error checking, you can use this statement to return an integer value for any other reason.
    Using RETURN statement can boost performance because SQL Server will not create a recordset.
    Don't use the prefix "sp_" in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.
    The prefix "sp_" is used in the system stored procedures names. Microsoft does not recommend to use the prefix "sp_" in the user-created stored procedure name, because SQL Server always looks for a stored procedure beginning with "sp_"
    in the following order: the master database, the stored procedure based on the fully qualified name provided, the stored procedure using dbo as the owner, if one is not specified. So, when you have the stored procedure with the prefix "sp_" in the
    database other than master, the master database is always checked first, and if the user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.
    Use the sp_executesql stored procedure instead of the EXECUTE statement.
    The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve readability of your code when there are many parameters are used. When you use the sp_executesql stored procedure to
    executes a Transact-SQL statements that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.
    Use sp_executesql stored procedure instead of temporary stored procedures.
    Microsoft recommends to use the temporary stored procedures when connecting to earlier versions of SQL Server that do not support the reuse of execution plans. Applications connecting to SQL Server 7.0 or SQL Server 2000 should use the sp_executesql system
    stored procedure instead of temporary stored procedures to have a better chance to reuse the execution plans.
    If you have a very large stored procedure, try to break down this stored procedure into several sub-procedures, and call them from a controlling stored procedure.
    The stored procedure will be recompiled when any structural changes were made to a table or view referenced by the stored procedure (for example, ALTER TABLE statement), or when a large number of INSERTS, UPDATES or DELETES are made to a table referenced by
    a stored procedure. So, if you break down a very large stored procedure into several sub-procedures, you get chance that only a single sub-procedure will be recompiled, but other sub-procedures will not.
    Try to avoid using temporary tables inside your stored procedure.
    Using temporary tables inside stored procedure reduces the chance to reuse the execution plan.
    Try to avoid using DDL (Data Definition Language) statements inside your stored procedure.
    Using DDL statements inside stored procedure reduces the chance to reuse the execution plan.
    Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.
    The WITH RECOMPILE option prevents reusing the stored procedure execution plan, so SQL Server does not cache a plan for this procedure and the procedure is recompiled at run time. Using the WITH RECOMPILE option can boost performance if your query will vary
    each time it is run from the stored procedure because in this case the wrong execution plan will not be used.
    Use SQL Server Profiler to determine which stored procedures has been recompiled too often.
    To check the stored procedure has been recompiled, run SQL Server Profiler and choose to trace the event in the "Stored Procedures" category called "SP:Recompile". You can also trace the event "SP:StmtStarting" to see at what point
    in the procedure it is being recompiled. When you identify these stored procedures, you can take some correction actions to reduce or eliminate the excessive recompilations.
    http://www.mssqlcity.com/tips/stored_procedures_optimization.htm
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Reset file name and line number in preprocessor

    We are using Sun Studio 12u1 on Solaris x86 10u9.
    For one of our large projects our make file copies many C++ source files into one large allsource.cpp file. This results in significantly faster compilation and better inter-procedural optimizations.
    Unfortunately, when the compiler generates warning or error messages they refer to allsource.cpp. Also when it comes time to debug, dbx is looking for debugging information for the original source file instead of looking for allsource.o.
    On Windows (MSVC), we use the #line directive to reset the line number and filename so that the error messages point to the correct line and number, and so that the debugger knows that the debugging information for myfile.cpp is actually in allsource.o.
    Does the Sun compiler have anything similar to the #line directive?

    To reset the preprocessor to the start of a new file:
    #1 "filename"
    where filename is the name or complete path name of the file.
    To change the line number within the current file:
    #N
    or
    #line N
    where N is an integer
    Example:
    % cat z.cc
    struct S { X x; };
    #1 "/foo/bar.h"
    Int I;
    #500
    Float F;
    #line 1000
    Double D;
    88% CC -c z.cc
    "z.cc", line 1: Error: Type name expected instead of "X".
    "/foo/bar.h", line 1: Error: Int is not defined.
    "/foo/bar.h", line 500: Error: Float is not defined.
    "/foo/bar.h", line 1000: Error: Double is not defined.
    4 Error(s) detected.BTW, you might get a similar improvement in compile time by using precompiled headers.
    The -xipo option provide inter-procedural optimization across compilation units. Refer to the C++ Users Guide for details.
    We seem to have a bug in the Forum software. My original source code and the compiler output have double quotes ("...") but they show as single quotes in the code brackets.
    Edited by: clamage45 on Apr 13, 2010 1:13 PM

  • Do we need to recompile entire code base ?

    Do we need to recompile the entire code base to utilize the efficiency of a Sun SPARC Enterprise T5220 Server.
    We will not be able to perform any of the optimization on the code, as it affects the working nature of the product.
    So I'm not able to utilize http://www.spec.org/cpu2006/flags/Sun-Solaris-Studio12-and-gccfss4.2.html#Section_compiler
    any of the above flags.
    I'm able to run the software built on solaris 10 using gcc-3.4.2. can you please suggest is it required to build the entire codebase or not ?
    are there any special flags with gcc or gfss compilers for getting better performance on multi core architectures?

    We will need a little bit more information about the nature of the application etc, to make any reasonable recommendations.
    You mention
    "We will not be able to perform any of the optimization on the code, as it affects the working nature of the product. "
    Compiler optimizations are always safe, as long as your code is correct. Some subset of the compiler flags enable more aggressive optimizations and can alter the precision of the floating point operations like -fsimple=2. These are however, documented and you can avoid such flags if you feel it may effect the stability of your application. -fast is a good starting point.
    There are a wealth of tools offered by Gccfss and Sun Studio. I am listing them here in no specific order.
    1. Please take a look at Performance Analyzer, works with Gccfss.
    http://developers.sun.com/sunstudio/documentation/ss12/mr/READMEs/analyzer.html
    You can download it from developers.sun.com/sunstudio
    2. ATS is a tool that is offered part of the distribution, whose whole purpose it to help you tune your application. It is already bundled in your download. You can read more about it here
    http://cooltools.sunsource.net/ats/
    Let it run on your binary, and it will automatically suggest the best options for your application.
    3. You can try -xautopar which enable automatic parallelization. The benefit largely depends on the parallelization opportunities that can be discovered by the compiler. This will heavily depend on your application though.
    4. You should definitely try "-fast -xipo", the former which is a macro flag which enables aggressive optimizations in the compiler, the latter which enables inter procedural optimizations.
    Thanks
    Prashanth

  • Paralellism problem after recent upgrade to 11.2

    Hi Gurus,
    We have recently upgraded from OWB 10.1 to OWB 11.2
    In 11.2 there is no parallelism for DML statements (INSERT, MERGE etc) in OWB mappings.
    The reason is that the new configuration parameter "Enable Parallel DML" is by default set to false (in 10.1, parallel DML was always enabled).
    We have enabled the parallel DML now in 11.2.
    However we have to still set the parallel hint in the target tables(s) for the parallel DML to be in force
    Now;As I have a huge set of mappings and we are wondering on what basis should we decide on to set these
    hints on target table
    If we enable the hints for all of the target tables it is resulting in
    1) few mappings executing faster(hints in place and paralellism helped)
    2) few mappings executing slower(the paralellism made performance worse)
    3) none(no change with or without paralelism i.e in this case without paralelism helps as it will free up resources and result in total performance improvement )
    so,on what basis should we decide on enabling hints and paralelism in OWB 11.2
    Appreciate your valuable inputs
    BR
    Sridha

    http://www.oracle.com/technetwork/articles/datawarehouse/twp-parallel-execution-fundamentals-133639.pdf
    http://www.akadia.com/services/ora_parallel_processing.html
    http://www.orafaq.com/wiki/Parallel_Query_FAQ
    or use google for specific situations.
    I can tell you this. We have over 2k processes that run daily and 200+ monthly processes that are loads of data with over 100m rows, sometimes more. With that 2000 processes only about 10 of them use parallel execution.
    In general we use parallel because we have to, not because we want to.
    As I said it depends on so many factors. Your system configuration, your procedures, optimization techniques (level), ...
    As default value for us, parallel is OFF, but we hint are procedures to do what we want them to do and not what Oracle tells them to do.

  • Optimising a query

    Hi experts
    i have made the following query
    SELECT
    T0.DOCSTATUS
    ,T0.DOCDATE
    ,T0.SERIES
    ,T2.DocEntry
    , T2.ItemCode
    , T2.Quantity
    , T2.Price
    , ISNULL(T2.DiscPrcnt, 0) AS DiscPrcnt
    , T2.LineTotal
    FROM dbo.OINV T0
    INNER JOIN dbo.OCRD T1 ON T1.CardCode = T0.CardCode
    INNER JOIN dbo.INV1 T2 ON T2.DocEntry = T0.DocEntry
    INNER JOIN dbo.OITM T3 ON T3.ItemCode = T2.ItemCode
    WHERE
    ((T0.DocStatus != 'C') OR ((T0.DocDate >= DATEADD(MM,-3,GETDATE()) AND T0.DocStatus = 'C')))
    AND (T0.Series IN ('1000', '1002', '1003', '1006', '1280', '1281') AND T1.U_Web = 'Y' AND (T3.ItemCode >= '00000' AND T3.ItemCode<='99999') AND T3.U_categ NOT IN ('19', '20', '21'))
    and i have realised that it tooks ages to give results for the line
    *((T0.DocStatus != 'C') OR ((T0.DocDate >= DATEADD(MM,-3,GETDATE()) AND T0.DocStatus = 'C'))) *
    do you have any idea why it happens?
    thanks in advance for your time!

    hi,
    put query in a stored procedure.
    please refer to this articles why Store Procedure more recommended when it comes to Optimizing performance.
    http://blog.sqlauthority.com/2010/02/16/sql-server-stored-procedure-optimization-tips-best-practices/
    http://blog.sqlauthority.com/2007/04/13/sql-server-stored-procedures-advantages-and-best-advantage/
    regards,
    Fidel

  • Help for optimization of procedure

    Hi,
    I am having following procedure it is accessing LY_RWPT_SUCCESS table having 2501818 records. i want to insert data into LY_RWPT_cap_SUCCESS with following logic but its taking lot of time .
    How we can optimize this query to give better result. pls help.
    CREATE OR REPLACE PROCEDURE "LY_PRODUCT_CAPPING_old"(P_MONTH VARCHAR2) IS
    --v_sum_rewards number
    V_SUM_REWARDS integer;
    V_FLAG VARCHAR2(1);
    V_AMOUNT integer;
    V_REWARD NUMBER;
    V_REMARKS VARCHAR2(1000);
    cursor c1 is
    select *
    from LY_RWPT_SUCCESS
    where as_of_month = P_MONTH
    -- and source_account_number ='000101006399'
    order by source_account_number asc,
    product_code asc,
    transaction_id asc,
    transaction_date asc;
    begin
    DELETE FROM LY_RWPT_CAP_SUCCESS WHERE AS_OF_MONTH = P_MONTH;
    for i in c1 loop
    V_REWARD := I.REWARDS;
    /*select nvl(sum(rewards),0) INTO V_SUM_REWARDS from ly_rwpt_cap_success_temp
    where as_of_month = P_MONTH
    and product_code = I.PRODUCT_CODE
    AND SOURCE_ACCOUNT_NUMBER = I.SOURCE_ACCOUNT_NUMBER
    and partial_flag in( 'F','P');*/
    if V_REWARD != 0 THEN
    select nvl(sum(rewards), 0)
    INTO V_SUM_REWARDS
    from ly_rwpt_cap_success
    where as_of_month = P_MONTH
    and product_code = I.PRODUCT_CODE
    AND SOURCE_ACCOUNT_NUMBER = I.SOURCE_ACCOUNT_NUMBER
    and partial_flag in ('F', 'P');
    IF (V_SUM_REWARDS >= I.PRODUCT_CAPPING) THEN
    V_REMARKS := i.remarks || ' but receiving ' || ' ' || 0 ||
    ' points as reached to product capping';
    -- V_REMARKS := i.PRODUCT_NAME ||'transaction successfully earned'||' ' ||0 ;
    V_FLAG := 'N';
    INSERT INTO LY_RWPT_CAP_SUCCESS
    VALUES
    (I.source_account_number,
    I.cust_id,
    I.customer_status_code,
    I.product_code,
    I.value,
    I.transaction_date,
    I.processing_date,
    I.balance,
    I.eligible_tag,
    0,
    I.transaction_id,
    I.payee_name,
    V_REMARKS,
    V_FLAG,
    I.as_of_month,
    I.product_name,
    I.product_capping,
    I.CUSTOMER_SEGMENT,
    I.RD_ACCOUNT_NBR,
    I.MEMBER_CUST_ID);
    COMMIT;
    ELSIF (V_SUM_REWARDS = 0 AND V_REWARD <= I.PRODUCT_CAPPING) THEN
    V_REMARKS := I.REMARKS;
    --V_REMARKS := i.PRODUCT_NAME ||'transaction successfully earned'||' ' || V_REWARD ;
    V_FLAG := 'F';
    INSERT INTO LY_RWPT_CAP_SUCCESS
    VALUES
    (I.source_account_number,
    I.cust_id,
    I.customer_status_code,
    I.product_code,
    I.value,
    I.transaction_date,
    I.processing_date,
    I.balance,
    I.eligible_tag,
    V_REWARD,
    I.transaction_id,
    I.payee_name,
    V_REMARKS,
    V_FLAG,
    I.as_of_month,
    I.product_name,
    I.product_capping,
    I.CUSTOMER_SEGMENT,
    I.RD_ACCOUNT_NBR,
    I.MEMBER_CUST_ID
    COMMIT;
    ELSIF (i.product_capping < (V_SUM_REWARDS + V_REWARD)) then
    V_AMOUNT := ABS(I.PRODUCT_CAPPING - V_SUM_REWARDS);
    V_REMARKS := i.remarks || ' but earned ' || ' ' || V_AMOUNT ||
    ' partial points' || ' as exceeding product capping';
    -- V_REMARKS := i.PRODUCT_NAME ||'transaction successfully earned'||' ' || V_AMOUNT ;
    V_FLAG := 'P';
    INSERT INTO LY_RWPT_CAP_SUCCESS
    VALUES
    (I.source_account_number,
    I.cust_id,
    I.customer_status_code,
    I.product_code,
    I.value,
    I.transaction_date,
    I.processing_date,
    I.balance,
    I.eligible_tag,
    V_AMOUNT,
    I.transaction_id,
    I.payee_name,
    V_REMARKS,
    V_FLAG,
    I.as_of_month,
    I.product_name,
    I.product_capping,
    I.CUSTOMER_SEGMENT,
    I.RD_ACCOUNT_NBR,
    I.MEMBER_CUST_ID);
    COMMIT;
    ELSIF
    (i.product_capping >= (V_SUM_REWARDS + V_REWARD)) then
    V_REMARKS := I.REMARKS;
    -- V_REMARKS := i.PRODUCT_NAME ||'transaction successfully earned'||' ' || V_REWARD ;
    V_FLAG := 'F';
    INSERT INTO LY_RWPT_CAP_SUCCESS
    VALUES
    (I.source_account_number,
    I.cust_id,
    I.customer_status_code,
    I.product_code,
    I.value,
    I.transaction_date,
    I.processing_date,
    I.balance,
    I.eligible_tag,
    V_REWARD,
    I.transaction_id,
    I.payee_name,
    V_REMARKS,
    V_FLAG,
    I.as_of_month,
    I.product_name,
    I.product_capping,
    I.CUSTOMER_SEGMENT,
    I.RD_ACCOUNT_NBR,
    I.MEMBER_CUST_ID);
    END IF;
    COMMIT;
    ELSE
    V_REMARKS := i.remarks;
    -- V_REMARKS := i.PRODUCT_NAME ||'transaction successfully earned'||' '||0 ;
    V_FLAG := 'R';
    INSERT INTO LY_RWPT_CAP_SUCCESS
    VALUES
    (I.source_account_number,
    I.cust_id,
    I.customer_status_code,
    I.product_code,
    I.value,
    I.transaction_date,
    I.processing_date,
    I.balance,
    I.eligible_tag,
    0,
    I.transaction_id,
    I.payee_name,
    V_REMARKS,
    V_FLAG,
    I.as_of_month,
    I.product_name,
    I.product_capping,
    I.CUSTOMER_SEGMENT,
    I.RD_ACCOUNT_NBR,
    I.MEMBER_CUST_ID);
    END IF;
    COMMIT;
    END LOOP;
    END;

    Try this
    create or replace procedure ly_product_capping_old
       p_month varchar2
    is
    begin
       insert
         into ly_rwpt_cap_success
       select i.source_account_number,
              i.cust_id,
              i.customer_status_code,
              i.product_code,
              i.value,
              i.transaction_date,
              i.processing_date,
              i.balance,
              i.eligible_tag,
              case when i.reward != 0 then
                      case when nvl(j.rewards, 0) >  i.product_capping then 0
                        when nvl(j.rewards, 0) =  0 and i.rewards <= i.product_capping then i.rewards
                     when i.product_capping <  nvl(j.rewards, 0) + i.rewards then abs(i.product_capping -  nvl(j.rewards, 0))
                     when i.product_capping >= nvl(j.rewards, 0) + i.rewards then i.rewards
                   end
                   else 0
              end v_reward,
              i.transaction_id,
              i.payee_name,
              case when i.reward != 0 then
                      case when nvl(j.rewards, 0) >  i.product_capping then i.remarks || ' but receiving ' || ' ' || 0 || ' points as reached to product capping'
                        when nvl(j.rewards, 0) =  0 and i.rewards <= i.product_capping then i.remarks
                     when i.product_capping <  nvl(j.rewards, 0) + i.rewards then i.remarks || ' but earned  ' || ' ' || abs(i.product_capping -  nvl(j.rewards, 0)) || ' partial  points' || ' as exceeding product capping';
                     when i.product_capping >= nvl(j.rewards, 0) + i.rewards then i.remarks
                   end
                else i.remarks
              end  v_remarks,
              case when i.reward != 0 then
                      case when nvl(j.rewards, 0) >  i.product_capping then 'N'
                        when nvl(j.rewards, 0) =  0 and i.rewards <= i.product_capping then 'F'
                     when i.product_capping <  nvl(j.rewards, 0) + i.rewards then 'P'
                     when i.product_capping >= nvl(j.rewards, 0) + i.rewards then 'F'
                   end
                else 'R'
              end v_flag,
              i.as_of_month,
              i.product_name,
              i.product_capping,
              i.customer_segment,
              i.rd_account_nbr,
              i.member_cust_id
         from ly_rwpt_success i
         left
         join (
                 select product_code, source_account_number, sum(rewards) rewards
                   from ly_rwpt_cap_success
                  where as_of_month  = p_month
                    and partial_flag in ('F', 'P')
                  group
                     by product_code, source_account_number
              ) j
           on i. product_code = j.product_code
          and i.source_account_number = j.source_account_number
        where as_of_month = p_month;
       commit;
    end;There could be some semantic errors, if found please correct. And also please specify the column list in the insert statement.
    And oh forgot to mention the code is untested :)

  • Optimize an Store Procedure

    Hi, I have created a table and a package to perform several maintenance tasks.While creating a procedure to retrieve information. I would like to optimize the sp
    Please considere that this sp is employed with a VB interface.
    CREATE TABLE D_METEREOLOG (
    cod_fundo CHAR(3) NOT NULL,
    fecha DATE NOT NULL,
    temp_max INTEGER NULL,
    temp_min INTEGER NULL,
    porc_humedad NUMBER(6,3) NULL,
    evaporacion NUMBER(6,3) NULL,
    prec_pluvial NUMBER(6,3) NULL,
    velvient_min NUMBER(6,3) NULL,
    velvient_max NUMBER(6,3) NULL,
    usuario CHAR(12) NULL,
    fech_act DATE NULL,
    estado CHAR(1) NULL
    ALTER TABLE D_METEREOLOG
    ADD ( PRIMARY KEY (cod_fundo, fecha) ) ;
    CREATE OR REPLACE PACKAGE BODY upkg_mrp
    AS
    AS
    TYPE t_cfundo IS TABLE OF d_metereolog.cod_fundo%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_fecha IS TABLE OF VARCHAR2(20)
    INDEX BY BINARY_INTEGER;
    TYPE t_tmax IS TABLE OF d_metereolog.temp_max%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_tmin IS TABLE OF d_metereolog.temp_min%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_phumedad IS TABLE OF d_metereolog.porc_humedad%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_evaporacion IS TABLE OF d_metereolog.evaporacion%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_ppluvial IS TABLE OF d_metereolog.prec_pluvial%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_vmax IS TABLE OF d_metereolog.velvient_max%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_vmin IS TABLE OF d_metereolog.velvient_min%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_usuario IS TABLE OF d_metereolog.usuario%TYPE
    INDEX BY BINARY_INTEGER;
    TYPE t_fact IS TABLE OF VARCHAR2(20)
    INDEX BY BINARY_INTEGER;
    TYPE t_estado IS TABLE OF d_metereolog.estado%TYPE
    INDEX BY BINARY_INTEGER;
    PROCEDURE usp_getdata_dmetereolog
    (p_cfundo IN OUT d_metereolog.cod_fundo%TYPE,
    p_fecha IN OUT d_metereolog.fecha%TYPE,
    p_tmax OUT d_metereolog.temp_max%TYPE,
    p_tmin OUT d_metereolog.temp_min%TYPE,
    p_phumedad OUT d_metereolog.porc_humedad%TYPE,
    p_evaporac OUT d_metereolog.evaporacion%TYPE,
    p_ppluvial OUT d_metereolog.prec_pluvial%TYPE,
    p_vmax OUT d_metereolog.velvient_max%TYPE ,
    p_vmin OUT d_metereolog.velvient_min%TYPE ,
    p_usuario OUT d_metereolog.usuario%TYPE ,
    p_fact OUT d_metereolog.fech_act%TYPE,
    p_estado OUT d_metereolog.estado%TYPE
    CREATE OR REPLACE PACKAGE BODY upkg_mrp
    AS
    PROCEDURE usp_getdata_dmetereolog
    (p_cfundo IN OUT d_metereolog.cod_fundo%TYPE,
    p_fecha IN OUT d_metereolog.fecha%TYPE,
    p_tmax OUT d_metereolog.temp_max%TYPE,
    p_tmin OUT d_metereolog.temp_min%TYPE,
    p_phumedad OUT d_metereolog.porc_humedad%TYPE,
    p_evaporac OUT d_metereolog.evaporacion%TYPE,
    p_ppluvial OUT d_metereolog.prec_pluvial%TYPE,
    p_vmax OUT d_metereolog.velvient_max%TYPE ,
    p_vmin OUT d_metereolog.velvient_min%TYPE ,
    p_usuario OUT d_metereolog.usuario%TYPE ,
    p_fact OUT d_metereolog.fech_act%TYPE,
    p_estado OUT d_metereolog.estado%TYPE
    IS
    CURSOR aux_cur IS
    SELECT cod_fundo,fecha,temp_max,temp_min,porc_humedad,evaporacion,
    prec_pluvial,velvient_max,velvient_min,usuario,fech_act,estado
    FROM d_metereolog
    WHERE cod_fundo = p_dmetereolog.cod_fundo AND
    fecha = TO_DATE(p_dmetereolog.fecha,'DD/MM/YYYY');
    BEGIN
    FOR dyn_cur IN aux_cur
    LOOP
    p_dmetereolog.cod_fundo:=dyn_cur.cod_fundo;
    p_dmetereolog.fecha:=dyn_cur.fecha;
    p_dmetereolog.temp_max:=dyn_cur.temp_max;
    p_dmetereolog.temp_min:=dyn_cur.temp_min;
    p_dmetereolog.porc_humedad:=dyn_cur.porc_humedad;
    p_dmetereolog.evaporacion:=dyn_cur.evaporacion;
    p_dmetereolog.prec_pluvial:=dyn_cur.prec_pluvial;
    p_dmetereolog.velvient_max:=dyn_cur.velvient_max;
    p_dmetereolog.velvient_min:=dyn_cur.velvient_min;
    p_dmetereolog.usuario:=dyn_cur.usuario;
    p_dmetereolog.fech_act:=dyn_cur.estado;
    END LOOP;
    END usp_getdata_dmetereolog;
    Best regards
    Benjamin

    1. I am trying to return just a single row of data
    2. this should be
    TO_DATE(p_fecha,'DD/MM/YYYY');
    I tried to work with a single type to make it easier
    /*============================================*/
    CREATE OR REPLACE PACKAGE upkg_mrp
    AS
    TYPE t_dmetereolog IS TABLE OF d_metereolog%ROWTYPE
    INDEX BY BINARY_INTEGER;
    PROCEDURE usp_getdata_dmetereolog
    (p_cfundo IN d_metereolog.cod_fundo%TYPE,
    p_fecha IN VARCHAR2,
    p_dmetereolog OUT t_dmetereolog);
    END;
    /*============================================*/
    CREATE OR REPLACE PACKAGE BODY upkg_mrp
    AS
    PROCEDURE usp_getdata_dmetereolog
    (p_cfundo IN d_metereolog.cod_fundo%TYPE,
    p_fecha IN VARCHAR2,
    p_dmetereolog OUT t_dmetereolog);
    IS
    CURSOR aux_cur IS
    SELECT cod_fundo,fecha,temp_max,
    temp_min,porc_humedad,
    evaporacion,prec_pluvial,
    velvient_max,velvient_min,
    usuario,TO_CHAR(fech_act,'DD/MM/YYYY HH24:MI:SS'),
    fech_act ,estado
    FROM d_metereolog
    WHERE
    cod_fundo=p_cfundo AND
    fecha =TO_DATE(p_fecha,'DD/MM/YYYY');
    BEGIN
    FOR dyn_cur IN aux_cur
    LOOP
    p_dmetereolog(1).cod_fundo:=dyn_cur.cod_fundo;
    p_dmetereolog(1).fecha:=dyn_cur.fecha;
    p_dmetereolog(1).temp_max:=dyn_cur.temp_max;
    p_dmetereolog(1).temp_min:=dyn_cur.temp_min;
    p_dmetereolog(1).porc_humedad:=dyn_cur.porc_humedad;
    p_dmetereolog(1).evaporacion:=dyn_cur.evaporacion;
    p_dmetereolog(1).prec_pluvial:=dyn_cur.prec_pluvial;
    p_dmetereolog(1).velvient_max:=dyn_cur.velvient_max;
    p_dmetereolog(1).velvient_min:=dyn_cur.velvient_min;
    p_dmetereolog(1).usuario:=dyn_cur.usuario;
    p_dmetereolog(1).fech_act:=dyn_cur.fech_act;
    p_estado(1):=dyn_cur.estado;
    END LOOP;
    END usp_getdata_dmetereolog;
    END upkg_mrp;
    Show me my flaws please. How can I optimize this sp

  • Optimization of procedure to increase performance

    Hi All,
    One of the screens in one of the application is facing performance issues. we having a procedure that is being called to load this screen. This procedure uses a dynamic query which loads the screen based on the user role and his associated SBE’s. This screen works normal if it satisfies certain conditions like user has DOT role and it is extremely slow if user has SBE leader role and does not have DOT role. Can any one let me know that how to optimize this so as to load the screen become faster on all conditions?
    Kindly help me out as i am very new to this.
    Thanks & Regards
    Raj

    Not really much anyone not familiar with your application can say to help you based on the level of information you've provided.
    It could be you have a simple performance issue, it could be that the entire application needs to be rewritten to make it perform reasonably.
    Likely the best approach would be to do a trace (SQL TRACE / TKPROF or AWR / Statspack) of the application when it runs in 'not acceptable performing mode' and see where the time is spent. If you're not familiar with what i've mentioned, find someone in your organization who can mentor you in these things, if none exist, there's a plethora of information available on the internet and in the Oracle documentation.
    From there you'll at least have a better-er idea of where the performance issues are.
    Hope that helps.

  • Optimization Help ?? Pl/sql procedure

    Hi people,
    I have 2 procedure and they are taking forever to complete.
    I need your help in optimizing those procedures to finish my task.
    My task is data migration. I am using Oracle 11g , DQL Dev 3.0
    I have to migrate about 2 million records.
    I would like to know why my procedure is taking a long time when it comes to insertion.
    My current code inserts about 300 records every 10 minutes.
    Could it be my Cases statements ??
    if it is, what would be a better solution ??
    Note: The code is working, however its slow. I need it to be faster.
    Thanks in advance for your help.
    here are some data just to understand what is the code doing:
    Please look at DOC_TYPE_CODE in procedure, maybe thats where the problem is (case statement)
    20100121085123687(SOR_DOC)-00010641.PDF
    20100121103547355(PSR_DOC)-058744_148631696.pdf
    20100121115927953(JC_DOC)-00013741.PDF
    20100122102257379(REV_DOC)-6-034848_141278871.pdf
    20100128105556824(OTHER_DOC)-2-059399_590886456.pdf
    20100203113810388(PLEA_DOC)-059019_44397339.pdfhere are the 2 procedures
    create or replace
    PROCEDURE RUN
    AS
    BEGIN
         FOR I IN (SELECT DCOLLECTIONID FROM COLMETA)
         LOOP
              DOCUMENT_INSERTION(TO_NUMBER(I.DCOLLECTIONID));
         END LOOP;
    END;
    create or replace
    PROCEDURE DOCUMENT_INSERTION(XCOL_ID NUMBER) AS
    COUNT_NUM NUMBER := 0;
    BEGIN
         -- GET THE COUNT
         SELECT      COUNT(*)
         INTO      COUNT_NUM
         FROM      DOCMETA D,
                   CASES_DOCUMENTS DOC,
                   COLLECTIONS C
         WHERE     D.XCOLLECTIONID = XCOL_ID
         AND      DOC.DID = D.DID
         AND      C.DCOLLECTIONID = D.XCOLLECTIONID
         AND      D.XFOLDERNAME = C.DCOLLECTIONNAME
         AND      DOC.DISPRIMARY = 1;
         -- START THE INSERTION PROCESS
         INSERT INTO DOCUMENTS
         SELECT
              DM.DID AS DID,
              C.DCOLLECTIONID AS SUBMISSION_ID,
              CASE
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'PSR' THEN 10
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'JC' THEN 20
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'SOR' THEN 30
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'PLEA' THEN 40
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'INDICT' THEN 50
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'OTHER' THEN 80
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'AMEND' THEN 80
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                         INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'REV' THEN 80
                   WHEN COUNT_NUM = 1 THEN 150   /* CODE FOR MAIN IS 150 */
                   ELSE 160       /* CODE FOR UNKNOWN IS 160 */
              END AS DOC_TYPE_CODE,
              NULL AS BFILEDATA,
              CASE
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                       INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'AMEND' THEN 'OTHER'
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                       INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) = 'REV' THEN 'OTHER'
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                       INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) IS NULL
                         AND COUNT_NUM = 1 THEN 'MAIN'
                   WHEN SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                       INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1) IS NULL
                         AND COUNT_NUM > 1 THEN 'UNKNOWN'
                   ELSE SUBSTR(D.DORIGINALNAME, INSTR(D.DORIGINALNAME,'(') + 1,
                       INSTR(D.DORIGINALNAME,'_DOC') - INSTR(D.DORIGINALNAME,'(') - 1)
              END AS DOC_NAME,
              D.DFORMAT AS MIME_TYPE
    FROM      CASES_DOCUMENTS D,
              DOCMETA DM,
              COLMETA C
    WHERE     DM.XCOLLECTIONID = XCOL_ID
    AND      DM.XCOLLECTIONID = C.DCOLLECTIONID
    AND      D.DID = DM.DID
    AND      D.DISPRIMARY = 1;
    COMMIT;     /* Committing the record */
    END;

    Thanks everyone for the help.
    here is the DDL
    CREATE TABLE "CASES_DOCUMENTS"
        "DDOCID"        NUMBER(38,0) NOT NULL ENABLE,
        "DID"           NUMBER(38,0),
        "DISPRIMARY"    NUMBER(1,0) NOT NULL ENABLE,
        "DORIGINALNAME" VARCHAR2(255 CHAR),
        "DFORMAT"       VARCHAR2(80 CHAR),
        "DFILESIZE"     NUMBER(38,0)
      CREATE TABLE "DOCMETA"
        "DID"                   NUMBER(38,0) NOT NULL ENABLE,
        "XCOLLECTIONID"         NUMBER(38,0),
        "XUSSCID"              VARCHAR2(30 CHAR),
        "XSUBMISSIONID"        VARCHAR2(30 CHAR),
        "XMISSINGCASE"         VARCHAR2(30 CHAR),
         "XFOLDERNAME"          VARCHAR2(200 CHAR),
        "XDEFTYPE"       VARCHAR2(30 CHAR),
        CONSTRAINT "PK_DOCMETA" PRIMARY KEY ("DID")
      CREATE TABLE "COLMETA"
        "DCOLLECTIONID"         NUMBER(38,0) NOT NULL ENABLE,
        "XUSSCID"              VARCHAR2(30 CHAR),
        CONSTRAINT "PK_COLLECTIONMETA" PRIMARY KEY ("DCOLLECTIONID")
      CREATE TABLE "COLLECTIONS"
        "DCOLLECTIONID"       NUMBER(38,0) NOT NULL ENABLE,
        "DCOLLECTIONGUID"     VARCHAR2(36 CHAR) NOT NULL ENABLE,
         "DPARENTCOLLECTIONID" NUMBER(38,0),
        CONSTRAINT "PK_COLLECTIONID" PRIMARY KEY ("DCOLLECTIONID")
        CONSTRAINT "UK_COLLECTIONNAMES" UNIQUE ("DCOLLECTIONNAME", "DPARENTCOLLECTIONID")
    /* insert statements */
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (271787,135894,1,'20100121085123687(SOR_DOC)-00010641.PDF','Application/pdf',202115);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (271823,135912,1,'20100121103547355(PSR_DOC)-058744_148631696.pdf','Application/pdf',1118423);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (271861,135931,1,'20100121110415669(SOR_DOC)-058011_58041316.pdf','Application/pdf',219272);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (271937,135969,1,'20100121115927953(JC_DOC)-00013741.PDF','Application/pdf',259548);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (272051,136026,1,'20100122102257379(REV_DOC)-6-034848_141278871.pdf','Application/pdf',230619);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (272087,136044,1,'20100125111357271(JC_DOC)-00011510.PDF','Application/pdf',102264);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (272159,136080,1,'20100126112526792(SOR_DOC)-1-00013020.PDF','Application/pdf',244530);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (272235,136118,1,'20100126182111728(PSR_DOC)-059335_498074466.pdf','Application/pdf',963139);
    Insert into "cases_documents" (DDOCID,DID,DISPRIMARY,DORIGINALNAME,DFORMAT,DFILESIZE) values (272275,136138,1,'20100127115025011(REV_DOC)-1-00006915.PDF','Application/pdf',649596);
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (135894,798044066,'1303497','416738','false','124341_20100121085123687','10');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (135912,798044069,'1302059','416812','false','124341_20100121103547355','10');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (135931,798044072,'1300935','416834','false','124341_20100121110415669','10');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (135969,798044079,'1301693','416897','false','124341_20100121115927953','10');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (136026,798044088,null,'417263','false','124341_20100122102257379','12');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (136044,798044092,'901763','417720','false','124341_20100125111357271','12');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (136080,798044099,'1214058','418182','false','124341_20100126112526792','11');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (136118,798044105,'1304859','418444','false','124341_20100126182111728','10');
    Insert into "docmeta" (DID,XCOLLECTIONID,XUSSCID,XSUBMISSIONID,XMISSINGCASE,XFOLDERNAME,XDEFTYPE) values (1361380,798451924,'1273153','386886','false','124152_20090930102348552','10');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044066,'1303497');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044069,'1302059');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044072,'1300935');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044079,'1301693');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044088,null);
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044092,'901763');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044099,'1214058');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798044105,'1304859');
    Insert into "colmeta" (DCOLLECTIONID,XUSSCID) values (798451924,'1273153');
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044066,'89532951-9E1A-1EAF-D74C-F317AD2A4880',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044069,'0533F5D5-5C70-6661-EF54-74F2B78F342C',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044072,'58A26BB4-3BE9-28C8-8A83-1DAD6FDBAD4D',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044079,'61471A50-1711-DA1B-90C9-9BE7EE4A1A1A',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044088,'412F77D8-9784-AE91-7B28-F469B852C70D',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044092,'E161DDD6-A297-A514-2BCA-C4E43415C3A6',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044099,'6CB6366A-83B1-ADD3-2F86-75C13401C866',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798044105,'46556A82-E55A-DD4E-7D21-D39C9DC365AB',798044005);
    Insert into "collections" (DCOLLECTIONID,DCOLLECTIONGUID,DPARENTCOLLECTIONID) values (798451924,'C959D755-E792-6C32-A804-0F9DE9FDAC21',798451840);
    Note: xcollectionid in docmeta = dcollectionid in colmeta

  • Error while running the Oracle Text optimize index procedure (even as a dba user too)

    Hi Experts,
    I am on Oracle on 11.2.0.2  on Linux. I have implemented Oracle Text. My Oracle Text indexes are fragmented but I am getting an error while running the optimize_index error. Following is the error:
    begin
      ctx_ddl.optimize_index(idx_name=>'ACCESS_T1',optlevel=>'FULL');
    end;
    ERROR at line 1:
    ORA-20000: Oracle Text error:
    ORA-06512: at "CTXSYS.DRUE", line 160
    ORA-06512: at "CTXSYS.CTX_DDL", line 941
    ORA-06512: at line 1
    Now I tried then to run this as DBA user too and it failed the same way!
    begin
      ctx_ddl.optimize_index(idx_name=>'BVSCH1.ACCESS_T1',optlevel=>'FULL');
    end;
    ERROR at line 1:
    ORA-20000: Oracle Text error:
    ORA-06512: at "CTXSYS.DRUE", line 160
    ORA-06512: at "CTXSYS.CTX_DDL", line 941
    ORA-06512: at line 1
    Now CTXAPP role is granted to my schema and still I am getting this error. I will be thankful for the suggestions.
    Also one other important observation: We have this issue ONLY in one database and in the other two databases, I don't see any problem at all.
    I am unable to figure out what the issue is with this one database!
    Thanks,
    OrauserN

    How about check the following?
    Bug 10626728 - CTX_DDL.optimize_index "full" fails with an empty ORA-20000 since 11.2.0.2 upgrade (DOCID 10626728.8)

  • How to get multiple out parameters from a pl/sql stored procedure in ADF Jdeveloper 11g release2

    I´m trying to call from AppModuleImpl a stored procedure from my oracle DB which receives one input parameter and returns 5 out parameters. 
    I´m using jdeveloper 11g release2  ADF and I have created a java bean "ProRecallPlatesBean " with the atributes and accesors and I serialize it. just like in this article http://docs.oracle.com/cd/E24382_01/web.1112/e16182/bcadvgen.htm#sm0297
    This is my code so far:
    public ProRecallPlatesBean getCallProRecallPlates(String numPlates) {
    CallableStatement st = null;
    try {
              // 1. Define the PL/SQL block for the statement to invoke
              String stmt = "begin CTS.Pk_PreIn.proRecallPlates(?,?,?,?,?,?); end;";
              // 2. Create the CallableStatement for the PL/SQL block
              st = getDBTransaction().createCallableStatement(stmt,0);
              // 3. Register the positions and types of the OUT parameters
              st.registerOutParameter(2,Types.VARCHAR);
    st.registerOutParameter(3,Types.VARCHAR);
    st.registerOutParameter(4,Types.VARCHAR);
    st.registerOutParameter(5,Types.VARCHAR);
    st.registerOutParameter(6,Types.VARCHAR);
    // 4. Set the bind values of the IN parameters
    st.setString(1,numPlates);
    // 5. Execute the statement
    st.executeUpdate();
    // 6. Create a bean to hold the multiple return values
    ProRecallPlatesBean result = new ProRecallPlatesBean();
    // 7. Set values of properties using OUT params
    result.setSpfVal(st.getString(2));
    result.setTransportTypeVal(st.getString(3));
    result.setTransportCompanyVal(st.getString(4));
    result.setCompanyDescrVal(st.getString(5));
    result.setDGAPrint(st.getString(6));
    // 8. Return the result
    return result;
    } catch (SQLException e) {
    throw new JboException(e);
    } finally {
    if (st != null) {
    try {
    // 9. Close the JDBC CallableStatement
    st.close();
    catch (SQLException e) {}
    In Jdeveloper I went into AppModule.xml JAVA>Client Interface section and expose "getCallProRecallPlates" Then I can see "getCallProRecallPlates" in Data Controls, I drag and drop it to a JSF page, an input text component and a button are generated in order to put in there the procedure input parameter (numPlates).
    I don't know if I'm on the right track.
    When I click the button, the "result" variable is supposed to be filled with data from the stored procedure. I want each of those values to be displayed in Output text or input text adf components but I dont know how. Thank you very much in advance I´m a newbie and i'll appreciate your help!

    What version are you on?
    Works fine for me on my 11g:
    SQL> create or replace procedure testxml (clob_out out clob)
      2  is
      3     l_clob   clob;
      4     l_ctx    dbms_xmlquery.ctxhandle;
      5  begin
      6     l_ctx := dbms_xmlquery.newcontext ('select * from dual');
      7     l_clob := dbms_xmlquery.getxml (l_ctx);
      8     clob_out := l_clob;
      9     dbms_xmlquery.closecontext (l_ctx);
    10  end testxml;
    11  /
    Procedure created.
    SQL>
    SQL> variable vout clob;
    SQL>
    SQL> exec testxml (:vout)
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print vout
    VOUT
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <DUMMY>X</DUMMY>
       </ROW>
    </ROWSET>But definitely you can optimize your proc a bit: Try
    create or replace procedure testxml (clob_out in out nocopy clob)
    is
       l_ctx    dbms_xmlquery.ctxhandle;
    begin
       l_ctx := dbms_xmlquery.newcontext ('select * from dual');
       clob_out := dbms_xmlquery.getxml (l_ctx);
       dbms_xmlquery.closecontext (l_ctx);
    end testxml;
    /

  • How to download output from a PL/SQL Procedure

    Hi all
    I have set up a PL/SQL procedure that sets up the mime type etc.
    to download the output but IE keeps telling me it can't get the
    file. I think that it's something to do with the browser wanting
    to just GET the file and getting extra stuff because the mime
    header is being sent every time. Anyone managed to do this?
    Code sample follows:
    create or replace procedure x
    is
    begin
    owa_util.mime_header('application/force-download',false,null);
    htp.p('Content-Disposition: attachment;
    filename="timeline.html"');
    htp.p('Pragma: no-cache');
    htp.p('Cache-Control: no-cache');
    htp.p('Expires: Thu, 01 Jan 1970 12:00:00 GMT');
    owa_util.http_header_close;
    htp.p('<HTML>');
    htp.p('<body>');
    htp.p('Hello there man');
    htp.p('</body>');
    htp.p('</HTML>');
    end;

    What version are you on?
    Works fine for me on my 11g:
    SQL> create or replace procedure testxml (clob_out out clob)
      2  is
      3     l_clob   clob;
      4     l_ctx    dbms_xmlquery.ctxhandle;
      5  begin
      6     l_ctx := dbms_xmlquery.newcontext ('select * from dual');
      7     l_clob := dbms_xmlquery.getxml (l_ctx);
      8     clob_out := l_clob;
      9     dbms_xmlquery.closecontext (l_ctx);
    10  end testxml;
    11  /
    Procedure created.
    SQL>
    SQL> variable vout clob;
    SQL>
    SQL> exec testxml (:vout)
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print vout
    VOUT
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <DUMMY>X</DUMMY>
       </ROW>
    </ROWSET>But definitely you can optimize your proc a bit: Try
    create or replace procedure testxml (clob_out in out nocopy clob)
    is
       l_ctx    dbms_xmlquery.ctxhandle;
    begin
       l_ctx := dbms_xmlquery.newcontext ('select * from dual');
       clob_out := dbms_xmlquery.getxml (l_ctx);
       dbms_xmlquery.closecontext (l_ctx);
    end testxml;
    /

Maybe you are looking for

  • Web Service consumer using ABAP-PROXY

    Hello, I want to test Web Service consumer using ABAP-PROXY . So I do what is explain in the weblog : [http://wiki.sdn.sap.com/wiki/display/Snippets/WebServiceconsumerusingABAP-PROXY] But when I execute the programm, the message : 'No valid source co

  • Need help Setting up Multiple Static Ip , 1 for each port of the fios router

    Need help Setting up multiple Static Ip on my fios router I have been trying to figure out how to set up multiple ip in my fios router. However I kind of managed how to set up multiple static ip However the way I want it is for each port of my router

  • Attaching Invoice document in MIRO

    Hi, Our customer want to attach the Invoice scanned copy during MIRO to avoid dispute of misplacing by departments. How do we go with this? Points will be awarded. Regards

  • Confirmations in the Classic Scenario

    We are currently running SRM 4.0 and using the classic scenario to create reqs and POs in the backend system.  We want to do GR in SRM and have setup the central receiver role. Is there an ALE process that needs to be activated to see the list of POs

  • Read all projects within Project Online using web part Sharepoint

    Hello all. Can we get data of all projects from Project Online in Sharepoint Site? So far as I understand we can get data of list like this: SPWeb web = SPContext.Current.Web; SPList issueList = web.GetList("https://tenant.sharepoint.com/sites/demo/S