Pl/sql block is too slow, should  procedure a better option

Hi all,
how to tune A PL/SQL block that traverse cursors and fetch millions of records then execute inserts in different tables,
using execute immediate statement.
It's too slow and takes 10 hours to populate 40 tables having millions of records,
as i have to do some modifications in data so can not do it by CTAS,
i.e. a single sql statement.
Should i make a procedure, does it help .
Please help or suggest As i am New to PL/Sql
My code look like,
declare
cursor     cur_table1 is
     select field1,field2,field3,field4 from table1;
begin
for i in cur_table1
loop
     execute immediate 'insert into table2 (field1,field2,field3,field4) '||
'select :1,field2,field3,field4 '||
' from table1 where field3= :2'
using i.field1||'_'||to_char(sysdate,'ddmmyyyy hh12:mi:ss',i.field1;
commit;
end if;
end;
Thanks and Regards,

declare
cursor cur_projects is
     select PROJECTID, PROJECTNAME, DESCRIPTION, DELETED, DELETINGDATE, ACTIVE, ADMINONLY, READONLY, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, CREATOR, CREATED, MODIFIER, MODIFIED from projects ;
cursor cur_projectversion(p_projectid projects.projectid%TYPE) is
     select PROJECTID, PROJECTVERSIONID, PROJECTVERSIONNAME, DESCRIPTION, DELETED , DELETINGDATE, ACTIVE , ADMINONLY, READONLY, decode(EFFECTIVEDATE,null,trunc(sysdate),EFFECTIVEDATE) EFFECTIVEDATE, EXPIRATIONDATE, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, PUBLICATIONSRCPROJVERNAME, CREATOR, CREATED, MODIFIER, MODIFIED, PROFILELOADERCLASS /*, TRACKCHANGES */
     from projectversions where PROJECTID=p_projectid ;
cursor cur_objects(p_projectid projects.projectid%TYPE,p_projectversionid projectversions.projectversionid%TYPE) is
     select PROJECTID , PROJECTVERSIONID, OBJECTID , OBJECTKEY , PARENTID, KIND , NAME , TITLE , OWNER , CREATED, MODIFIER , MODIFIED , READY_TO_PUBLISH, LAST_PUBLISHED_DATE , LAST_PUBLISHER , EFFECTIVE_PUBLISHING_DATE , PUBLISHER , PUBLISHING_DATE /*, to_lob(scripttext) */ from OBJECTS where PROJECTID=p_projectid and PROJECTVERSIONID=p_projectversionid /*order by objectid */;
begin
for i in cur_projects
loop
dbms_output.put_line('PROJECTID => '||i.projectid);
dbms_output.put_line('_________________________________');
execute immediate 'insert into &TARGET_USER\.projects(locktimeout, memorysavinglevel , preloadobjects, projectid, projectname, description, deleted, deletingdate, active, adminonly, readonly, securityclass, projectcontact, defaultversion, defaultstartpage, imagepath, maxexamineerrors ) values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17) '
using i.locktimeout, i.memorysavinglevel, i.preloadobjects,i.projectid ,i.projectname , i.description , i.deleted , i.deletingdate , i.active , i.adminonly , i.readonly, i.securityclass, i.projectcontact , i.defaultversion, i.defaultstartpage , i.imagepath, i.maxexamineerrors;
for k in cur_projectversion(i.projectid)
     loop
for l in cur_objects(k.projectid,k.projectversionid)
          loop
               cnt:=cnt+1;
select count(1) into object_exists from &TARGET_USER\.objects where objectid=l.objectid and projectversionid=1 and projectid=l.projectid;
          if object_exists = 0
          then
          if l.objectid = 1 ------Book Object , objectid = 1 and parentid = 0
          then
          execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                    using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 0 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
               else
                    select count(1) into object_parentid_exists from objects where objectid=l.parentid and projectversionid=1 and projectid=l.projectid;
                    if object_parentid_exists = 0 ---Set Parentid as 1
                    then
                              cnt_parentid_1:=cnt_parentid_1+1;
                              execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                              using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 1 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
                    else
                              execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY, PARENTID, NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                              using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY,l.PARENTID,l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
                    end if;
               end if ;
     end if;
               execute immediate 'INSERT INTO &TARGET_USER\.objectversions( PROJECTID, OBJECTID, PROJECTVERSIONID ,VERSIONNAME,OBJECTVERSIONID, REVISIONID,DESCRIPTION, TITLE , OWNER, CREATED, MODIFIER, MODIFIED, READY_TO_PUBLISH , LAST_PUBLISHED_DATE, LAST_PUBLISHER, EFFECTIVEDATE, SCRIPTTEXT, REVIEWSTATUS, READONLY, PUBLISHED, DELETED ) '||
                         'SELECT PROJECTID, OBJECTID, 1, owner||:1, PROJECTVERSIONID , '''', '''', TITLE, OWNER, CREATED, MODIFIER, MODIFIED, ''N'', '''' , '''', :2 , to_lob(SCRIPTTEXT), '''', ''N'', ''N'', '''' '||
                         'FROM OBJECTS '||
                         'WHERE PROJECTID= :3 and PROJECTVERSIONID= :4 and OBJECTID= :5'
                         using '_'||TO_CHAR(k.EFFECTIVEDATE,'DDMMYYHHMISS'),k.EFFECTIVEDATE,l.projectid,l.projectversionid,l.objectid;
     end loop;
     dbms_output.put_line(cnt||' OBJECTS, OBJECTVERIONS POPULATED');
     dbms_output.put_line(cnt_parentid_1||' DUMPED UNDER BOOK FOLDER ');
     cnt_parentid_1:=0;
     cnt:=0;
............

Similar Messages

  • Pl/Sql block returning too many values

    Hi
    Below is simple pl/sql block.while excecuting this i'm getting too many values exception
    declare
    attrib QW_ACCT_ATTR%ROWTYPE;
    begin
    SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL INTO attrib FROM (SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL FROM QW_ACCT_ATTR where CUST_ACCT_ID='5158660414' AND ATTR_NM = 'SS' ORDER BY ATTR_END_DATE DESC) where rownum = 1;
    DBMS_OUTPUT.PUT_LINE('end daate is...'||attrib.ATTR_END_DATE);
    end;
    could anybody please help me how to rewrite this qwery to get only one record.
    we are not supposed to use cursors here,
    thanks

    I am just changing your logic,
    declare
    attrib QW_ACCT_ATTR%ROWTYPE;
    begin
    SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL INTO attrib FROM (SELECT ATTR_END_DATE, ATTR_NM, ATTR_VAL FROM QW_ACCT_ATTR where CUST_ACCT_ID='5158660414' AND ATTR_NM = 'SS' ORDER BY ATTR_END_DATE DESC where rownum = 1) ;
    DBMS_OUTPUT.PUT_LINE('end daate is...'||attrib.ATTR_END_DATE);
    end;

  • PL/SQL Loop is too slow??

    Hi all,
    I have a basic loop (LOOP..END LOOP) for reading a very large varchar2 variable. In this Loop i always read 1 caracter for header (size in bytes) and the amount of data. Why this loop processing is too slow??? Can i boost it with something?
    Thanx.

    Function to read data on a socket
    Always read 1 byte for length, and with this length,
    body of message.
    FUNCTION PEGA_MESG (io_Conex_Env IN OUT Utl_Tcp.connection)
    RETURN LONG RAW
    IS
    v_Buffer LONG RAW;
    v_Mesg LONG RAW;
    v_intResp INTEGER;
    v_intBytes INTEGER;
    v_qtde_bytes integer;
    BEGIN
    v_Mesg := NULL;
    LOOP
    v_intResp := utl_tcp.read_raw(io_Conex_Env, v_Buffer, 1);
    v_qtde_bytes := ascii(utl_raw.cast_to_varchar2(v_Buffer));
    v_intResp := utl_tcp.read_raw(io_Conex_Env, v_Mesg, v_qtde_bytes);
    EXIT WHEN v_Mesg is not null;
    END LOOP;
    RETURN(v_Mesg);
    END;
    This is a little peace of my prog. If i send a lot of data, my prog get too slow.
    loop
    v_Mesg := Pega_Mesg(io_conexao);
    if ( v_Mesg = utl_raw.cast_to_raw('sum')) then
    v_Mesg := Pega_Mesg(io_conexao);
    l_Dados.DELETE;
    while v_Mesg <> utl_raw.cast_to_raw('fimsum') loop
    for sumario in 1..4 loop -- Loop para quantidade de campos na tabela saida_sumario
    l_Dados(sumario) :=Long postings are being truncated to ~1 kB at this time.

  • SQL Developer 2.1 working too slow

    Hi All,
    I am working on SQL Developer 2.1 after 3 years previously I used version 1.2. Comparatively so many changes came in 2.1 version but it is too slow and while debugging variable values not shows in Tooltip we need to depend on Smartdata tab. If any settings or patches available for following problem than please provide me.
    1.     Too slow
    2.     Variable values in Tooltip
    By
    Srinivas M. P.

    SQL Developer using 127232 KB, Free 1.32 GB
    Is there any setting is SQL Developer or you talking about my system memory.
    If you talking about my system memory than I am using 2 GB RAM in my system and system working well
    If I do anything in TOAD than TOAD is working fine but SQL Developer working too slow.
    Edited by: SrinivasMP on Feb 5, 2010 3:34 PM

  • Use Chains, or PL/SQL Block of calls.

    I currently have a half dozen cron jobs that kick off different batches of processing. Originally, these were generally a sequence of C programs that did different operations (fetch student info from student record system and load into IdM system, process directory changes, etc). Over the years, most of the program logic has been rewritten as PL/SQL packages and the cron jobs basically drop into SQL*PLUS and do things like:
    prompt "Do Spbpers delta"
    execute simon.employee_maint.Spbpers_Delta;
    commit;
    prompt "Do People.Update_From_Employees"
    execute simon.People_Maint.Update_From_Employees;
    commit;
    prompt "Do SGBSTDN_Full"
    execute Simon.Bstudent_Maint.Sgbstdn_Full;
    commit;
    prompt "Do SPRIDEN_Full (Student)"
    execute Simon.Bstudent_Maint.Spriden_Full;
    These procedures generally connect to other Oracle databases and get or push data around, and are hitting a number of different databases. The biggest of these scripts has 45 execute statements in it. (This script started in 1992.....)
    Anyway, we are getting some issues with and it is time to clean things up. This is my first foray into Scheduler and I am hoping to get some philosophical guidance on how best I should restructure things. One obvious thing, is to break up the big script into a couple of smaller ones. In some cases, order matters and in other, it doesn't - although I would prefer not to have several jobs hitting the admin system at the same time.
    I have been playing a bit with the scheduler, mostly via the EM web interface, and have come up with a few questions - some pretty specific, others more stylistic.
    1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
    2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
    3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
    4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
    The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....

    Hi,
    I can try to answer some of these questions
    1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
    False. The EM interface does have this restriction, but if you use dbms_scheduler directly there is no such restrisction. Even in the EM interface you can workaround this by using a PL/SQL block which calls the package procedure (although argument handling is a little less flexible this way).
    2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
    The answer to this depends on what you are doing. If the 5 steps run serially one after the other, using one pl/sql block may be easier. If you want some pieces to run in parallel, then creating a simple chain is better. A bit more effort spent setting up the chain will result in much faster execution times if you can run pieces in parallel.
    3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
    This has come up on the forum a few times and there are basically two different approaches. One is to use dbms_lock to ensure that only one runs at a time. This is the easiest way and the way that I recommend.
    The other way is to set up a job class with a resource consumer group and put into effect a resource consumer plan that specifies that only one session from that resource consumer group can run at a time. This is easily extensible to cases where you want 2 or more running at a time from a certain job class (which dbms_lock doesn't support).
    Code on how to set this up and more discussion is located here
    Run Jobs One After Another
    4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
    Jobs and programs can be disabled. But if a job or chain tries to run a disabled program it will result in a failure (though it will be retried if you say that the job can be restarted).
    [ 5) ] The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....
    The Scheduler was intended to accommodate a wide range of usage from simple one-off background tasks to complex sequences of interrelated tasks. As with any other software development you should use it in the simplest way possible that does what you need it to do.
    Hope this helps. Feel free to post any further questions.
    -Ravi

  • Calling sql script from pl/sql block

    Hi
    I want to call a sql script from pl/sql block.
    like
    CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
    as
    begin
    execute immediate  '@ C:\Documents and Settings\umesh\emp.sql';
    end DataBaseExport;
    /

    Try something like this -
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host
         public static void executeCommand(String command)
         try {
                String[] finalCommand;
                   if (isWindows())
                        finalCommand = new String[4];
                        // Use the appropriate path for your windows version.
                        finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
                        //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
                        finalCommand[1] = "/y";
                        finalCommand[2] = "/c";
                        finalCommand[3] = command;
                   else
                        finalCommand = new String[3];
                        finalCommand[0] = "/bin/sh";
                        finalCommand[1] = "-c";
                        finalCommand[2] = command;
              final Process pr = Runtime.getRuntime().exec(finalCommand);
             pr.waitFor();
             new Thread(new Runnable()
                public void run()
                      BufferedReader br_in = null;
                   try
                        br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                        String buff = null;
                        while ((buff = br_in.readLine()) != null)
                                  System.out.println("Process out :" + buff);
                               try {Thread.sleep(100); } catch(Exception e) {}
                        br_in.close();
                   catch (IOException ioe)
                        System.out.println("Exception caught printing process output.");
                        ioe.printStackTrace();
                 finally
                     try {
                              br_in.close();
                          } catch (Exception ex) {}
         ).start();
         new Thread(new Runnable()
           public void run()
                BufferedReader br_err = null;
                try
                   br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                   String buff = null;
                   while ((buff = br_err.readLine()) != null)
                        System.out.println("Process err :" + buff);
                        try
                           Thread.sleep(100);
                         } catch(Exception e) {}
                   br_err.close();
               catch (IOException ioe)
                   System.out.println("Exception caught printing process error.");
                   ioe.printStackTrace();
              finally
                  try
                          br_err.close();
                   catch (Exception ex) {}
          ).start();
         catch (Exception ex)
                  System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows()
              if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
              return true;
              else
              return false;
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    --- THE PERMISSIONS ---
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
    create or replace procedure call_sql_file(usr  in varchar2,
                                              pwd  in varchar2,
                                              host_str in varchar2)
    is
    begin
       host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
    exception
      when others then
        dbms_output.put_line(sqlerrm);
    end;Now, you can pass all the argument in order to execute that file.
    N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Dynamic sql and block based on a stored procedure

    Hi!
    I'm triying to generate a block based on a stored procedure. I want the stored procedure to execute a dynamic sql, but I'm having getting the error "PLS-00455 cursor 'AULOCASLATE' cannot be used in dynamic SQL OPEN statement".
    I have the following code:
    CREATE OR REPLACE package pkg_f0015 is
    type rClieInstSlate is record
    (clie_id CMS_CLIENTS.ID%type
    ,client_nm varchar2(1000)
    ,cs_no CMS_CLIENTS.CS_NO%type
    ,dob CMS_CLIENT_NAMES.BIRTH_DT%type);
    type tClieInstSlate is table of rClieInstSlate;
    type uClieInstSlate is ref cursor return rClieInstSlate;
    procedure prLocationSlateQry(
    auLocaSlate in out uClieInstSlate,                anCsNo in CMS_CLIENTS.CS_NO%type,
    avClieNm in varchar2,
    avSearchType in varchar2,
    avLotyCd in CMS_LOCATION_TYPES.CD%type);
    end pkg_f0015;
    CREATE OR REPLACE PACKAGE BODY pkg_cms_f0015 is
    procedure PRLocationSlateQry( auLocaSlate in out uClieInstSlate,
    anCsNo in CMS_CLIENTS.CS_NO%type,
    avClieNm in varchar2,
    avSearchType in varchar2,
    avLotyCd in CMS_LOCATION_TYPES.CD%type) IS
    vSelect varchar2(5000);
    vAddCond varchar2(1000);
    vSupLevel varchar2(50);
    begin
    vSelect := 'select clie.ID,'||
    ' CLIENT_NAME,'||
    ' clie.CS_NO,'||
    ' clna.BIRTH_DT dob'
    ' from CMS_CLIENT_NAMES clna,'||
    'CMS_CLIENTS clie'||
    ' where clna.CLIE_ID = clie.ID';
    if avSearchType= 'C' then
    vAddCond := ' and clie.CS_NO = nvl('||anCsNo||',clie.CS_NO)';
    vSelect := vSelect || vAddCond;
    open auLocaSlate for vSelect;
    end if;
    end PRLocationSlateQry;
    end;
    I wonder if what I want is possible

    OK,
    Now it works. Previously we had the parameter p_guid declared as RAW, which obviously is not any good. :)
    Radovan
    Edited by: biciste on Apr 28, 2009 4:57 PM

  • Performance is too slow on SQL Azure box

    Hi,
    Performance is too slow on SQL Azure box (Located in Europe)
    Below query returns 500,000 rows in 18 Min. on SQL Azure box (connected via SSMS, located in India)
    SELECT * FROM TABLE_1
    Whereas, on local server it returns 500,000 rows in (30 sec.)
    SQL Azure configuration:
    Service Tier/Performance Level : Premium/P1
    DTU       : 100
    MAX DB Size : 500GB     
    Max Worker Threads : 200          
    Max Sessions     : 2400
    Benchmark Transaction Rate      : 105 transactions per second
    Predictability : Best
    Any suggestion would be highly appreciated.
    Thanks,

    Hello,
    Can you please explain in a little more detail the scenario you testing? Are you comparing a SQL Database in Europe against a SQL Database in India? Or a SQL Database with a local, on-premise SQL Server installation?
    In case of the first scenario, the roundtrip latency for the connection to the datacenter might play a role. 
    If you are comparing to a local installation, please note that you might be running against completely different hardware specifications and without network delay, resulting in very different results.
    In both cases you can use the below blog post to assess the resource utilization of the SQL Database during the operation:
    http://azure.microsoft.com/blog/2014/09/11/azure-sql-database-introduces-new-near-real-time-performance-metrics/
    If the DB utilizes up to 100% you might have to consider to upgrade to a higher performance level to achieve the throughput you are looking for.
    Thanks,
    Jan 

  • I have downloades Logic Pro 9 onto my older modfel Mac Book Pro 1,1 with OS 10.6.8 and 2 GB RAM, according to the rquirements for Logic 9. the program should run, but it won't open. Is my configutation too slow?

    I have downloades Logic Pro 9 onto my older modfel Mac Book Pro 1,1 with OS 10.6.8 and 2 GB RAM, according to the rquirements for Logic 9. the program should run on OS 10.6.8. with 2 GB RAM, 4 GB better, but it won't open. Is my configutation too slow?

    Looks as if you're just at the minimum specs - http://www.apple.com/logicpro/specs/. Says 2GB minimum, 4GB recommended. And 2GB of RAM is all the RAM the 1,1 can handle. If I were you I would call Apple's App Store service center - you have the minimum requirements, as I read it, but perhaps you need a faster processor?
    I had a 1,1 but sold it when I bought my late 2011 in March of this year - maybe it's time to look at a new machine?
    Clinton

  • First execution of pl/sql block is slow.

    Hi,
    I've introduced TimesTen to improve performance of a pl/sql block in Oracle.
    For that I created certain cachegroups in TimesTen to cache the oracle data.
    After everything is done on TimesTen, when we run the pl/sql block on TimesTen, I observed that it is taking 35 Seconds ( against 48 secs on Oracle) for first time execution on Timesten.  Subsequent execution of same pl/sql block with same parameters are taking just 6 seconds. I want to achieve the same throughput ( 6 sec) when the pl/sql block is executed for the first time. Can you please suggest what exactly I should look into.
    Thanks
    Amit

    Thanks you so much Chris for your response.
    Please find the requested info here:
    1=>
    C:\TimesTen\tt1122_64\bin>ttversion
    TimesTen Release 11.2.2.5.0 (64 bit NT) (tt1122_64:53396) 2013-05-23T16:26:12Z
      Instance admin: shuklaam
      Instance home directory: C:\TimesTen\TT1122~1\
      Group owner: ES\Domain Users
      Daemon home directory: C:\TimesTen\TT1122~1\srv\info
      PL/SQL enabled.
    2, 3=>Complete DSN definition and CG definitions is available in the  doc here https://docs.google.com/file/d/0BxQyEfoOqCkDWVZmSG90NUd5bGM/edit?usp=sharing
    4=>I can't share the source code due to my company policies, but I'm explaining here what exactly it is doing.
    1. Based on the parameters to the proc, build a cursor, and fetch records from various tables.
    2. insert them into pl/sql tables.
    3. Do some calculations on those records, & calculate certain amounts.
    4. Insert these values into a temporary table, and display to the UI.
    At the same time, I found a metalink note 1272819.1 which stats this is a known phenomena. Not sure if setting DSN attribute MemoryLock=4 will resolve the issue.
    Also, I couldn't find this attribute in windows DSN definition any where. Can you please point me where exactly I need to set it.
    Thanks
    Amit

  • Stored Procedure Vs PL-SQL Block

    Hi,
    I came across an interesting problem last week. Fortunately, I was able to solve it or find an acceptable workaround for myself. But wanted to get some clarification from the experts. So posting it here.
    Also, I am new to Orcle, so please excuse any shortcomings in the post.
    My data model has following tables-
    TABLE_PARENT (ID, other columns)
    TABLE_CHILD (ID, other columns, PARENT_ID_FK)
    Here, ID is the primary key column for the respective tables; PARENT_ID_FK is the foreign key referencing the ID column from the TABLE_PARENT.
    I created a stored procedure programmatically (using MS Excel) to insert records in the two tables. The stored procedure has insert statements for an indefinite number of records in the parent table and for every such record, there's a corresponding record inserted in the child table. Here's the sample code.
    BEGIN
    /*first record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*second record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*third record*/
    parent_id := MY_SEQUENCE_GENERATOR.NEXTVAL;
    INSERT INTO TABLE_PARENT(ID, other columns) VALUES (parent_id, other values);
    INSERT INTO TABLE_CHILD(ID, other values,parent_id );
    /*and so on*/
    END
    When I run this stored procedure, I keep getting following exception intermittently-
    ORA-02291: integrity constraint violated-parent key not found tips.
    My thinking is that it comes because the insert statements are executing ahead of turn of the parent_id assignment statement. And this is happening possibly because of some parallelism that is taking place during the execution of the stored procedure, or, some sort of optmization that the DB server does (though erroneously) when it compiles the stored procedure.
    I tried out everything that I could think of but it didn't go away. Finally, when I executed the same set of statements as a PL-SQL block, it worked fine.
    To understand it better, I am looking for clarification on the following questions.
    1) Why does the exception come with stored procedure but not with PL-SQL block? Is my reasoning given above correct (parallelism or some sort of optimization coming into play)?
    2) If it is due to parallelism, how to run a Oracle stored procedure with defree of prallelism set to 1?
    3) If it is due to optimization done by the compiler, how to instruct the compiler to not do any such optimization. Also, in any case, isn't it an error to optimize but lose program semantics?
    4) Another question related to the same piece of work I have is to use transactions in the PL-SQL block, I had to explicitly COMMIT/ROLLBACK it in the code. In whatever references I had read, it was said that by default the transaction begins with BEGIN statement and commits with END. Also, it seems to work with a Stored Proedure though. So is it that a PL_SQL block needs explicity call to COMMIT/ROLLBACK to achive transactions but stored procedures do not?
    Any inputs/clarifications will be much appreciated.
    Thank you
    Neelesh

    Ok, your last couple of paragraphs were helpful. Here're the details that were missing in my earlier post.
    - I am on Oracle 10.2.0.
    - Table definitions-
    CREATE TABLE "MYUSER"."TABLE_PARENT"
    *(     "ID" NUMBER(19,0) NOT NULL ENABLE,*
    *     "NAME" VARCHAR2(30),*
    *     "DESCRIPTION" VARCHAR2(80),*
    *     "RULETYPE" NUMBER(10,0) NOT NULL ENABLE,*
    *     "OPERATOR" NUMBER(10,0),*
    *     "MININTERCEPT" FLOAT(126),*
    *     "PRIORITY" NUMBER(10,0),*
    *     "PENALTY" NUMBER(10,0),*
    *     "STATUS" NUMBER(10,0),*
    *     PRIMARY KEY ("ID")*
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"  ENABLE,
    *) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    CREATE TABLE "MYUSER"."TABLE_CHILD"
    *(     "ID" NUMBER(19,0) NOT NULL ENABLE,*
    *     "WEIGHT" NUMBER(19,0),*
    *     "PARENTID_FK" NUMBER(19,0),*
    *     PRIMARY KEY ("ID")*
    USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"  ENABLE,
    *     CONSTRAINT "FK3A78BF1E6A9DCE51" FOREIGN KEY ("PARENTID_FK")*
    *     REFERENCES "MYUSER"."TABLE_PARENT" ("ID") ENABLE*
    *) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING*
    STORAGE(INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    TABLESPACE "USERS"
    - The Stored procedure definition is-
    CREATE OR REPLACE PROCEDURE LOAD_RULES_SP AS
    ruleid NUMBER(19,0);
    tempid NUMBER(19,0);
    BEGIN
    */* First parent record */*
    SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
    INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
    */* Corresponding child records */*
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.2, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.5, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.3, ruleid);
    */* First parent record */*
    SELECT IDGENERATOR.NEXTVAL INTO ruleid FROM dual;
    INSERT INTO TABLE_PARENT (ID, NAME, DESCRIPTION, RULETYPE, OPERATOR, MININTERCEPT, PRIORITY, penalty, STATUS) VALUES (ruleid, 'Rule 1',null,3,0,0,null,null,1);
    */* Corresponding child records */*
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.2, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.5, ruleid);
    SELECT IDGENERATOR.NEXTVAL INTO tempid FROM dual;
    INSERT INTO TABLE_CHILD (id, weight, PARENTID_FK)
    VALUES (tempid, 0.3, ruleid);
    */* And so on for a few parent records more */*
    END;
    Can you throw some light on the exception I was seeing now? Note that when I changed from stored procedure to an anonymous block, it worked fine.
    One correction in my earlier post is that as the code snippet shows, there are multiple inserts in the child table for every record inserted in the parent one.

  • Help! macBook is too slow, haven't updated in months, rehilete always appears? What should I do?

    HELP! My MacBookPro is too slow, rehilete always appears, haven't Updated in months, is that the problem? What should I do?

    MaryKarmen wrote:
    HELP! My MacBookPro is too slow, rehilete always appears, haven't Updated in months, is that the problem? What should I do?
    Can you explain what  "rehilete always appears" means?

  • PL/SQL Block working fine but same code procedure is giving error.

    Hi Experts,
    I am executing  procedure getting error ORA-27486: insufficient privileges
    If It's PL/SQL block it's creating job classes.
    Both the cases same user.
    CREATE OR REPLACE PROCEDURE JOB_CLASS_PROC
    AS
       V_SQL   VARCHAR2 (4000);
       V_JOB_STEP VARCHAR2 (50);
    BEGIN
    -- Create Job Class if not exist
       BEGIN
       FOR i
          IN (SELECT SNS.OWNER_NAME OWNER_NAME,
                     VDB.NAME
                        SNAME
                FROM SCHEMA_NAMES SNS,
                     V$DATABASE VDB
               WHERE OWNER_NAME NOT IN ('')
                AND (OWNER_NAME || '_JOB_CLASS')
                     NOT IN
                    (SELECT JOB_CLASS_NAME FROM DBA_SCHEDULER_JOB_CLASSES))
       LOOP
          V_SQL :=
                'BEGIN
                  DBMS_SCHEDULER.CREATE_JOB_CLASS
                   job_class_name => ''' || i.owner_name || '_JOB_CLASS'',
                   service           => ''' || i.SNAME || ''',
                   comments       => ''Job class for ' || i.owner_name || '''
                EXCEPTION
                 WHEN OTHERS THEN
                  RAISE;                 
                END;';
          EXECUTE IMMEDIATE V_SQL;
       END LOOP;
    END;
    EXCEPTION
       WHEN OTHERS
       THEN
       RAISE_APPLICATION_ERROR(-20001, V_JOB_STEP||' SQLERRM: ' || SQLERRM || ' SQLCODE: '|| SQLCODE);
    END JOB_CLASS_PROC;
    DECLARE
       V_SQL   VARCHAR2 (4000);
       V_JOB_STEP VARCHAR2 (50);
    BEGIN
    -- Create Job Class if not exist
       BEGIN
       FOR i
          IN (SELECT SNS.OWNER_NAME OWNER_NAME,
                     VDB.NAME
                        SNAME
                FROM SCHEMA_NAMES SNS,
                     V$DATABASE VDB
               WHERE OWNER_NAME NOT IN ('')
                AND (OWNER_NAME || '_JOB_CLASS')
                     NOT IN
                    (SELECT JOB_CLASS_NAME FROM DBA_SCHEDULER_JOB_CLASSES))
       LOOP
          V_SQL :=
                'BEGIN
                  DBMS_SCHEDULER.CREATE_JOB_CLASS
                   job_class_name => ''' || i.owner_name || '_JOB_CLASS'',
                   service           => ''' || i.SNAME || ''',
                   comments       => ''Job class for ' || i.owner_name || '''
                EXCEPTION
                 WHEN OTHERS THEN
                  RAISE;                 
                END;';
          EXECUTE IMMEDIATE V_SQL;
       END LOOP;
    END;
    EXCEPTION
       WHEN OTHERS
       THEN
       RAISE_APPLICATION_ERROR(-20001, V_JOB_STEP||' SQLERRM: ' || SQLERRM || ' SQLCODE: '|| SQLCODE);
    END;
    Why for same code procedure is giving error.
    Please help me.
    Thanks.

    Hi,
    Then with the same grants how the below script is working.
    If I put the below same script in Procedure it's not working.
    DECLARE
       V_SQL   VARCHAR2 (4000);
       V_JOB_STEP VARCHAR2 (50);
    BEGIN
    -- Create Job Class if not exist
       BEGIN
       FOR i
          IN (SELECT SNS.OWNER_NAME OWNER_NAME,
                     VDB.NAME
                        SNAME
                FROM SCHEMA_NAMES SNS,
                     V$DATABASE VDB
               WHERE OWNER_NAME NOT IN ('')
                AND (OWNER_NAME || '_JOB_CLASS')
                     NOT IN
                    (SELECT JOB_CLASS_NAME FROM DBA_SCHEDULER_JOB_CLASSES))
       LOOP
          V_SQL :=
                'BEGIN
                  DBMS_SCHEDULER.CREATE_JOB_CLASS
                   job_class_name => ''' || i.owner_name || '_JOB_CLASS'',
                   service           => ''' || i.SNAME || ''',
                   comments       => ''Job class for ' || i.owner_name || '''
                EXCEPTION
                 WHEN OTHERS THEN
                  RAISE;               
                END;';
          EXECUTE IMMEDIATE V_SQL;
       END LOOP;
    END;
    EXCEPTION
       WHEN OTHERS
       THEN
       RAISE_APPLICATION_ERROR(-20001, V_JOB_STEP||' SQLERRM: ' || SQLERRM || ' SQLCODE: '|| SQLCODE);
    END;
    Please help me.
    Thanks.

  • Need to refresh materialized view from procedure and pl/sql block

    Hi,
    I need to refresh materialized view (complete refresh)from procedure and pl/sql block .can some one help.
    MV name:MV_DGN_TEST_SESSION
    Thanks,
    Rajasekhar

    dbms_mview.REFRESH ('MV_DGN_TEST_SESSION', 'C');Regards,
    Mahesh Kaila
    Edited by: user4211491 on Dec 1, 2009 10:41 PM

  • Performance too Slow on SQL Azure box

    Hi,
    Performance is too slow on SQL Azure box:
    Below query returns 500,000 rows in 18 Min. on SQL Azure box (connected via SSMS)
    SELECT * FROM TABLE_1
    Whereas, on local server it returns 500,000 rows in (30 sec.)
    SQL Azure configuration:
    Service Tier/Performance Level : Premium/P1
    DTU       : 100
    MAX DB Size : 500GB     
    Max Worker Threads : 200          
    Max Sessions     : 2400
    Benchmark Transaction Rate      : 105 transactions per second
    Predictability : Best
    Thanks,

    Hello,
    Please refer to the following document too:
    http://download.microsoft.com/download/D/2/0/D20E1C5F-72EA-4505-9F26-FEF9550EFD44/Performance%20Guidance%20for%20SQL%20Server%20in%20Windows%20Azure%20Virtual%20Machines.docx
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

Maybe you are looking for