How to build the query SQL for indexes work based on data - dict.?

Hello

I want to build the index 'create' - statement to all indexes have worked-based on the data dictionary.

For example:
create indexes tab1.ind1
on tab1 (lower (col3), lower (col1), col2, col4)
Tablespace "index."

I know I'll find all needed information views all_indexes, all_ind_columns and all_ind_expressions. During the generation of the create statement for the index of the order of the indexed columns must be correct (the order of the indexed column can be achieved using the "position_colonne" column of seen all_ind_columns and all_ind_expressions). But what would be the best way to provide all the necessary information in the right order?
One way would be a PLSQL procedure that puts it all together - but is it possible to use a single SQL statement?

Any help will be appreciated.

Rgds
JH

You can try using DBMS_METADATA. GET_DDL:

SQL> show user;
USER is "TEST"
SQL> drop table t;

Table dropped.

SQL> create table t(x varchar2(10));

Table created.

SQL> create index i on t(upper(x));

Index created.

SQL> select dbms_metadata.get_ddl('INDEX','I','TEST') from dual;

DBMS_METADATA.GET_DDL('INDEX','I','TEST')
--------------------------------------------------------------------------------

  CREATE INDEX "TEST"."I" ON "TEST"."T" (UPPER("X"))
  PCTFREE 10 INITRANS 2 MAXTRANS 255
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "USERS"

Tags: Database

Similar Questions

  • write the query sql for the following situation?

    We have a table like format following...

    A AND B
    ...................
    10 30
    50 40
    60 80
    90 100


    so to write the query and get the result like formats following...


    RESULT
    ............
    30
    50
    80
    100


    Try this... He's one of the interview question. I can't write the query...


    If a knowledge write the query...

    Hello
    Try this

    select (case when a>b then a else b end)   "Result"  from ;
    
  • How to pass the query parameters for the task "execute the external command"?

    Hello

    We are on the VSM 9 R8. Although VSM offers plenty of connectors, however we must incorporate VSM with other 3rd party applications using powershell, protocols SOAP.

    I do this via the task run the external procedure. However, I am only able to send standard variables outside the tasks for example [request: REQUEST_DESC]. This task can not pass my custom settings which I take on my portal to the user for example, currency (Datacae id is CURR).

    All the world is facing this limitation before?

    Concerning

    Ankit

    It's all exactley. Although just with the help of [EXTFLDV_500xxx] would give the value of the field of the task at hand. You could use [REQUEST: EXTFLDV_500xxx]. I prefer [REQUEST_NO$ CR_REQUEST.] EXTFLDV_500xxx]

  • Build the query to select date with status

    Hi guys,.

    Grateful if you can advise me on how to build the query on below scenario:

    Table A

    Date

    11.44.39.000000000 12-OCT-14 AM ASIA/SINGAPORE

    11.44.35.000000000 16-SEP-14 AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE

    The result of the query:

    Date                                                                                            Status

    11.44.39.000000000 12-OCT-14 AM ASIA / SINGAPORE inactive

    11.44.35.000000000 16-SEP-14 active AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE inactive

    Basically, the logic, I wanted is

    Active principles: today date or max (date) < sysdate

    Otherwise will be inactive

    And there is 1 active date in time.

    Thanks in advance

    Hello

    2753165 wrote:

    Hi guys,.

    Grateful if you can advise me on how to build the query on below scenario:

    Table A

    Date

    11.44.39.000000000 12-OCT-14 AM ASIA/SINGAPORE

    11.44.35.000000000 16-SEP-14 AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE

    The result of the query:

    Date                                                                                            Status

    11.44.39.000000000 12-OCT-14 AM ASIA / SINGAPORE inactive

    11.44.35.000000000 16-SEP-14 active AM ASIA/SINGAPORE

    11.44.42.000000000 22-SEP-14 AM ASIA/SINGAPORE inactive

    Basically, the logic, I wanted is

    Active principles: today date or max (date)<>

    Otherwise will be inactive

    And there is 1 active date in time.

    Thanks in advance

    Sorry, we don't know what you want.

    Are you saying that 1 row (maximum) can be assigned status = 'Active' and if 2 or more lines are eligible, the last of them will be called 'Active'?

    If so:

    CASE

    WHEN tmstmp<=>

    OR ROW_NUMBER () OVER (PARTITION BY CASE

    WHEN tmstmp<=>

    THEN "could be."

    ANOTHER 'No Way'

    END

    ORDER BY tmstmp DESC

    )  = 1

    THEN "active."

    ELSE 'inactive '.

    END

    If you would care to post CREATE TABLE and instructions INSERT for some samples, so I could test it.

    DATE is not a very good name for a column, especially if the column is a TIMESTAMP, not a DATE.  I called the TMSTMP instead of the DATE column.

  • Web site created by Muse. The greats until tweek of today. Web site insists now for open index.html in the tablet. Don't know how product, nor how to change the default value for pc of office/index.html. Would advise. Bob

    Web site created by Muse. The greats until tweek of today. Web site insists now for open index.html in the tablet. Don't know how product, nor how to change the default value for pc of office/index.html. Would advise. Bob

    Hi Bob

    I think that you have found the solution but if still you are facing the question, please give me the url of the site that opens another provision in the tablet.

    Please make sure desktop redirection is checked in the site properties page layout.

    Thank you

    Sanjit

  • procedure that will dynamically build the query data and table Medallion

    Hi people,

    I write a procedure that dynamically build the query data and insert in the table "dq_summary".
    enforcement procedure with success and data not inserted into the table 'dq_summary '.

    I have thin problem in code attached below
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOR rep IN cur_di_attr
          LOOP
            dbms_output.put_line ('d: ');   
            
            BEGIN
              EXECUTE IMMEDIATE 'SELECT table_name FROM ' || sum_tab || ' WHERE id = ' || rep.attribute_id INTO rep_tab;
              dbms_output.put_line ('rep_tab: '||rep_tab);
              run_query := run_query || ' ' || rep_tab || ' WHERE ' || nvl(wh_cond, '1 = 1');
              EXECUTE IMMEDIATE run_query INTO end_rslt;
            
              EXECUTE IMMEDIATE 'UPDATE dq_summary SET ' || prop || '_' || p_code || ' = ' || end_rslt || ' WHERE attribute_id = ' || rep.attribute_id;
              dbms_output.put_line ('e: ');      
              dbms_output.put_line ('rep_tab: '||rep_tab);
              dbms_output.put_line ('end_rslt: '||end_rslt);
              dbms_output.put_line ('f: '); 
            EXCEPTION
              WHEN no_data_found THEN
                rep_tab := '';
                sum_tab := '';
            END;  
          
          END LOOP;    
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    but in the procedure below must be run several times
    create or replace
    PROCEDURE DQ_REPORT_PROC
    AS
      prop                              di_proposition.pro_name%type;
      col_var                           VARCHAR2(100);
      p_code                            dq_parameter.para_code%type;
      sum_tab                           di_proposition.summary_table%type;
      run_query                         dq_parameter.run_query%type;
      wh_cond                           dq_parameter.where_cond%type;
      end_rslt                          VARCHAR2(20);
      rep_tab                           VARCHAR2(50);
      v_error_msg                       VARCHAR2(200);   
      v_error_code                      VARCHAR2(200);  
      v_object_name                     VARCHAR2(50)                          DEFAULT 'DQ_REPORT_PROC';
      v_iss_no                          VARCHAR2(20)                          DEFAULT NULL;
      CURSOR cur_di_prop IS 
        SELECT upper(replace(replace(pro_name, ' '),'-')) pro_name
          FROM di_proposition;
      
      CURSOR cur_di_para IS
        SELECT upper(para_code) para_code, run_query, where_cond
          FROM dq_parameter;
      
      CURSOR cur_di_attr IS 
        SELECT attribute_id
          FROM dq_summary;
    BEGIN
      
      DELETE FROM dq_summary;
    
      INSERT INTO dq_summary (attribute_id, entity_name, attribute_name, data_champ) 
        SELECT a.attribute_id, b.entity_name, a.attribute_name, a.data_champ
          FROM di_attribute_master a, di_entity_master b
         WHERE a.entity_id = b.entity_id;
    
      FOR c_prop IN cur_di_prop
      LOOP
        prop := c_prop.pro_name;
        
        BEGIN
          SELECT distinct SUBSTR(column_name, 1, INSTR(column_name, '_')-1), summary_table
            INTO col_var, sum_tab
            FROM user_tab_cols a, di_proposition b
           WHERE a.table_name = 'DQ_SUMMARY'
             AND upper(replace(replace(b.pro_name, ' '),'-')) = prop
             AND SUBSTR(a.column_name, 1, INSTR(a.column_name, '_')-1) = upper(replace(replace(b.pro_name, ' '),'-'))
             AND upper(b.status) = 'Y';
             
             dbms_output.put_line ('col_var: '||col_var);
             dbms_output.put_line ('sum_tab: '||sum_tab);
             
        EXCEPTION
          WHEN no_data_found THEN
            col_var := '';
            sum_tab := '';
        END;
    
        dbms_output.put_line ('a: ');
    
        FOR para IN cur_di_para
        LOOP
         dbms_output.put_line ('b: ');
          p_code := para.para_code;
          run_query := para.run_query;
          wh_cond := para.where_cond;
          dbms_output.put_line ('c: ');
          FOR rep IN cur_di_attr
          LOOP
            dbms_output.put_line ('d: ');   
            
            BEGIN
              EXECUTE IMMEDIATE 'SELECT table_name FROM ' || sum_tab || ' WHERE id = ' || rep.attribute_id INTO rep_tab;
              dbms_output.put_line ('rep_tab: '||rep_tab);
              run_query := run_query || ' ' || rep_tab || ' WHERE ' || nvl(wh_cond, '1 = 1');
              EXECUTE IMMEDIATE run_query INTO end_rslt;
            
              EXECUTE IMMEDIATE 'UPDATE dq_summary SET ' || prop || '_' || p_code || ' = ' || end_rslt || ' WHERE attribute_id = ' || rep.attribute_id;
              dbms_output.put_line ('e: ');      
              dbms_output.put_line ('rep_tab: '||rep_tab);
              dbms_output.put_line ('end_rslt: '||end_rslt);
              dbms_output.put_line ('f: '); 
            EXCEPTION
              WHEN no_data_found THEN
                rep_tab := '';
                sum_tab := '';
            END;  
          
          END LOOP;    
        END LOOP;
      END LOOP; 
      COMMIT;   
    EXCEPTION
          WHEN OTHERS THEN
             v_error_msg   := SQLERRM;
             v_error_code  := SQLCODE;  
             TRACKER_LOG_EXECEPTION(v_iss_no, v_object_name, CURRENT_TIMESTAMP, v_error_msg, v_error_code);
          COMMIT;        
      
    END DQ_REPORT_PROC;
    Published by: BluShadow on February 7, 2012 12:04
    addition of {noformat}
    {noformat} tags.  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    903830 wrote:

    I write a procedure that dynamically build the query data and insert in the table "dq_summary".
    enforcement procedure with success and data not inserted into the table 'dq_summary '.

    I'm sorry. But there is no kind of say that way. The code is undesirable. The approach is wrong. This will not happen. This will cause the fragmentation of memory in the shared Pool. This will lead to another session being impossible to analyze the sliders because of the fragmented memory.

    Not only that. The underlying data model is questionable.

    All this seems a candidate perfect as an example of how NOT to design and code and use Oracle.

  • Need help to build the query

    Hello

    I got the info from a table named X.

    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    IT01 30 50 X

    If the value of "X" all 4 combinations of Col2 and Col3, Col4 the result should be displayed as

    Col1, Col4
    IT01 X

    If the actual values are as
    Col1 Col2 Col3 Col4
    IT01 20 01 X
    IT01 20 50 X
    IT01 30 01 X
    30 50 IT01 Y

    The result should be displayed as

    Col1, Col4
    IT01 Y

    How will generate the query for this?

    Thank you
    Thomas Titus

    Published by: Titus Thomas on April 20, 2010 14:48

    Try this:

    with test_tab as (select 'ITO1' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO1' Col1, 30 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 20 Col2, 50 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 01 Col3, 'X' Col4 from dual union all
                      select 'ITO2' Col1, 30 Col2, 50 Col3, 'Y' Col4 from dual)
    --- end of mimicking your data; use SQL below:
    select col1, max(col4) col4
    from   test_tab
    group by col1;
    
    COL1 COL4
    ---- ----
    ITO2 Y
    ITO1 X   
    
  • How to get the device model, for example app works on PlayBoook or BlackBerry 10?

    How to get the device model, for example app works on PlayBoook or BlackBerry 10?

    You can use this class: http://goo.gl/GtMLP for information on devices

    something like this:

    String myDeviceModel = android.os.Build.MODEL;
    String myDeviceBrand = android.os.Build.BRAND;
    String myDeviceDevice = android.os.Build.DEVICE;
    
  • How to get the different records for the date max.

    Hi all

    Here is the sample sql for sample table and data.

    Create table student (dept_id number(10), first_name varchar2(10),last_name varchar2(10),join_date date,years_attended number(10));

    insert into student values (1,'Ann','Coleman',to_date('3/7/1917','MM/DD/YYYY'),4);
    insert into student values (1,'Ann','Coleman',to_date('3/7/1916','MM/DD/YYYY'),5);
    insert into student values (2,'Rock','Star',to_date('1/1/1920','MM/DD/YYYY'),5);
    insert into student values (2,'Rock','Star',to_date('1/1/1921','MM/DD/YYYY'),6);
    insert into student values (3,'Jack','Smith',to_date('7/1/1900','MM/DD/YYYY'),3);

    insert into student values (3,'Jack','Smith',to_date('7/1/1901','MM/DD/YYYY'),4);

    commit;

    I need to get maximum date records when the name and dep_id corresponds to. I wrote the query below and it becomes the expected result, but I'm not sure it's quite effective.

    SELECT s.dept_id, s.first_name,s.years_attended

    FROM (SELECT dept, MAX (join_date) join_date

    STUDENT GROUP BY dept_id) x

    Student JOIN s ON x.dept_id = s.dept_id AND x.join_date = s.join_date;

    This above query returns records like below, and this is the goal.

    DEPT_ID NAME YEARS_ATTENDED

    1                         Ann                                4

    2                         Rock                              6

    3                         Jack                              4

    Can you please let me know the query SQL I wrote is effective or not? This sample table may have less data, but I'm dealing with millions of records.

    Hello

    Thanks for posting CREATE TABLE and INSERT statement. This really helps.

    Here's a solution. I also added a name that seems logical. In which case you can delete:

    Select dept_id, first_name, last_name

    , max (years_attended) Dungeon years_attended (last dense_rank order by join_date)

    the student

    Group of dept_id, first_name, last_name;

    DEPT_ID FIRST_NAME LAST_NAME YEARS_ATTENDED

    ---------- ---------- ---------- --------------

    1 Ann Coleman 4

    Rock 2 star 6

    3 Jack Smith 4

    Kind regards.

    Alberto

  • How to provide the Alias name for BOX Stmt?

    Hello

    How to provide the Alias name for the instruction BOX?

    --

    Thank you and best regards,

    Badr Hari

    1007980 wrote:

    Hello

    How to provide the Alias name for the instruction BOX?

    --

    Thank you best regards &,.

    Badr Hari

    You post any instructions BOX or a query.

    You just add an alias after him, as you do for any other column you select.

    Select case when deptno = 20, then 'Yes' else 'no' from the end IsItDept20 dept

    ISITDEPT20

    NO.

    Yes

    NO.

    NO.

  • How to frame the query?

    Uses oracle ebs r12

    I have a table of data is

    Operation_seq Type statusflag SeqNum
    1 10A Y
    2 20 b Y
    3 30 c Y
    4 40 D Y
    5 50 e N
    6 60 f Y

    I want to write a query in which I want to take only 1 record operation_seq = 50 and Statusflag is N and all other interventions seq status is there.

    My query must return only 50 operation when the status of 50 is N and any other status is Y.

    Help, please.

    Thank you
    Lavan

    LAVANKV wrote:
    This statusflag can be (null or N), then how to frame the query.

    Simply wrap the statusflag with NVL column, you should be good.

    SQL> with t
      2  as
      3  (
      4  select 1 seqnum, 10 operation_seq, 'a' type, 'Y' statusflag from dual union all
      5  select 2 seqnum, 20 operation_seq, 'b' type, 'Y' statusflag from dual union all
      6  select 3 seqnum, 30 operation_seq, 'c' type, 'Y' statusflag from dual union all
      7  select 4 seqnum, 40 operation_seq, 'd' type, 'Y' statusflag from dual union all
      8  select 5 seqnum, 50 operation_seq, 'e' type, '' statusflag from dual union all
      9  select 6 seqnum, 60 operation_seq, 'f' type, 'Y' statusflag from dual
     10  )
     11  select seqnum, operation_seq, type, statusflag
     12    from (
     13            select t.*, count(decode(statusflag, 'Y', 1, null)) over() cnt_1, count(*) over() cnt_2
     14              from t
     15         )
     16   where operation_seq = 50
     17     and nvl(statusflag, 'N') = 'N'
     18     and cnt_2-cnt_1 = 1
     19  /
    
        SEQNUM OPERATION_SEQ T S
    ---------- ------------- - -
             5            50 e
    
  • How to write the query option in expdp

    Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...

    where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';


    Please do what is necessary...

    Pavan Kumar says:
    QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")

    Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.

    query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
    

    You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.

  • How to change the PCTFREE parameter for an existing table

    How to change the PCTFREE parameter for an existing table?

    Guys can you help me please

    Hello

    Of course it is possible.
    In this case you would export the table from the database (using old style exp)
    Start the import with the index_file option to generate the table/index instructions
    Modify the file created and updated the PCTFREE and remove any that need to be performed (default, if I remember correctly, he comments on the statements of the Index)
    Run the file for the table and the index created
    After that start the import with the option "ignore = yes".

    Make sure that you export only this particular table using "tables =
    Also in importing the "ignore = yes" will also be important data that still exists.

    In my view, however, this is not what you want to do. It's more complex, sensitive failure and the table should be deleted, so users are affected unnecessarily long.

    Success!
    FJFranken

  • How to end a query running for a report?

    Hello
    When I run a report, the SQL query takes too long.
    This causes an overload on the database.
    How to stop the query execution after a while?

    It is NOT possible in OBIEE 10 g.
    In OBIEE 11 g, when a scheduled report task is working you can now cancel the currently running task since the report job history page.
    This section 6.9, ['Cancellation of a work in progress.' | http://docs.oracle.com/cd/E23943_01/bi.1111/e22257/view_manage_rpt_his.htm#cancel_runj]
    And only possible since 11.1.1.5

    concerning
    Jorge
    p.s if this answers your question, then please mark my answer 'Proper' or 'useful '.

  • How to find the bpel instance in 11 g based on the index values

    We have 10 GB BPEL processes where we define the 4 index values for all instances. Whenever the support request comes, ask us the values of index and based on what we're looking for the process instance.

    We have now migrated bpel 10g and 11g process. How to find the bpel instance in 11 g based on the index values?

    You can go there. http://soasphere.blogspot.com/2011/04/how-to-Serch-composites-for-index.html. Do a join on the cube_instance and ci_indexes tables.

Maybe you are looking for

  • Toshiba NB100 ACPI & WIFI on Debian Squeeze

    Hi, it is perhaps a good place to ask. One morning, I founded my netbook completely hung. So I turned off and restarted, but it hung in new and latest lines on the screen where the ACPI: _OSI (Linux) ignored BIOS query. From now my linux can start ve

  • Best way to display a waform through a webservice

    Hello I know my way around text based on well enough programming languages, but I am very new to Labview.The problem I face is something that I can't seem to know the right information on the internet. I have a DAQmx Council I would like to show sign

  • problem updating Levono p780 since s110 to s112

    I download new updates from s110 to s112 menu update. He asked me to restart to update. After reboot from recovery with Update menu began appeared and almost on the half of the progress bar - shows me error: Installing update... Checking current syst

  • 3 difficulty settings problems

    I have three issues in the workplace with how I use the mobile and at least two of them are useless mobile for me. 1. I need to have the active screen when charging, without going into sleep or reduction of brightness. 2 I need also a feature that co

  • 1217 LaserJet MFP: Securing e-print printer connected

    The printer is set to e-print, email addresses allowed only and to print wireless at home.  Both work very well.  However, the printer broadcasts its SSID and shows as non-secure.  I have two questions: (1) how to stop the broadcast SSID?  (2) how to