Script to recreate indexes

Hi:
I am on 10.2.0.3.
I am aware (and use) index rebuild but now I need to drop and recreate all function-based indexes (for the char set conversion). Create a dropping script is easy. Does anyone have an idea on how to write a script which will get my indexes recreated? Use dba_source somehow?
Thanks,
Greg

Greg,
Here's a start:
SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name) FROM USER_INDEXES u;

Similar Messages

  • TIPS(18) : CREATING SCRIPTS TO RECREATE A TABLE STRUCTURE

    제품 : SQL*PLUS
    작성날짜 : 1996-11-12
    TIPS(18) : Creating Scripts to Recreate a Table Structure
    =========================================================
    The script creates scripts that can be used to recreate a table structure.
    For example, this script can be used when a table has become fragmented or to
    get a defintion that can be run on another database.
    CREATES SCRIPT TO RECREATE A TABLE-STRUCTURE
    INCL. STORAGE, CONSTRAINTS, TRIGGERS ETC.
    This script creates scripts to recreate a table structure.
    Use the script to reorganise a table that has become fragmented,
    to get a definition that can be run on another database/schema or
    as a basis for altering the table structure (eg. drop a column!).
    IMPORTANT: Running the script is safe as it only creates two new scripts and
    does not do anything to your database! To get anything done you have to run the
    scripts created.
    The created scripts does the following:
    1. save the content of the table
    2. drop any foreign key constraints referencing the table
    3. drop the table
    4. creates the table with an Initial storage parameter that
    will accomodate the entire content of the table. The Next
    parameter is 25% of the initial.
    The storage parameters are picked from the following list:
    64K, 128K, 256K, 512K, multiples of 1M.
    5. create table and column comments
    6. fill the table with the original content
    7. create all the indexes incl storage parameters as above.
    8. add primary, unique key and check constraints.
    9. add foreign key constraints for the table and for referencing
    tables.
    10.Create the table's triggers.
    11.Compile any depending objects (cascading).
    12.Grant table and column privileges.
    13.Create synonyms.
    This script must be run as the owner of the table.
    If your table contains a LONG-column, use the COPY
    command in SQL*Plus to store/restore the data.
    USAGE
    from SQL*Plus:
    start reorgtb
    This will create the scripts REORGS1.SQL and REORGS2.SQL
    REORGS1.SQL contains code to save the current content of the table.
    REORGS2.SQL contains code to rebuild the table structure.
    undef tab;
    set echo off
    column a1 new_val stor
    column b1 new_val nxt
    select
    decode(sign(1024-sum(bytes)/1024),-1,to_char((round(sum(bytes)/(1024*1
    024))+1))||'M', /* > 1M new rounded up to nearest Megabyte */
    decode(sign(512-sum(bytes)/1024), -1,'1M',
    decode(sign(256-sum(bytes)/1024), -1,'512K',
    decode(sign(128-sum(bytes)/1024), -1,'256K',
    decode(sign(64-sum(bytes)/1024) , -1,'128K',
    '64K'
    a1,
    decode(sign(1024-sum(bytes)/4096),-1,to_char((round(sum(bytes)/(4096*1
    024))+1))||'M', /* > 1M new rounded up to nearest Megabyte */
    decode(sign(512-sum(bytes)/4096), -1,'1M',
    decode(sign(256-sum(bytes)/4096), -1,'512K',
    decode(sign(128-sum(bytes)/4096), -1,'256K',
    decode(sign(64-sum(bytes)/4096) , -1,'128K',
    '64K'
    b1
    from user_extents
    where segment_name=upper('&1');
    set pages 0 feed off verify off lines 150
    col c1 format a80
    spool reorgs1.sql
    PROMPT drop table bk_&1
    prompt /
    PROMPT create table bk_&1 storage (initial &stor) as select * from &1
    prompt /
    spool off
    spool reorgs2.sql
    PROMPT spool reorgs2
    select 'alter table '||table_name||' drop constraint
    '||constraint_name||';'
    from user_constraints where r_constraint_name
    in (select constraint_name from user_constraints where
    table_name=upper('&1')
    and constraint_type in ('P','U'));
    PROMPT drop table &1
    prompt /
    prompt create table &1
    select decode(column_id,1,'(',',')
    ||rpad(column_name,40)
    ||decode(data_type,'DATE' ,'DATE '
    ,'LONG' ,'LONG '
    ,'LONG RAW','LONG RAW '
    ,'RAW' ,'RAW '
    ,'CHAR' ,'CHAR '
    ,'VARCHAR' ,'VARCHAR '
    ,'VARCHAR2','VARCHAR2 '
    ,'NUMBER' ,'NUMBER '
    ,'unknown')
    ||rpad(
    decode(data_type,'DATE' ,null
    ,'LONG' ,null
    ,'LONG RAW',null
    ,'RAW' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'CHAR' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'VARCHAR' ,decode(data_length,null,null
    ,'('||data_length||')')
    ,'VARCHAR2',decode(data_length,null,null
    ,'('||data_length||')')
    ,'NUMBER' ,decode(data_precision,null,' '
    ,'('||data_precision||
    decode(data_scale,null,null
    ,','||data_scale)||')')
    ,'unknown'),8,' ')
    ||decode(nullable,'Y','NULL','NOT NULL') c1
    from user_tab_columns
    where table_name = upper('&1')
    order by column_id
    prompt )
    select 'pctfree '||t.pct_free c1
    ,'pctused '||t.pct_used c1
    ,'initrans '||t.ini_trans c1
    ,'maxtrans '||t.max_trans c1
    ,'tablespace '||s.tablespace_name c1
    ,'storage (initial '||'&stor' c1
    ,' next '||'&stor' c1
    ,' minextents '||t.min_extents c1
    ,' maxextents '||t.max_extents c1
    ,' pctincrease '||t.pct_increase||')' c1
    from user_Segments s, user_tables t
    where s.segment_name = upper('&1') and
    t.table_name = upper('&1')
    and s.segment_type = 'TABLE'
    prompt /
    select 'comment on table &1 is '''||comments||''';' c1 from
    user_tab_comments
    where table_name=upper('&1');
    select 'comment on column &1..'||column_name||
    ' is '''||comments||''';' c1 from user_col_comments
    where table_name=upper('&1');
    prompt insert into &1 select * from bk_&1
    prompt /
    set serveroutput on
    declare
    cursor c1 is select index_name,decode(uniqueness,'UNIQUE','UNIQUE')
    unq
    from user_indexes where
    table_name = upper('&1');
    indname varchar2(50);
    cursor c2 is select
    decode(column_position,1,'(',',')||rpad(column_name,40) cl
    from user_ind_columns where table_name = upper('&1') and
    index_name = indname
    order by column_position;
    l1 varchar2(100);
    l2 varchar2(100);
    l3 varchar2(100);
    l4 varchar2(100);
    l5 varchar2(100);
    l6 varchar2(100);
    l7 varchar2(100);
    l8 varchar2(100);
    l9 varchar2(100);
    begin
    dbms_output.enable(100000);
    for c in c1 loop
    dbms_output.put_line('create '||c.unq||' index '||c.index_name||' on
    &1');
    indname := c.index_name;
    for q in c2 loop
    dbms_output.put_line(q.cl);
    end loop;
    dbms_output.put_line(')');
    select 'pctfree '||i.pct_free ,
    'initrans '||i.ini_trans ,
    'maxtrans '||i.max_trans ,
    'tablespace '||i.tablespace_name ,
    'storage (initial '||
    decode(sign(1024-sum(e.bytes)/1024),-1,
    to_char((round(sum(e.bytes)/(1024*1024))+1))||'M',
    decode(sign(512-sum(e.bytes)/1024), -1,'1M',
    decode(sign(256-sum(e.bytes)/1024), -1,'512K',
    decode(sign(128-sum(e.bytes)/1024), -1,'256K',
    decode(sign(64-sum(e.bytes)/1024) , -1,'128K',
    '64K'))))) ,
    ' next '||
    decode(sign(1024-sum(e.bytes)/4096),-1,
    to_char((round(sum(e.bytes)/(4096*1024))+1))||'M',
    decode(sign(512-sum(e.bytes)/4096), -1,'1M',
    decode(sign(256-sum(e.bytes)/4096), -1,'512K',
    decode(sign(128-sum(e.bytes)/4096), -1,'256K',
    decode(sign(64-sum(e.bytes)/4096) , -1,'128K',
    '64K'))))) ,
    ' minextents '||s.min_extents ,
    ' maxextents '||s.max_extents ,
    ' pctincrease '||s.pct_increase||')'
    into l1,l2,l3,l4,l5,l6,l7,l8,l9
    from user_extents e,user_segments s, user_indexes i
    where s.segment_name = c.index_name
    and s.segment_type = 'INDEX'
    and i.index_name = c.index_name
    and e.segment_name=s.segment_name
    group by s.min_extents,s.max_extents,s.pct_increase,
    i.pct_free,i.ini_trans,i.max_trans,i.tablespace_name ;
    dbms_output.put_line(l1);
    dbms_output.put_line(l2);
    dbms_output.put_line(l3);
    dbms_output.put_line(l4);
    dbms_output.put_line(l5);
    dbms_output.put_line(l6);
    dbms_output.put_line(l7);
    dbms_output.put_line(l8);
    dbms_output.put_line(l9);
    dbms_output.put_line('/');
    end loop;
    end;
    declare
    cursor c1 is
    select constraint_name, decode(constraint_type,'U',' UNIQUE',' PRIMARY
    KEY') typ,
    decode(status,'DISABLED','DISABLE',' ') status from user_constraints
    where table_name = upper('&1')
    and constraint_type in ('U','P');
    cname varchar2(100);
    cursor c2 is
    select decode(position,1,'(',',')||rpad(column_name,40) coln
    from user_cons_columns
    where table_name = upper('&1')
    and constraint_name = cname
    order by position;
    begin
    for q1 in c1 loop
    cname := q1.constraint_name;
    dbms_output.put_line('alter table &1');
    dbms_output.put_line('add constraint '||cname||q1.typ);
    for q2 in c2 loop
    dbms_output.put_line(q2.coln);
    end loop;
    dbms_output.put_line(')' ||q1.status);
    dbms_output.put_line('/');
    end loop;
    end;
    declare
    cursor c1 is
    select c.constraint_name,c.r_constraint_name cname2,
    c.table_name table1, r.table_name table2,
    decode(c.status,'DISABLED','DISABLE',' ') status,
    decode(c.delete_rule,'CASCADE',' on delete cascade ',' ')
    delete_rule
    from user_constraints c,
    user_constraints r
    where c.constraint_type='R' and
    c.r_constraint_name = r.constraint_name and
    c.table_name = upper('&1')
    union
    select c.constraint_name,c.r_constraint_name cname2,
    c.table_name table1, r.table_name table2,
    decode(c.status,'DISABLED','DISABLE',' ') status,
    decode(c.delete_rule,'CASCADE',' on delete cascade ',' ')
    delete_rule
    from user_constraints c,
    user_constraints r
    where c.constraint_type='R' and
    c.r_constraint_name = r.constraint_name and
    r.table_name = upper('&1');
    cname varchar2(50);
    cname2 varchar2(50);
    cursor c2 is
    select decode(position,1,'(',',')||rpad(column_name,40) colname
    from user_cons_columns
    where constraint_name = cname
    order by position;
    cursor c3 is
    select decode(position,1,'(',',')||rpad(column_name,40) refcol
    from user_cons_columns
    where constraint_name = cname2
    order by position;
    begin
    dbms_output.enable(100000);
    for q1 in c1 loop
    cname := q1.constraint_name;
    cname2 := q1.cname2;
    dbms_output.put_line('alter table '||q1.table1||' add constraint ');
    dbms_output.put_line(cname||' foreign key');
    for q2 in c2 loop
    dbms_output.put_line(q2.colname);
    end loop;
    dbms_output.put_line(') references '||q1.table2);
    for q3 in c3 loop
    dbms_output.put_line(q3.refcol);
    end loop;
    dbms_output.put_line(') '||q1.delete_rule||q1.status);
    dbms_output.put_line('/');
    end loop;
    end;
    col c1 format a79 word_wrap
    set long 32000
    set arraysize 1
    select 'create or replace trigger ' c1,
    description c1,
    'WHEN ('||when_clause||')' c1,
    trigger_body ,
    '/' c1
    from user_triggers
    where table_name = upper('&1') and when_clause is not null
    select 'create or replace trigger ' c1,
    description c1,
    trigger_body ,
    '/' c1
    from user_triggers
    where table_name = upper('&1') and when_clause is null
    select 'alter trigger '||trigger_name||decode(status,'DISABLED','
    DISABLE',' ENABLE')
    from user_Triggers where table_name='&1';
    set serveroutput on
    declare
    cursor c1 is
    select 'alter table
    '||'&1'||decode(substr(constraint_name,1,4),'SYS_',' ',
    ' add constraint ') a1,
    decode(substr(constraint_name,1,4),'SYS_','
    ',constraint_name)||' check (' a2,
    search_condition a3,
    ') '||decode(status,'DISABLED','DISABLE','') a4,
    '/' a5
    from user_constraints
    where table_name = upper('&1') and
    constraint_type='C';
    b1 varchar2(100);
    b2 varchar2(100);
    b3 varchar2(32000);
    b4 varchar2(100);
    b5 varchar2(100);
    fl number;
    begin
    open c1;
    loop
    fetch c1 into b1,b2,b3,b4,b5;
    exit when c1%NOTFOUND;
    select count(*) into fl from user_tab_columns where table_name =
    upper('&1') and
    upper(column_name)||' IS NOT NULL' = upper(b3);
    if fl = 0 then
    dbms_output.put_line(b1);
    dbms_output.put_line(b2);
    dbms_output.put_line(b3);
    dbms_output.put_line(b4);
    dbms_output.put_line(b5);
    end if;
    end loop;
    end;
    create or replace procedure dumzxcvreorg_dep(nam varchar2,typ
    varchar2) as
    cursor cur is
    select type,decode(type,'PACKAGE BODY','PACKAGE',type) type1,
    name from user_dependencies
    where referenced_name=upper(nam) and referenced_type=upper(typ);
    begin
    dbms_output.enable(500000);
    for c in cur loop
    dbms_output.put_line('alter '||c.type1||' '||c.name||' compile;');
    dumzxcvreorg_dep(c.name,c.type);
    end loop;
    end;
    exec dumzxcvreorg_dep('&1','TABLE');
    drop procedure dumzxcvreorg_Dep;
    select 'grant '||privilege||' on '||table_name||' to '||grantee||
    decode(grantable,'YES',' with grant option;',';') from
    user_tab_privs where table_name = upper('&1');
    select 'grant '||privilege||' ('||column_name||') on &1 to
    '||grantee||
    decode(grantable,'YES',' with grant option;',';')
    from user_col_privs where grantor=user and
    table_name=upper('&1')
    order by grantee, privilege;
    select 'create synonym '||synonym_name||' for
    '||table_owner||'.'||table_name||';'
    from user_synonyms where table_name=upper('&1');
    PROMPT REM
    PROMPT REM YOU MAY HAVE TO LOG ON AS SYSTEM TO BE
    PROMPT REM ABLE TO CREATE ANY OF THE PUBLIC SYNONYMS!
    PROMPT REM
    select 'create public synonym '||synonym_name||' for
    '||table_owner||'.'||table_name||';'
    from all_synonyms where owner='PUBLIC' and table_name=upper('&1') and
    table_owner=user;
    prompt spool off
    spool off
    set echo on feed on verify on
    The scripts REORGS1.SQL and REORGS2.SQL have been
    created. Alter these script as necesarry.
    To recreate the table-structure, first run REORGS1.SQL.
    This script saves the content of your table in a table
    called bk_.
    If this script runs successfully run REORGS2.SQL.
    The result is spooled to REORGTB.LST.
    Check this file before dropping the bk_ table.
    */

    Please do NOT cross-postings: create a deep structure for dynamic internal table
    Regards
      Uwe

  • Recreating indexes of type: ctxsys.context

    For a database on Oracle 10g, I need to output a script that recreates all indexes of type of ctxsys.context type. I can do it running this query:
    SELECT owner, index_name, DBMS_METADATA.get_ddl('INDEX', index_name, owner)
    FROM all_indexes
    WHERE ityp_owner = 'CTXSYS' AND ityp_name = 'CONTEXT';However, if an index has parameters like this:
    CREATE INDEX <MySchema>.<Index_name> ON <MySchema>.<Index_name>
    (BL_RESOLUCION)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS('sync (every "FREQ=DAILY; BYHOUR=1")')
    NOPARALLEL;If I run DBMS_METADATA.get_ddl function, I get this output script:
    CREATE INDEX <MySchema>.<Index_name> ON <MySchema>.<Index_name>
    (BL_RESOLUCION)
    INDEXTYPE IS CTXSYS.CONTEXT;How to include the parameter line?
    Edited by: user521219 on 06-nov-2012 9:55

    >
    For a database on Oracle 10g, I need to output a script that recreates all indexes of type of ctxsys.context type. I can do it running this query:
    SELECT owner, index_name, DBMS_METADATA.get_ddl('INDEX', index_name, owner)
    FROM all_indexes
    WHERE ityp_owner = 'CTXSYS' AND ityp_name = 'CONTEXT';
    However, if an index has parameters like this:
    CREATE INDEX <MySchema>.<Index_name> ON <MySchema>.<Index_name>
    (BL_RESOLUCION)
    INDEXTYPE IS CTXSYS.CONTEXT
    PARAMETERS('sync (every "FREQ=DAILY; BYHOUR=1")')
    NOPARALLEL;
    If I run DBMS_METADATA.get_ddl function, I get this output script:
    CREATE INDEX <MySchema>.<Index_name> ON <MySchema>.<Index_name>
    (BL_RESOLUCION)
    INDEXTYPE IS CTXSYS.CONTEXT;
    How to include the parameter line?
    >
    When you post always provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION); 10g is not a version.
    Works for me on Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
      CREATE INDEX "SCOTT"."NDX_TEST_CONTEXT" ON "SCOTT"."DEPT" ("DNAME")
       INDEXTYPE IS "CTXSYS"."CONTEXT" PARAMETERS ('sync (every "FREQ=DAILY; BYHOUR=1")')Post information about which user is running that query and which user owns the index that is giving the problem.
    Have you tried the query using a DBA user?

  • How to automatically create the custom migration scripts after recreating SSMA project?

    How to automatically create the custom data migration scripts after recreating SSMA project?
    There is number of tables ( big tables with BLOBS)  which I want to set up automatically to be migrated with custom migration scripts (replacing e.g. attribute named "FILE" with "TO_BLOB('') AS FILE" ).
    So the question is how to open MB file (I think that it should be standard db of some destktop RDBMS) ? 

    Hi Roman.Pokrovskij,
    According
    to your description, we can use SSMA tool to migrate data from one database (including Access, Oracle and so on) to SQL Server via GUI or the scripts. There is an example about migrating Access database to SQL Server via the
    custom migration scripts, you can review refer to them.
    <?xml version="1.0" encoding="utf-8"?>
    <ssma-script-file xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Microsoft SQL Server Migration Assistant for Access\Schemas\A2SSConsoleScriptSchema.xsd">
    <config>
    <output-providers>
    <output-window suppress-messages="false"
    destination="stdout"/>
    <upgrade-project action="yes"/>
    <data-migration-connection source-use-last-used="true"
    target-server="target_1"/>
    <progress-reporting enable="false"
    report-messages="false"
    report-progress="off"/>
    <object-overwrite action="skip" />
    </output-providers>
    </config>
    <servers>
    <!-- Server definition for Sql server target server-->
    <sql-server name="target_1">
    <sql-server-authentication>
    <server value="$SQLServerName$"/>
    <database value="$SQLServerDb$"/>
    <user-id value="$SQLServerUsrID$"/>
    <password value="$SQLServerPassword$"/>
    <encrypt value="true"/>
    <trust-server-certificate value="true"/>
    </sql-server-authentication>
    </sql-server>
    </servers>
    <script-commands>
    <create-new-project project-folder="$project_folder$ "
    project-name="$project_name$"
    overwrite-if-exists="true"/>
    <connect-target-database server="target_1"/>
    <load-access-database database-file="$AccessDbFolder$\$AccessDatabaseFile$"/>---
    <!--Schema Mapping-->
    <map-schema source-schema="$AccessDatabase$" sql-server-schema="$SQLServerDb$.dbo" />
    <!-- Convert schema -->
    <!-- Example: Convert entire Schema (with all attributes)-->
    <convert-schema object-name="$AccessDatabase$"
    object-type="Databases"
    conversion-report-overwrite="true"
    verbose="true"
    report-errors="true" />
    <!-- Synchronize target -->
    <!-- Example: Synchronize target entire Database with all attributes-->
    <synchronize-target object-name="$SQLServerDb$.dbo"
    on-error="fail-script" />
    <!-- Data Migration-->
    <!--Example: Data Migration of all tables in the schema (with all attributes)-->
    <migrate-data object-name="$AccessDatabase$.Tables"
    object-type="category"
    report-errors="true"
    verbose="true"/>
    </script-commands>
    </ssma-script-file>
    There is a similar scripts about migrating Oracle database to SQL Server, you can use powershell script to automatically run the console for scripts/variable files, saved in the specified folder. For more information, review the following
    article.
    http://blogs.msdn.com/b/ssma/archive/2010/09/09/performing-database-migration-assessment-using-ssma-console-application.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • VBA script for automatically indexing topics

    A big disadvantage with InDesign's indexing system is that you cannot automatically index all occurences of topics currently in the index.
    Instead, you have to find an occurence of each topic in the document itself and go to the Index menus and then click New Page Reference...Add All, for each index topic individually.
    To get around this, I have been trying to produce a VBA script to automatically index all occurrences in a document of the topics currently in the document index.
    I have been using the MS Excel VBA development environment but find the definitions of the object model in the Excel VBA browser rather inadequate and ambiguous .
    Is there a more thorough reference work for these?
    The plan was to start by taking each individual topic in the index which I tried to access with something along the lines of:
    MyDocument.Index.Topic(1)
    This hasn't worked.
    The plan then was to take each index topic and use it to find an occurence in the document of that topic and then use that occurence to invoke the New Page Reference...Add All option to index all occcurences of that selected term, using something like:
    MyDocument.PageReferences.Add
    Again, without success.
    Any guidance or suggestions would be appreciated.

    Dear Peter,
    Many thanks for your posting, that was very helpful.
    This is the state of the script so far (I have added a large number of MsgBox entries - these aren't needed, they are just for debugging purposes during development):
    'VBA script which tries to work through all of the topics in the index and automatically index each occurence of them in the current text frame:
    main
    Function main()
    Set MyInDesign = CreateObject("InDesign.Application.CS4")
    If MyInDesign.Documents.Count > 0 Then
        Set MyDocument = MyInDesign.ActiveDocument
        Set MyPage = MyDocument.Pages.Item(1)
        Set MyTextFrame = MyPage.TextFrames.Item(1)
        Set MyStory = MyTextFrame.ParentStory
        Set MyIndex = MyDocument.Indexes(1)
        Set MyTopics = MyIndex.AllTopics
        MyIndexesCount = MyDocument.Indexes.Count
        MsgBox "Current indexes Count: " & MyIndexesCount
        MyIndexTopicsCount = MyTopics.Count
        MsgBox "Current index topics Count: " & MyIndexTopicsCount
        For i = 1 To MyTopics.Count Step 1 'work through the topics
    MyIndexTerm=MyTopics(i)
    MsgBox "Current indexes Topic: " & MyIndexTerm
    'search for MyIndexTerm :
            'Clear Find preferences:
            MyInDesign.FindTextPreferences = idNothingEnum.idNothing
            'Set up search paramaters:
            If MyIndexTerm <> "" Then
                MyInDesign.FindTextPreferences.FindWhat = MyIndexTerm
                'Set search options:
                MyInDesign.FindChangeTextOptions.CaseSensitive = False
                MyInDesign.FindChangeTextOptions.IncludeFootnotes = False
                MyInDesign.FindChangeTextOptions.IncludeHiddenLayers = False
                MyInDesign.FindChangeTextOptions.IncludeLockedLayersForFind = False
                MyInDesign.FindChangeTextOptions.IncludeLockedStoriesForFind = False
                MyInDesign.FindChangeTextOptions.IncludeMasterPages = False
                MyInDesign.FindChangeTextOptions.WholeWord = False
                'Search for the string:
                Set MyFoundItems = MyDocument.FindText 'this ought to be limited to the Story, not the Document eg MyStory
             MsgBox "Found index terms:" & MyFoundItems.Count
                For j = MyFoundItems.Count To 1 Step -1
                   MyTopics(i).PageReferences.Add MyFoundItems(j)
                Next
               'Clear preference:
                MyInDesign.FindTextPreferences = idNothingEnum.idNothing
                'Having found it, add page reference:
             'MyDocument.PageReferences.Add
            Else
                MsgBox "No search term specified"
            End If
    Response=MsgBox ("Continue?", vbYesNo)
    If Response = vbNo then
      Exit For
    End If
       Next
    'Set up Index options:
    MyIndex.IndexOptions.Title = "Index"
    MyIndex.IndexOptions(1).TitleStyle="Chapter Head"
    MyIndex.IndexOptions(1).ReplaceExistingIndex = True
    'Generate the index:
    MyIndex.Generate
    Else
        MsgBox ("Please open a document, select an object, and try again.")
    End If
    End Function
    There are a couple of problem areas still:
    1. Index terms appear to be added irrespective of whether or not that particular page reference already exists in the index.
    This can result in duplicate page references under each topic - especially if the script is run several times.
    Is there any way of avoiding these duplicate references?
    2. I haven't yet suceeded in getting the script to generate the index - so far I've had to do it manually after the script has run.
    The problem lies somewhere in the code to set up the index options and then generate the index.
    3. It might be useful to be able to limit the indexing to the curent story rather than the whole document - but I haven't yet got it to do that.
    Best wishes.

  • Drop - recreate indexes

    I have a table with more than a 100 million records in production.
    There are a total of 6 indexes on the table out of which 4 are bitmap indexes.
    At the end of the year the table is populated with data. I am not aware of how many records are inserted into the table at once.
    I have done some statistical analysis in the development environment though according to which dropping and recreating indexes is feasible if the number of records inserted at once is less than 500.
    But the table count in development is only 7 million, far less than the production.
    Please advise what is the best possible way. Is there a need to drop and recreate indexes and if yes are all indexes required to drop or only the bitmap ones.
    Note: I am using oracle 10g database
    Edited by: 834445 on Feb 13, 2011 1:45 AM

    834445 wrote:
    I have a table with more than a 100 million records in production.
    There are a total of 6 indexes on the table out of which 4 are bitmap indexes.
    At the end of the year the table is populated with data. I am not aware of how many records are inserted into the table at once.
    I have done some statistical analysis in the development environment though according to which dropping and recreating indexes is feasible if the number of records inserted at once is less than 500.
    But the table count in development is only 7 million, far less than the production.
    Please advise what is the best possible way. Is there a need to drop and recreate indexes and if yes are all indexes required to drop or only the bitmap ones.
    Note: I am using oracle 10g database
    Always a difficult call to make, but doing some experiments as you are doing is a good start.
    Other points to consider - how much down-time are you given for this load, or are people expecting to access the table while it's going on - does the table get more rows added bit by bit over the course of the year - is there a big delete that happens before or at about the same time as the big insert.
    How big are the indexes (the b-tree ones particularly) compared to the total size of the cache ? On a normal insert Oracle will update b-tree indexes row by row with the table, and this can lead to a very large amount of random I/O if the indexes can't stay in the cache; what are your options for using special mechanisms (like SQL*Load, direct path insert, append hints etc.)
    Is your test representative of the real load - what do you know about patterns of data distribution and ordering as the data is loaded: how many distinct values are there in each bitmap index - if the number of distinct values similar to (or larger then) the number of rows in an array then you might end up inserting one row per value in the index for each array, and this could make the index grow unreasonably and generate a lot of redo - if your arraysize is (say) inserting 20 rows per bitmap key then the impact might be much less dramatic. This means you might choose to drop a couple of bitmap indexes while loading but keep the others.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    A general reminder about "Forum Etiquette / Reward Points": http://forums.oracle.com/forums/ann.jspa?annID=718
    If you never mark your questions as answered people will eventually decide that it's not worth trying to answer you because they will never know whether or not their answer has been of any use, or whether you even bothered to read it.
    It is also important to mark answers that you thought helpful - again it lets other people know that you appreciate their help, but it also acts as a pointer for other people when they are researching the same question, moreover it means that when you mark a bad or wrong answer as helpful someone may be prompted to tell you (and the rest of the forum) what's so bad or wrong about the answer you found helpful.

  • Script: Lists All Indexes that Benefit from a Rebuild

    Hi,
    I have some problems in MyOracleSupport to get the "Script: Lists All Indexes that Benefit from a Rebuild". 122008.1 says me, that it is out of date and I should use "NOTE:989186.1". But when I click on the Link I only get failure that he can't find the site.
    I using Firefox 3, maybe this is a problem?! Maybe someone can post the script?
    greetings from Germany

    When I go to the original document in metalink and then click on the NOTE:989093.1 link, I get to that note.
    Using
    Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
    Seems like a local problem at your site.
    By the way, if you search a little after index rebuild here, you may get an idea that you probably just don't need that script :-) I recommend especially postings from Jonathan Lewis & Richard Foote about that topic.
    Kind regards
    Uwe
    http://uhesse.wordpress.com

  • Recreating Index Behaviour

    I have an index which has size 12 GB , i reliazed that this index space is fragmented for that i decided to defragmente its space , what i did for the dfragmentation is as follows.
    1) drop that index.
    2) recreate the same index.
    -Before dropping that index the tablepace of that index space usage was 89 % in Enterprise manager console tablespaces link.
    -After dropping this index it reclaimed the space of this tablepace usage column from 89 % to 81 %, i.e it reduce the space to 8%.
    -After recreating that index the space did not reuse recliamed space from that tablespace , it reduced the space of /orahome, where my datafiles reside.
    Though recreating an index is not having the same space as before , it is occuping the space of 4 GB as before to 10 GB.Why recreating the index is consuming the space of /orahome though the space from index tablespace is reclaimed?

    no i am recreating the index on the same tablespace from where i dropped.
    This script (metadata) i got from PL/SQL developer before dropping that index , i used the same script after dropping the index.
    create unique index WF_ITEM_ATTRIBUTE_VALUES_PK on WF_ITEM_ATTRIBUTE_VALUES (ITEM_TYPE, ITEM_KEY, NAME)
      tablespace APPS_TS_TX_IDX
      pctfree 10
      initrans 11
      maxtrans 255
      storage
        initial 128K
        next 128K
        minextents 1
        maxextents unlimited
        pctincrease 0
    SQL> Drop index WF_ITEM_ATTRIBUTE_VALUES_PK
      2  /
    Index dropped.
    [prod1@uat1 ~]$ df -ha
    Filesystem                      Size            Used           Avail           Use%           Mounted on
    /dev/mapper/vgora-lvora             1.4T           1.3T              93G            94%           /orahome
    SQL> create unique index WF_ITEM_ATTRIBUTE_VALUES_PK on WF_ITEM_ATTRIBUTE_VALUES
      2  (ITEM_TYPE, ITEM_KEY, NAME)
      3    tablespace APPS_TS_TX_IDX
      4    pctfree 10
      5    initrans 11
      6    maxtrans 255
      7    storage
      8    (
      9      initial 128K
    10      next 128K
    11      minextents 1
    12      maxextents unlimited
    13      pctincrease 0
    14    );
    Index created.
    [prod1@uat1 bin]$ df -ha
    Filesystem                           Size            Used           Avail           Use%      Mounted on
    /dev/mapper/vgora-lvora                     1.4T            1.3T               85G              94%      /orahome

  • Recreate indexes,triggers and primary keys.

    Hi All,
    We have done an import of few table from MS SQL Server to oracle. But we couldnt see the indexes, triggers, primary key, foreign key of those tables.
    Could you please let us know how to recreate the primary key, foreign key, indexes, triggers etc of those tables.
    Pl suggest.
    Thanks in advance!
    Regards,
    Vidhya

    >
    We have done an import of few table from MS SQL Server to oracle
    >
    What does that mean exactly? How did you do an import from sql server to Oracle?
    Post your 4 digit Oracle version (result of SELECT * FROM V$VERSION) and the exact steps you took to 'import'.

  • Database Diff script creates redundant indexes and fails

    In Version 4.1.0.18, I create a table such that the primary key constraint and unique index have the same name:
        CREATE TABLE "MY_TABLE"
         ( "CORP_ID" CHAR(2 BYTE),
           "COMPANY_ID" NUMBER(5,0),
           CONSTRAINT "PK_MY_TABLE" PRIMARY KEY ("CORP_ID", "COMPANY_ID") ENABLE
    The DDL export of this table yields a different approach but the same end results:
        CREATE TABLE "MY_TABLE"
         ( "CORP_ID" CHAR(2 BYTE),
           "COMPANY_ID" NUMBER(5,0)
        CREATE UNIQUE INDEX "PK_MY_TABLE" ON "MY_TABLE" ("CORP_ID", "COMPANY_ID");
        ALTER TABLE "MY_TABLE" ADD CONSTRAINT "PK_MY_TABLE" PRIMARY KEY ("CORP_ID", "COMPANY_ID") ENABLE;
    Perfectly fine - no issue there.
    But if I do a complete Database Diff (all object types) and the target database is missing the table, the resulting script uses a combined approach:
        CREATE TABLE "MY_TABLE"
         ( "CORP_ID" CHAR(2) NOT NULL ENABLE,
           "GL_ACCOUNT" VARCHAR2(16),
           CONSTRAINT "PK_MY_TABLE" PRIMARY KEY ("CORP_ID","COMPANY_ID") ENABLE
       CREATE UNIQUE INDEX ."PK_MY_TABLE" ON "MY_TABLE" ("CORP_ID","COMPANY_ID");
    In this script, the CREATE TABLE will correctly create both the constraint and index.  Therefore the CREATE INDEX fails because the index already exists.

    In this script, the CREATE TABLE will correctly create both the constraint and index.  Therefore the CREATE INDEX fails because the index already exists.
    Can't help you beyond saying that is a bug since the DIFF should NOT do both of those.
    Someone from the sql dev team will need to tell you if the bug is in sql dev or the package sql dev is using to do the diff.
    Can you open the log window and review the SQL being generated/executed by sql dev?
    Sql Dev is likely using the DBMS_METADATA_DIFF package to generate the diff:
    http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_metadiff.htm
    If they are using it correctly but you get that error then it is an Oracle DB bug that needs to be filed.
    If sql dev is using the package incorrectly then sql dev has a bug and the team can address that.
    Sorry I can't help you more.

  • IND 3 or 4: script for making INDEX

    Hi,
    When typesetting books in Indesign cs3/4 (OSX), some of our texts contain words tagged like this: [r]word[#r].
    Those are the words which should end up in the index. It's a timeconsuming job to select these tagged words by hand, apply the 'create a new index entry' (apple-u), and move on to the next one.
    Can someone write a script that automates this nasty job for me? Search for the word between the paranthesis, apply apple-u, move on to the next one.
    I hope it won't be difficult for someone who is used scripting around in indesign.....
    greetings, frits

    Hi Frits,
    Check out this script (post5):
    Peter Kahrel, "Footnote behaviour" #5, 3 Dec 2008 7:24 am
    Kasyan

  • Export Table Script & all other db scripts to recreate the db

    Hi,
    I used TOAD to get all the DBScripts to recreate db. Unfortunately it does not get everything and does not get everything in dependency order. I have very limited knowledge of TOAD and unfortunately I couldn't acheive what I wanted to.
    My Requirement
    I should be able to export all DB Scripps from Oracle 9i and using those scripts I should be able to recreate DB.
    Your help shall be very much appreciated.
    Many Thanks,

    858407 wrote:
    Thanks very much. I think this might be a solution to my requirement. But I have not used this before and do not know how to use it. I am novice to database.
    I have a schema called vmlizard
    I need to be able to recreate vmlizard in vm2lizard using db scripts.
    Please tell me the steps and I shall do it accordingly.
    ThanksCheck the following code:
    SQL> grant dba to user1 identified by user1;
    Grant succeeded.
    SQL> conn user1/user1
    Connected.
    SQL> create table tbl_user1 (id number);
    Table created.
    SQL> create table tbl_user2 (id number);
    Table created.
    SQL> insert into tbl_user1 values(1);
    1 row created.
    SQL> insert into tbl_user2 values(1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from dba_directories;
    SQL> col directory_path format a20
    SQL> col directory_name format a10
    SQL> /
    OWNER                          DIRECTORY_ DIRECTORY_PATH
    SYS                            AUDIT_DIR  /tmp/
    SQL> exit
    [oracle@localhost ~]$ expdp user1/user1 dumpfile=audit_dir:user1_exp.dmp logfile=audit_dir:user1_exp.log schemas=user1 content=metadata_only
    FLASHBACK automatically enabled to preserve database integrity.
    Starting "USER1"."SYS_EXPORT_SCHEMA_01":  user1/******** dumpfile=audit_dir:user1_exp.dmp logfile=audit_dir:user1_exp.log schemas=user1 content=metadata_only
    Processing object type SCHEMA_EXPORT/USER
    Processing object type SCHEMA_EXPORT/TABLE/COMMENT
    Master table "USER1"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
    Dump file set for USER1.SYS_EXPORT_SCHEMA_01 is:
      /tmp/user1_exp.dmp
    Job "USER1"."SYS_EXPORT_SCHEMA_01" successfully completed at 15:23Now I create the second user to import the data in it:
    SQL> grant dba to user2 identified by user2;    
    Grant succeeded.
    [oracle@localhost ~]$ impdp user1/user1 dumpfile=audit_dir:user1_exp.dmp logfile=audit_dir:user1_exp.log schemas=user1 content=metadata_only remap_schema=user1:user2
    Import: Release 10.1.0.4.0 - 64bit Production on Wednesday, 25 May, 2011 15:24
    Copyright (c) 2003, Oracle.  All rights reserved.
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    Master table "USER1"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
    Starting "USER1"."SYS_IMPORT_SCHEMA_01":  user1/******** dumpfile=audit_dir:user1_exp.dmp logfile=audit_dir:user1_exp.log schemas=user1 content=metadata_only remap_schema=user1:user2
    Processing object type SCHEMA_EXPORT/USER
    ORA-31684: Object type USER:"USER2" already exists
    Processing object type SCHEMA_EXPORT/SYSTEM_GRANT
    Processing object type SCHEMA_EXPORT/ROLE_GRANT
    Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
    [oracle@localhost ~]$ sqlplus /nolog
    SQL*Plus: Release 10.1.0.4.0 - Production on Wed May 25 15:24:57 2011
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    SQL> conn user2/user2
    Connected.
    SQL> select table_name from user_tables;
    TABLE_NAME
    TBL_USER1
    TBL_USER2
    SQL> select * from tbl_user1;
    no rows selected
    SQL> select * from tbl_user2;     
    no rows selected
    SQL> As you see I've successfully moved only the structure of two tables to the different schema

  • Best script for recreating control file

    Hi
    Yesterday I had a lot of fun trying to refresh a Dev db with an inconsistent backup (just learned that the offline backup from that night finished late and not before the db was started up again, thus making datafile inconsistent).
    Today I will try again. I am waiting for the tape backup to finish restoring to the Dev datafile directory.
    I would love to know if there is a template out there, or if we can agree here, for the best standard for recreating a control file through a @script.
    I will include the one I intend to use here, minus the datafiles.
    I am using the RESETLOGS, since we are using :"SET" database.
    STARTUP NOMOUNT
    CREATE CONTROLFILE SET DATABASE "DEV" RESETLOGS ARCHIVELOG
    -- SET STANDBY TO MAXIMIZE PERFORMANCE
    MAXLOGFILES 16
    MAXLOGMEMBERS 2
    MAXDATAFILES 500
    MAXINSTANCES 1
    MAXLOGHISTORY 19285
    LOGFILE
    GROUP 1 (
    '/oradbi1/oracle/proddata/log01a.dbf',
    '/oradbi1/oracle/proddata/log01b.dbf'
    ) SIZE 10M,
    GROUP 2 (
    '/oradbi1/oracle/proddata/log02a.dbf',
    '/oradbi1/oracle/proddata/log02b.dbf'
    ) SIZE 10M,
    GROUP 3 (
    '/oradbi1/oracle/proddata/log03a.dbf',
    '/oradbi1/oracle/proddata/log03b.dbf'
    ) SIZE 10M
    -- STANDBY LOGFILE
    DATAFILE
    '/oradbi1/oracle/proddata/system01.dbf',
    '/oradbi1/oracle/proddata/applsysd09.dbf',
    '/oradbi1/oracle/proddata/bend06.dbf'
    CHARACTER SET US7ASCII
    RECOVER DATABASE USING BACKUP CONTROLFILE
    ALTER DATABASE OPEN RESETLOGS;
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oradbi1/oracle/proddata/tmp04.dbf'
    SIZE 2040M REUSE AUTOEXTEND OFF;
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oradbi1/oracle/proddata/tmp03.dbf'
    SIZE 2040M REUSE AUTOEXTEND OFF;
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oradbi1/oracle/proddata/tmp02.dbf'
    SIZE 2040M REUSE AUTOEXTEND ON NEXT 10485760 MAXSIZE 32767M;
    ALTER TABLESPACE TEMP ADD TEMPFILE '/oradbi1/oracle/proddata/tmp01.dbf'
    SIZE 2000M REUSE AUTOEXTEND OFF;
    If anyone can see room for improvement on this, please let us know.
    Thanks.
    AIX 5.2
    Oracle 9.2

    I normally break it up into seperate scripts (even though the "trace" file generates a single script file).
    1. The first is the CREATE CONTROLFILE itself. If successful , it also mounts the database.
    The most important portion is to validate that we do have ALL the datafiles included.
    (eg if you are generating from an old controlfile backup and some new datafile(s) have been added since that backup you had better ensure that you add them to the script , else the RECOVER DATABASE will ignore them and they will be unrecoverable after the OPEN RESETLOGS !)
    2. The next portion is the RECOVER DATABASE USING BACKUP CONTROLFILE which I never run non-interactively.
    Always ensure that it is NOT an interactive run. If you really have more than a dozen archivelogs to apply, then you could just enter AUTO after supplying the first 3 or 4 archivelogs and wait for the RECOVER DATABASE to "error" out after it applies the last archivelog.
    3. The next portion is a manual RECOVER to apply any Archivelogs that couldn't be applied by the AUTO -- eg Archives that weren't on disk but which I've restored OR the actual last Active/Current Online Redo Logs that hadn't been applied.
    between step 3 and step 4,
    to be safe : I could SHUTDOWN (it is MOUNTED but not OPEN) and take a Cold Backup of the database files and controlfiles. -- This can help me retry a RESETLOGS or restore a datafile that I might have mistakenly excluded from the CREATE CCF script
    and re-"recover" database -- meaning that Oracle will recover that datafile alone.
    4. Finally I review the alert.log, satisfy myself that I have applied all archivelogs and then manually issue the ALTER DATABASE OPEN RESETLOGS.
    5. Now I add TEMPFILEs (if 10g hasn't done it "automagically")
    6. If I have time, take a Cold Backup OR initiate a Hot Backup asap.
    I know that 10g now provides supported methods of recovering through a RESETLOGS, based on Incarnation ID, ... but still , old habits and old commands die hard.
    Have I answered your question about how to format the CREATE CCF ? No. But I've just added some inputs on how I prefer the next few steps be done.
    Hemant K Chitale
    http://hemantoracledba.blogspot.com
    Edited by: Hemant K Chitale on Oct 22, 2008 10:05 PM
    Added the addition of TEMPFILEs
    Edited by: Hemant K Chitale on Oct 22, 2008 10:20 PM
    Corrected step 2 to be "Always ensure that it is NOT an interactive run"

  • Rebuilding or recreating index

    I'm currently disabling the index on a table that is truncated and loaded with upto 10Million of rows, this is done repeatedly-- i mean the whole process is like this. At the end i enable the index and rebuild it.
    Would it be better to drop the index and just recreate it ? Is there any difference in speed or costs?
    Thanks for the answer.

    since you're truncating the table (as opposed to appending to it) there probably are no noticable gains from disabling the index. by disabling it, it has to be built after the table is loaded, as opposed to while the table is being loaded. and if it were more than one index, then there could be an argument for disabling all and rebuilding in parallel (having multiple rebuild jobs run in parallel, not using parallel processing on an individual statement), but for only one index this doesn't matter.
    try leaving the index in place, without disabling it, and load the table. compare that to the time to disable, load, enable and rebuild. probably not much difference.

  • Possible to make a script for duplicating index entries?

    I would like to make things easier than they seem to be.
    I have several references (1:st level topics) already that are correct with page numbers and all that.
    Now, I would like to create a 1:st level topic, under which I put "duplicates" of these already indexed references and put them as 2:nd level topics, under the main, 1:st level, topic.
    Example.
    Let's say I have these references (1:st level topics) already, with correct page numbers and everything:
    Audi 4-6, 8
    BMW 7, 21-24
    Citroen 11, 12
    Mercedes 80
    Volkswagen 31-36
    Okay, these are perfectly indexed and all the pages are correct.
    Now, I would like to have these references as both 1:st level topics, and also as second level topic references under the main topic "Cars", like this:
    Cars 4-80
    Audi 4-6, 8
    BMW 7, 21-24
    Citroen 11, 12
    Mercedes 80
    Volkswagen 31-36
    My question is. Is it possible to achieve this by a script, so I can copy (duplicate) all these references and put them under the topic "Cars" too (preserving the 1:st level topics too of course), without having to go to each of the pages and create new topics all over again for every single finished topic, that I intend to put under the main topic "Cars"?
    Just to inform you, the above named 5 topics, are NOT only the topics I want to put under "Cars"... there are like a hundred :).
    Is it possible to make a script like this? Or do I have to do all the work ALL OVER again?
    Martin

    Hmmm… This one copies all files which have 'flash' (could by x-shockwave-flash) string in mime type to /tmp/flash. Hope it will be helpful.
    for i in ~/.opera/cache4/* ; do file -i -F '' $i | grep flash | cut -d ' ' -f 1 | xargs cp -t /tmp/flash 2>/dev/null ; done
    UPDATE:
    Sorry, there was a little bug, I've just changed 'video' to 'flash' ('video' coundn't match 'x-shockwave-flash').
    Last edited by zergu (2008-12-25 21:16:38)

Maybe you are looking for

  • Log in! Help Me Please!

    I have a Satellite L300-13R. when i switch the laptop on, the toshiba screen and then the Microsoft Corporation (with loading bar) appear. at the same time, i know that the hard drive is working as i can hear it. Shortly after this, the screen goes o

  • IPod Classic won't go into diognostic or disk mode

    I've been having trouble with my 160gb iPod classic the last few days, after deciding to sync it for the first time in 5 years. It keeps coming up with different error problems half way through syncing or causing my iTunes to freeze and eventually I

  • How to add new increase the pool rather then trowing a error.

    Im trying to build a game and after many attempts and hours of thinking i did manage to create something that looks like a game.The problem now is that there are so many objects that are constantly creating and removing from the stage. that the game

  • Using Field determined in a Condition in another Condition for a pricing procedure

    Hi Gurus, I have a scenario in a pricing procedure as follows: Cond type ZABC : Determines field HIENR because of the Processing type marked as B for determination based on a field KUNNR .. I want to use the HIENR determined in the previous access in

  • Using auto tune in garage band

    i just downloaded the Auto-Tune 5 AU demo but i do not know how i use it in garage band 1 now, if anyone could explain it to me i would greatly appreciate it! thanks, jball