Scheduled Job to gather stats for multiple tables - Oracle 11.2.0.1.0

Hi,
My Oracle DB Version is:
BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
In our application, we have users uploading files resulting in insert of records into a table. file could contain records ranging from 10000 to 1 million records.
I have written a procedure to bulk insert these records into this table using limit clause. After the insert, i noticed my queries run slow against these tables if huge files are uploaded simultaneously. After gathering stats, the cost reduces and the queries executed faster.
We have 2 such tables which grow based on user file uploads. I would like to schedule a job to gather stats during a non peak hour apart from the nightly automated oracle job for these two tables.
Is there a better way to do this?
I plan to execute the below procedure as a scheduled job using DBMS_SCHEDULER.
--Procedure
create or replace
PROCEDURE p_manual_gather_table_stats AS
TYPE ttab
IS
    TABLE OF VARCHAR2(30) INDEX BY PLS_INTEGER;
    ltab ttab;
BEGIN
    ltab(1) := 'TAB1';
    ltab(2) := 'TAB2';
    FOR i IN ltab.first .. ltab.last
    LOOP
        dbms_stats.gather_table_stats(ownname => USER, tabname => ltab(i) , estimate_percent => dbms_stats.auto_sample_size,
        method_opt => 'for all indexed columns size auto', degree =>
        dbms_stats.auto_degree ,CASCADE => TRUE );
    END LOOP;
END p_manual_gather_table_stats;
--Scheduled Job
BEGIN
    -- Job defined entirely by the CREATE JOB procedure.
    DBMS_SCHEDULER.create_job ( job_name => 'MANUAL_GATHER_TABLE_STATS',
    job_type => 'PLSQL_BLOCK',
    job_action => 'BEGIN p_manual_gather_table_stats; END;',
    start_date => SYSTIMESTAMP,
    repeat_interval => 'FREQ=DAILY; BYHOUR=12;BYMINUTE=45;BYSECOND=0',
    end_date => NULL,
    enabled => TRUE,
    comments => 'Job to manually gather stats for tables: TAB1,TAB2. Runs at 12:45 Daily.');
END;Thanks,
Somiya

The question was, is there a better way, and you partly answered it.
Somiya, you have to be sure the queries have appropriate statistics when the queries are being run. In addition, if the queries are being run while data is being loaded, that is going to slow things down regardless, for several possible reasons, such as resource contention, inappropriate statistics, and having to maintain a read consistent view for each query.
The default collection job decides for each table based on changes it perceives in the data. You probably don't want the default collection job to deal with those tables. You probably do want to do what Dan suggested with the statistics. But it's hard to tell from your description. Is the data volume and distribution volatile? You surely want representative statistics available when each query is started. You may want to use all the plan stability features available to tell the optimizer to do the right thing (see for example http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/ ). You may want to just give up and use dynamic sampling, I don't know, entire books, blogs and papers have been written on the subject. It's sufficiently advanced technology to appear as magic.

Similar Messages

  • Job not getting triggered for Multiple Scheduler Events

    hi,
    I would like a job to be triggered for multiple scheduler events, subscribing to a single event works fine. But, when I set multiple event condition, nothing works.
    My objective is to run a job, whenever job starts or restarts or exceeds max run duration.
    Note : Is it possible to trigger a job, when a job RESTARTS by subscribing to JOB_START ????????
    procedure sniffer_proc(p_message in sys.scheduler$_event_info)
    is
    --Code
    end sniffer_proc
    dbms_scheduler.create_program(program_name => 'PROG',
    program_action => 'sniffer_proc',
    program_type => 'stored_procedure',
    number_of_arguments => 1,
    enabled => false);
    -- Define the meta data on scheduler event to be passed.
    dbms_scheduler.define_metadata_argument('PROG',
    'event_message',1);
    dbms_scheduler.enable('PROG');
    dbms_scheduler.create_job
    ('JOB',
    program_name => 'PROG',
    * event_condition => 'tab.user_data.event_type = ''JOB_OVER_MAX_DUR''' ||*
    *' or tab.user_data.event_type = ''JOB_START''',*
    queue_spec => 'sys.scheduler$_event_queue,auagent',
    enabled => true);
    I tried this too...
    dbms_scheduler.create_job
    ('JOB',
    program_name => 'PROG',
    * event_condition => 'tab.user_data.event_type = ''JOB_OVER_MAX_DUR''' ||*
    *' and tab.user_data.event_type = ''JOB_START''',*
    queue_spec => 'sys.scheduler$_event_queue,auagent',
    enabled => true);
    Need help
    Thanks...
    Edited by: user602200 on Dec 28, 2009 3:00 AM
    Edited by: user602200 on Dec 28, 2009 3:03 AM

    Hi,
    Here is complete code which I tested on 10.2.0.4 which shows a second job that runs after a first job starts and also when it has exceeded its max run duration. It doesn't have the condition but just runs on every event raised, but the job only raises the 2 events.
    Hope this helps,
    Ravi.
    -- run a job when another starts and exceeds its max_run_duration
    set pagesize 200
    -- create a user just for this test
    drop user test_user cascade;
    grant connect, create job, create session, resource,
      create table to test_user identified by test_user ;
    connect test_user/test_user
    -- create a table for output
    create table job_output (log_date timestamp with time zone,
            output varchar2(4000));
    -- add an event queue subscriber for this user's messages
    exec dbms_scheduler.add_event_queue_subscriber('myagent')
    -- create the first job and have it raise an event whenever it completes
    -- (succeeds, fails or stops)
    begin
    dbms_scheduler.create_job
       ( 'first_job', job_action =>
         'insert into job_output values(systimestamp, ''first job runs'');'||
         'commit; dbms_lock.sleep(70);',
        job_type => 'plsql_block',
        enabled => false, repeat_interval=>'freq=secondly;interval=90' ) ;
    dbms_scheduler.set_attribute ( 'first_job' , 'max_runs' , 2);
    dbms_scheduler.set_attribute
        ( 'first_job' , 'raise_events' , dbms_scheduler.job_started);
    dbms_scheduler.set_attribute ( 'first_job' , 'max_run_duration' ,
        interval '60' second);
    end;
    -- create a simple second job that runs when the first starts and after
    -- it has exceeded its max_run_duration
    begin
      dbms_scheduler.create_job('second_job',
                                job_type=>'plsql_block',
                                job_action=>
        'insert into job_output values(systimestamp, ''second job runs'');',
                                event_condition =>
       'tab.user_data.object_name = ''FIRST_JOB''',
                                queue_spec =>'sys.scheduler$_event_queue,myagent',
                                enabled=>true);
    end;
    -- this allows multiple simultaneous runs of the second job on 11g and up
    begin
      $IF DBMS_DB_VERSION.VER_LE_10 $THEN
        null;
      $ELSE
        dbms_scheduler.set_attribute('second_job', 'parallel_instances',true);
      $END
    end;
    -- enable the first job so it starts running
    exec dbms_scheduler.enable('first_job')
    -- wait until the first job has run twice
    exec dbms_lock.sleep(180)
    select * from job_output;

  • Skip gather stats for a partition | table from the gather_stats_job in 10g

    Hi all,
    Can we skip gather statistics for a table or a partition in a partitioned-table from the GATHER_STATS_JOB in Oracle 10g ?
    (cause that partition store in an offline-datafile, so GATHER_STATS_JOB had errors when running in sheduled).
    Thanks.
    Edited by: user8710247 on Nov 26, 2011 6:41 PM

    GATHER_TABLE_STATS will default to GRANULARITY 'AUTO' which will include Global and Partition Statistics. Global Statistics have to be across all the Partitions -- so Oracle will attempt to read all the partitions for this !
    You need to run GATHER_TABLE_STATS with GRANULARITY 'PARTITION' and naming the other Partitions --- i.e. run it for each of the online partitions.
    See :
    SQL> create table XYZ (col_1  number, col_2 varchar2(5))
      2  partition by range (col_1)
      3  (partition P1 values less than (10) tablespace HEMANT,
      4  partition P2 values less than (100) tablespace USERS)
      5  /
    Table created.
    SQL> insert into XYZ values (5,'Five');
    1 row created.
    SQL> insert into XYZ values (50,'Fifty');
    1 row created.
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,granularity=>'ALL');
    PL/SQL procedure successfully completed.
    SQL> select partition_name, tablespace_name , num_rows, sample_size from user_tab_partitions
      2  where table_name = 'XYZ'
      3  /
    PARTITION_NAME                 TABLESPACE_NAME                  NUM_ROWS
    SAMPLE_SIZE
    P1                             HEMANT                                  1
              1
    P2                             USERS                                   1
              1
    SQL>
    SQL> exec dbms_stats.lock_table_stats('','XYZ');
    PL/SQL procedure successfully completed.
    SQL> alter tablespace HEMANT offline;
    Tablespace altered.
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,granularity=>'ALL');
    BEGIN dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,granularity=>'ALL'); END;
    ERROR at line 1:
    ORA-20005: object statistics are locked (stattype = ALL)
    ORA-06512: at "SYS.DBMS_STATS", line 13159
    ORA-06512: at "SYS.DBMS_STATS", line 13179
    ORA-06512: at line 1
    SQL>
    SQL> exec dbms_stats.unlock_table_stats('','XYZ');
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.lock_partition_stats('','XYZ','P1');
    PL/SQL procedure successfully completed.
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,granularity=>'ALL');
    BEGIN dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,granularity=>'ALL'); END;
    ERROR at line 1:
    ORA-00376: file 2 cannot be read at this time
    ORA-01110: data file 2:
    '/usr/oracle/oradata/MONDB/datafile/o1_mf_hemant_7d6m8zkx_.dbf'
    ORA-06512: at "SYS.DBMS_STATS", line 13159
    ORA-06512: at "SYS.DBMS_STATS", line 13179
    ORA-06512: at line 1
    SQL>
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,partname=>'P2');
    BEGIN dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,partname=>'P2'); END;
    ERROR at line 1:
    ORA-00376: file 2 cannot be read at this time
    ORA-01110: data file 2:
    '/usr/oracle/oradata/MONDB/datafile/o1_mf_hemant_7d6m8zkx_.dbf'
    ORA-06512: at "SYS.DBMS_STATS", line 13159
    ORA-06512: at "SYS.DBMS_STATS", line 13179
    ORA-06512: at line 1
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,partname=>'P2',granularity=>'GLOBAL AND PARTITION');
    BEGIN dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,partname=>'P2',granularity=>'GLOBAL AND PARTITION'); END;
    ERROR at line 1:
    ORA-00376: file 2 cannot be read at this time
    ORA-01110: data file 2:
    '/usr/oracle/oradata/MONDB/datafile/o1_mf_hemant_7d6m8zkx_.dbf'
    ORA-06512: at "SYS.DBMS_STATS", line 13159
    ORA-06512: at "SYS.DBMS_STATS", line 13179
    ORA-06512: at line 1
    SQL>
    SQL> exec dbms_stats.gather_table_stats('','XYZ',estimate_percent=>100,partname=>'P2',granularity=>'PARTITION');
    PL/SQL procedure successfully completed.
    SQL>Hemant K Chitale

  • Gather stats on every table in a schema

    Hi,
    i have an CRM application running on 10g R2 db. it has 5000 tbls on which less than 10% of tables are dynamic. gather stats job runs every day at 2am successfully.
    i was monitoring the statistics(dba_tables, dba_tab_modifications, dba_tab_statistics), noticed that only 28 tables r been update with latest stats every day for CRM schema and most of these tables are same. during query tunning i found that some tables has stale stats, but it does't figure in column stale of dba_tab_statistics, but it shows no of rows inserted, updated in tab_modifications.
    my question is there any draw back in gathering stats for all the tables every day irrespective of data is loaded with 10% or not and but not for tables with no rows..

    thanks for the quick response, it was helpful.
    due to application vendor recommendations, for some tables stats were disabled and optimizer parameter were changed which causes dynamic sample not using dynamic stats gather for some queries as they use the tables with no stats. as per documentation it would be calculating the stats on fly when the query the tables which stats has not been updated.
    as of now i am not gathering stats manually for this schema, as auto is scheduled. and will verify if indeed on 10% of data is loaded it updates the stats or not then i may manually gather stats for only those tables.

  • [ADF Help] How to create a view for multiple tables

    Hi,
    I am using Jdeveloper 11G and ADF framework, and trying to create a view to update multiple tables.
    ex:
    Table A has these fields: ID, Name
    Table B has these fields: ID, Address
    A.ID and B.ID are primary keys.
    B.ID has FK relationship with A.ID
    (basically, these tables have one-to-one relation)
    I want to create a view object, which contains these fields: B.ID (or A.ID), A.Name, B.Address.
    So I can execute C,R,U,D for both tables.
    I create these tables in DB, and create entity objects for these tables.
    So there are 2 entity objects and 1 association.
    Then I create a view object based on B and add fields of A into the view:
    If the association is not a "Composition Association",
    when I run the model ("Oracle Business Component Browser") and try to insert new data, fields of A can't edit.
    If the association is a "Composition Association", and click the insert button, I will get
    "oracle.jbo.InvalidOwnerException: JBO-25030: Failed to find or invalidate owning entity"
    If I create a view object based on A and add filed of B into the view:
    When I run the model and try to insert new data, fields of B can't edit, no matter the association is or is not a composition association.
    So... how can I create a view for multiple tables correctly?
    Thanks for any advices!
    Here are some pictures about my problem, if there is any unclear point, please let me know.
    http://leonjava.blogspot.com/2009_10_01_archive.html
    (A is Prod, B is CpuSocket)
    Edited by: user8093176 on Oct 25, 2009 12:29 AM

    Hi Branislav,
    Thanks, but the result is same ....
    In the step 2 of creating view object, I can select entity objects to be added in to the view.
    If I select A first, and then select B (the "Source Usage" of B is A), then finishing the wizards.
    When I try to create a new record in the view, I can't edit any properties of B (those files are disabled).
    If I select B first, and then select A in crating view object, the result is similar ...
    Thanks for any further suggestion.
    Leon

  • Can we use single DB Adapter for multiple tables

    Hi,
    I have 3 tables. ONE is the Master table and other 2 tables having Primary and foreign key relationships with the Master Table.
    Data is enter in the Tables 2 & 3 (based on Master Table Primary key)
    I have to use a DB Adapter in BPEL Process which will be in Transaction (what type of Transaction is Best in such a Scenario).
    - How do i implement it in BPEL.
    - Can i use a Single DB Adapter for Multiple Tables ? (*Views* should not be created for tables 1, 2 & 3),
    as we want to avoid using multiple DB Adapters, as in future Tables may increase or decrease...
    - while in Transaction if Table 2 fails in Inserting / Updating, it should roll back on error and also if Table 3 fails in Inserting / Updating, it should roll back table 2 and Table 3.
    - how access to concurrent users is maintained / managed in such a scenarios.
    But everything should be done using Single DB Adapter without creating a separate view.
    Is this Possible in BPEL..
    If not, How do we design, Implementation such a BPEL Process in Transaction with a best in Performance (both BPEL Process & DB Resources)
    thanks in advance
    thanks & regards,
    anvv sharma

    Hi,
    Thanks for your quick response.
    I have few quires.
    If we use PL/SQL, how do we implement transaction and Exception Handling appropriately based on the Error / Exception in BPEL.
    If the Table 2 or Table 3 gives out Error / Exception, i have to handle it separately and intimate accordingly.
    Suppose, if Table 2 got Error / Exception - Error Handling would be 'Roll back due to error in Table2'
    Thanks & regads,

  • User Datastore for multiple tables and columns!

    Hi,
    I hop so much, someone can help me.
    I've made a user datastore to index multiple columns of multiple tables.
    Now, the Documentation of Oracle explains the idexing of one table.
    I have multiple tables, which have all, the columns descr and tagnr. I want to make a query sth like this:
    select table1.column, table2.columnd... where contains(indexed field,'gas within descr',1)>0
    is it possible to index 4 seperate tables, without having a collective key? I dont want to make a Concatenated Datastore.
    I have wrote this code.
    But it doesn't work. It's been compiled fine. But I don't get any result with my queries.
    create or replace
    procedure My_Proc_Wide
    Must be in ctxsys schema.
    In a full-scale example, this would be a wrapper
    for a proc in the user schema.
    rid in rowid,
    tlob in out NOCOPY clob /* NOCOPY instructs Oracle to pass
    this argument as fast as possible */
    is
    v_descr varchar2(80);
    v_tagnr varchar2(30);
    v_descr_name constant varchar2(20) := 'descr';
    v_descr_start_tag constant varchar2(20) := '<' || v_descr_name || '>';
    v_descr_end_tag constant varchar2(20) := '</' || v_descr_name || '>';
    v_tagnr_name constant varchar2(20) := 'tagnr';
    v_tagnr_start_tag constant varchar2(20) := '<' || v_tagnr_name || '>';
    v_tagnr_end_tag constant varchar2(20) := '</' || v_tagnr_name || '>';
    v_buffer varchar2(4000);
    v_length integer;
    begin
    /* verify the env which called this */
    if Dbms_Lob.Istemporary ( tlob ) <> 1
    then
    raise_application_error ( -20000,
    '"IN OUT" tlob isn''t temporary' );
    end if;
    /* the real logic */
    /* first tabel to be indexed */
    select t1.tagnr, t1.descr
    into v_tagnr, v_descr
    from tweb.pdp_positions t1
    where t1.rowid = rid;
    v_buffer := v_tagnr_start_tag ||
    v_tagnr ||
    v_tagnr_end_tag ||
    v_descr_start_tag ||
         v_descr ||
         v_descr_end_tag;
    v_length := length ( v_buffer );
    Dbms_Lob.WriteAppend(tlob, length(v_buffer) + 1, v_buffer || ' ');
    /* second table to be indexed */
    select t2.tagnr, t2.descr
    into v_tagnr, v_descr
    from tweb.pdp_schema_equ t2
    where t2.rowid = rid;
         v_buffer := v_tagnr_start_tag ||
    v_tagnr ||
    v_tagnr_end_tag ||
    v_descr_start_tag ||
         v_descr ||
         v_descr_end_tag;
    v_length := length ( v_buffer );
    Dbms_Lob.WriteAppend(tlob, length(v_buffer) + 1, v_buffer || ' ');
    /*third table to be indexed */
    select t3.tagnr, t3.descr
    into v_tagnr, v_descr
    from tweb.pdp_equipment t3
    where t3.rowid = rid;
         v_buffer := v_tagnr_start_tag ||
    v_tagnr ||
    v_tagnr_end_tag ||
    v_descr_start_tag ||
         v_descr ||
         v_descr_end_tag;
    v_length := length ( v_buffer );
    Dbms_Lob.WriteAppend(tlob, length(v_buffer) + 1, v_buffer || ' ');
    /* fourth table to be indexed */
    select t4.tagnr, t4.descr
    into v_tagnr, v_descr
    from tweb.pdp_Projcode t4
    where t4.rowid = rid;
         v_buffer := v_tagnr_start_tag ||
    v_tagnr ||
    v_tagnr_end_tag ||
    v_descr_start_tag ||
         v_descr ||
         v_descr_end_tag;
    v_length := length ( v_buffer );
    Dbms_Lob.WriteAppend(tlob, length(v_buffer) + 1, v_buffer || ' ');
    end My_Proc_Wide;
    what have I to do, to make this work?
    Any Help would be appriciated!!
    Kind Regards,
    Arsineh

    Arsineh,
    I realise that it has been quite some time since you posted this question but I thought I'd reply just in case you never did manage to get your user datastore working.
    The reason your procedure will not work is simple. A user datastore procedure accepts a rowid input parameter. The rowid is the ID of the row that Oracle Text is currently trying to index. In the example you have given, you are attempting to use the supplied rowid as the primary key for multiple tables, this will simply never work as the rowid's across multiple tables will never correspond.
    The best way to achieve your goal is to create the index on a master table which contains the common primary keys for each of your four tables e.g.
    MASTER_TABLE
    COL:COMMON_KEY (NUMBER(n))
    COL:USER_INDEX_COLUMN (VARCHAR2(1))
    If you create the user datastore index on the MASTER_TABLE.USER_UNDEX_COLUMN column your stored proc simply needs to read the correct row from the MASTER_TABLE (SELECT t.common_key into v_CommonKey FROM master_table t WHERE t.rowid = rid) and issue subsequent queries to extract the relavant data from the t1..t4 tables using the common key e.g.
    SELECT t1.tagnr, t1.descr into v_tagnr, v_descr FROM t1 WHERE t1.[PRIMARY_KEY_FIELD] = v_CommonKey;
    SELECT t2.tagnr, t2.descr into v_tagnr, v_descr FROM t2 WHERE t2.[PRIMARY_KEY_FIELD] = v_CommonKey;
    and so on...
    Hope this helps
    Dean

  • Structure for Receiver Jdbc adapter for multiple tables

    Hi,
    For Receiver JDBC adapter,Standard structure
    structure as
    Statement
       Tablename(TABLE1)
            Action
            Access
    Can i make a structure like
    Statement
         Tablename(TABLE1)
            Action
            Access
                fields....
         Tablename(TABLE2)
            Action
            Access
                fields......
    As i am using tables and I want to insert or update both of them or one based on some conditions.
    Will Insert be possible in single Statement or I have to create separate statements for each table. Can you please help me on this?
    Thanks in advance
    Best Regards,
    Harleen Kaur Chadha

    Hi Harleen,
            As already said by Dharanveer, all that you need to do is replicate the Statement level, so, istead of using this structure:
    Statement
    Tablename(TABLE1)
       Action
       Access
         fields....
    Tablename(TABLE2)
       Action
       Access
         fields......
            You will construct something like this:
    Statement1
    Tablename(TABLE1)
       Action
       Access
         fields....
    Statement2
    Tablename(TABLE2)
       Action
       Access
         fields......
           And this structure will be created in a single Data Type, that will be used to create a single Message Type, that you will use in your Message Mapping, and, the 2(or more tables that you need to manipulate) will be inserted/updated without problems using this approach.
           Thank you, and best regards,
           Wilson

  • Plsql coding for multiplication table

    hai i need plsql coding for multiplication table can any one plzzzz.....

    SELECT AVBELN AFKDAT AVTWEG ASPART AWAERK AKURRF AKUNAG AKNUMV
             BPOSNR BFKIMG BNETWR BMATNR
             DBEGRU ELABOR E~MATKL
             INTO CORRESPONDING FIELDS OF TABLE ITAB
             FROM VBRK AS A INNER JOIN VBRP AS B
                  ON AVBELN EQ BVBELN
             INNER JOIN J_1IEXCHDR AS C
                  ON AVBELN EQ CRDOC
             INNER JOIN KNVV AS D
                  ON DKUNNR EQ AKUNAG  AND
                     DVKORG EQ AVKORG  AND
                     DSPART EQ ASPART  AND
                     D~BEGRU NE SPACE
             INNER JOIN MARA AS E
                  ON EMATNR EQ BMATNR
             WHERE A~FKDAT IN S_FKDAT AND
                   A~FKART EQ 'F2'    AND
                   A~VTWEG IN S_VTWEG AND
                   A~SPART IN S_SPART AND
                   A~KUNAG IN S_KUNAG AND
                   A~FKSTO NE 'X'     AND
                   B~WERKS IN S_WERKS AND
                   C~TRNTYP = 'DLFC'  AND
                   E~LABOR IN S_LABOR AND
                C~SRGRP IN ('01','02','03','31','32','33','41','42','43',
                            '81','82','83','95','55','45', '48') AND
                   B~MATNR IN S_MATNR AND
                   D~BEGRU IN S_BEGRU AND
                   E~MATKL IN S_MATKL.
    but my suggestion not to use more than 2 table in inner join it will affect in performance use for all entries instead of join.
    regards
    shiba dutta

  • Sample coding for multiple table join

    Hi,
    i need a sample coding for multiple table join. can anyone help me out.
    regards
    Gokul

    SELECT AVBELN AFKDAT AVTWEG ASPART AWAERK AKURRF AKUNAG AKNUMV
             BPOSNR BFKIMG BNETWR BMATNR
             DBEGRU ELABOR E~MATKL
             INTO CORRESPONDING FIELDS OF TABLE ITAB
             FROM VBRK AS A INNER JOIN VBRP AS B
                  ON AVBELN EQ BVBELN
             INNER JOIN J_1IEXCHDR AS C
                  ON AVBELN EQ CRDOC
             INNER JOIN KNVV AS D
                  ON DKUNNR EQ AKUNAG  AND
                     DVKORG EQ AVKORG  AND
                     DSPART EQ ASPART  AND
                     D~BEGRU NE SPACE
             INNER JOIN MARA AS E
                  ON EMATNR EQ BMATNR
             WHERE A~FKDAT IN S_FKDAT AND
                   A~FKART EQ 'F2'    AND
                   A~VTWEG IN S_VTWEG AND
                   A~SPART IN S_SPART AND
                   A~KUNAG IN S_KUNAG AND
                   A~FKSTO NE 'X'     AND
                   B~WERKS IN S_WERKS AND
                   C~TRNTYP = 'DLFC'  AND
                   E~LABOR IN S_LABOR AND
                C~SRGRP IN ('01','02','03','31','32','33','41','42','43',
                            '81','82','83','95','55','45', '48') AND
                   B~MATNR IN S_MATNR AND
                   D~BEGRU IN S_BEGRU AND
                   E~MATKL IN S_MATKL.
    but my suggestion not to use more than 2 table in inner join it will affect in performance use for all entries instead of join.
    regards
    shiba dutta

  • GATHER_STATS job collect stats for 'static' tables

    Oracle version: 10gR2
    If a business table hasn't changed (No DML) in the last 10 days, will oracle's default stats collection job
    DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROCstill collect stats of this table?

    The answer is no, unless you have modified the default optimizer stats collecting statistics, as about 10% of the data must have undergone change before the table is elgible for new statistics.
    See the following int he Performance and Tuning manual section 14.2.1 GATHER_STATS_JOB:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#sthref1068
    HTH -- Mark D Powell --

  • Use of LIKE in where clause of select statement for multiple records

    Hi Experts,
    I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
    For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
    And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
    data : begin of t_dda occurs 0,
            dda(19) type c,
           end of t_dda.
    data : begin of t_bukrs occurs 0,
            bukrs type t012k-bukrs,
           end of t_bukrs.
    data : dda type t012k-bankn,
           w_dda type t012k-bankn.
    CONCATENATE '%'
                             '2ARS1'
                     INTO  W_DDA.
    MOVE W_DDA TO T_DDA-DDA.
    APPEND T_DDA.
    CLEAR T_DDA.
    free t_bukrs.
    SELECT BUKRS
      FROM T012K
      into TABLE t_bukrs
        for all entries in t_dda
    WHERE BANKN like t_dda-dda.
    Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
    Thanks in advance,
    Akash

    Hi,
    yes, For All entries won't work for LIKE with '%  '.
    I think the other alternative is go for Native SQL by writing sub-query
    sample code is here:
    data: begin of i_mara occurs 0,
              matnr like mara-matnr,
              matkl like mara-matkl,
           end of i_mara.
    exec sql.
    select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
    endexec.
    loop at i_mara.
    write:/ i_mara-matnr, i_mara-matkl.
    endloop.
    hope u got it.
    regards
    Mahesh
    Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM

  • How to Schedule Job using Database Control for SQLPLUS script?

    Hi All,
    I am using Database version 10.2. I would like to schedule a SQLPLUS script job using Database control (Not using Grid Control!). The following is the script.
    ========================================================
    define OEM_FRIENDLY=1
    define OWB_BACKGROUND=0
    set serveroutput on
    set verify off
    whenever sqlerror exit failure;
    define REPOS_OWNER='&1.'
    define LOCATION_NAME='&2.'
    define TASK_TYPE='&3.'
    define TASK_NAME='&4.'
    define SYSTEM_PARAMS='&5.'
    define CUSTOM_PARAMS='&6.'
    alter session set current_schema = &REPOS_OWNER.;
    set role owb_d_&REPOS_OWNER., owb_o_&REPOS_OWNER.;
    variable exec_return_code number;
    begin
    -- Initialize Return Code
    :exec_return_code := wb_rt_api_exec.RESULT_FAILURE;
    -- Run Task
    :exec_return_code := wb_rt_api_exec.run_task('&LOCATION_NAME.',
    '&TASK_TYPE.',
    '&TASK_NAME.',
    '&CUSTOM_PARAMS.',
    '&SYSTEM_PARAMS.',
    &OEM_FRIENDLY.,
    &OWB_BACKGROUND.);
    end;
    exit :exec_return_code;
    ===========================================================
    Is it possible to schedule SQLPLUS script with 6 different parameters? If yes then how can I schedule for monday to friday or only for Saturday and sundays.
    Please provide brief steps.
    Thanks for your help in advance.
    - Mehul

    Let me explain to you about scheduler.
    You can schedule a pl/sql stored procedure TEST_S as follows...
    Begin
    dbms_scheduler.create_job(
    job_name=>'MY_JOB',
    Job_Type=>'STORED_PROCEDURE',
    job_action=>'TEST_S',
    start_date=>sysdate,
    repeat_interval=>'freq=monthly;BYDAY=MON,TUE,WED,THU,FRI',
    end_date=>null');
    END;
    You can also also execute o/s script like .bat or .sh. For this job type should be EXECUTABLE.
    Example of converting a .sql script in .bat script...
    insert.sql
    insert into dept values(50,'IT','LONDON');
    exit
    insert.bat
    sqlplus scott/tiger @insert.sql
    Executing now...
    C:\Documents and Settings>insert.bat
    C:\Documents and Settings>sqlplus scott/tiger @insert.sql
    SQL*Plus: Release 10.2.0.1.0 - Production on Thu Mar 1 08:01:00 2007
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    1 row created.
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - P
    oduction
    With the Partitioning, OLAP and Data Mining options
    C:\Documents and Settings>
    So first read about DBMS_SCHEDULER and do the work in prompt. Then you can go and schedule it even by database control.
    Scheduling by database control...
    http://www.oracle.com/technology/oramag/oracle/04-jul/o44tech_dba.html
    Scheduler
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#CIHEHDHA
    PS: By default each job you created is disable state. Please enable it by enable procedure of DBMS_SCHEDULER package.

  • How to reduce time for gather statistics for a table.

    I have a table size 520 gb
    Its one of the partition size is 38 gb
    and total indexes of related table is 412 gb.
    Server/instance details.
    ==========
    56 cpu -> Hyper threading enable
    280 gb ram
    35 gb sga
    27 gb buffer cache
    4.5 gb shared pool size
    25 gb pga
    undo size 90gb
    temp size 150 gb
    Details :
    exec dbms_stats.gather_table_stats('OWNER','TAB_NAME',PARTNAME=>'PART_NAME',CASCADE=>FALSE,ESTIMATE_PERCENT=>10,DEGREE=>30,NO_INVALIDATE=>TRUE);
    when i am firing this in an ideal time when there is no load that time also is is taking 28 mins to complete.
    Can anybody please reply me how can we reduce the stats gather time.
    Thanks in advance,
    Tapas Karmakar
    Oracle DBA.

    Enable tracing to see where the time is going.
    parallel 30 seems optimistic - unless you have a large number of discs to support the I/O ?
    you haven't limited histogram collection, and most of the time spent of histograms may be wasted time - what histograms do you really need, and how many does Oracle analyse for and then discard ?
    Using a block sample may help slightly
    You haven't limited the granularity of the stats collection to the partition - the default is partition plus table, so I think you're also doing a massive sample on the table after completing the partition. Is this what you want to do, or do you have an alternative strategy for generating table-level stats.
    Regards
    Jonathan Lewis

  • Query statement for internal table

    is it possible to use a select statement to select data from an internal table? if yes, can anyone show me the codes to it? thx

    Hi Daphne,
    You use SELECT statement to read data from database table but not from Internal table.
    For reading data from Internal table, you have to use READ statement.
    Syntax:
    READ TABLE itab { table_key
                    | free_key
                    | index } result.
    Effect of using read statement:
    This statement reads a row from internal table itab. You have to specify the row by either naming values table_key for the table key, a free condition free_key or an index index. The latter choice is possible only for index tables. The output result result determines when and where the row contents are read.
    If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
    Reward if usefull
    thanks
    swaroop

Maybe you are looking for