Do I need to create indexes on column name?

Following queries have been shown as bad sql :          
select * from t1 where name = 'FUNCTION'
Count=     7     Avg Time=13     Min Time=0     Max Time=47
select * from t2 where name = 'USER_TYPE'      
Count=2     Avg Time=85     Min Time=0     Max Time=156
select * from t3 where name = 'TEMPLATE'
Count=7     Avg Time=19     Min Time=0     Max Time=32
All these tables have less than 20 records and static tables.                    
Do I need to create indexes on column name?

A FTS even on very small tables can require more latches than accessing via an index. Also, a table access requires the segment header and data block to be accessed (2) whereas an index on a small index only requires access to the index root block and table block (2).
True, it's unlikely to make much of a difference in most environments but if the table is really heavily accessed, indexing even very small tables can help to reduce the related latch overheads.
Most of these small tables have PKs and are accessed via the PK so associated indexes usually exist anyways.
Cheers
Richard Foote
http://richardfoote.wordpress.com/

Similar Messages

  • When do I really need to create indexes for a table?

    Once I was talking to a dba in a conference.
    He told me that not always I have to create indexes for a single table, it depends of its size.
    He said that Oracle read registers in blocks, and for a small table Oracle can read it fully, in a single operation, so in those cases I don't need indexes and statistcs.
    So I would like to know how to calculate it.
    When do I really need to create indexes for a table?
    If someone know any documment that explain that, or have some tips, I'd aprecciate.
    Thanks.
    P.S.: The version that I'm using is Oracle 9.2.0.4.0.

    Hi Vin
    You mentioned so many mistakes here, I don't know where to begin ...
    vprabhu_2000 wrote:
    There are different kinds of Index. B-tree Index is by default. Bit map index, function based index,index organized table.
    B-tree index if the table is large This is incorrect. Small tables, even those consisting of rows within just one block, can benefit from an index. There is no table size too small in which an index might not be benefical. William Robertson in his post references links to my blog where I discuss this.
    and if you want to retrieve 10 % or less of data then B-tree index is good. This is all wrong as well. A FTS on a (say) million row table could very well be more efficient when retrieving (say) just 1% of data. An index could very well be more efficient when retrieving 100% of data. There's nothing special about 10% and there is no such magic number ...
    >
    Bit Map Index - On low cardinality columns like Sex for eg which could have values Male,Female create a bit map index. Completely and utterly wrong. A bitmap index might be the perfect type of index, better than a B-Tree, even if there are (say) 100,000 distinct values in the table. That a bitmap index is only suitable for low cardinality columns is just not true. And what if it's an OLTP application, with lot's of concurrent DML on the underlining table, do you really think a bitmap index would be a good idea ?
    >
    You can also create an Index organized table if there are less rows to be stored so data is stored only once in index and not in table. Not sure what you mean here but an IOT can potentially be useful if you have very large numbers of rows in the table. The number of rows has nothing to do with whether an IOT is suitable or not.
    >
    Hope this info helps. Considering most of it is wrong, I'm not sure it really helps at all :(
    Cheers
    Richard Foote
    http://richardfoote.wordpress.com/

  • I need the "Real" Table / Table Column names from a sql view

    Firstly, we have a system with ~1000 tables and ~250 views.  We have field level security on the table columns (in our code)
    Now we have a lot of views which select data from the tables, but I need to get the "Table Column Name" that is linked in the view. 
    I know there are view columns that is not linked to a specific table column, (or concatenation of columns) so those columns can just return NULL.
    From the sample you will see there is a view selecting data from another view.  I know it is not the best sql performance (execution path) but that is another topic on its own.
    I went through a lot of the sys.* stored procs or sys.* views to try and figure out if there is a view that we can use to get the expected results.
    here is the sql code:
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'AliasView2')
    drop view dbo.AliasView2
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'AliasView1')
    drop view dbo.AliasView1
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'Table4')
    BEGIN
    alter table dbo.Table4
    DROP CONSTRAINT [FK_T4_T3]
    alter table dbo.Table4
    DROP CONSTRAINT [PK_T4_Constraint]
    drop table dbo.Table4
    END
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'Table3')
    BEGIN
    alter table dbo.Table3
    DROP CONSTRAINT [FK_T3_T2]
    alter table dbo.Table3
    DROP CONSTRAINT [PK_T3_Constraint]
    drop table dbo.Table3
    END
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'Table2')
    BEGIN
    alter table dbo.Table2
    DROP CONSTRAINT [FK_T2_T1]
    alter table dbo.Table2
    DROP CONSTRAINT [PK_T2_Constraint]
    drop table dbo.Table2
    END
    if
    Exists (select
    * from
    sys.all_objects
    where name =
    'Table1')
    BEGIN
    alter table dbo.Table1
    DROP CONSTRAINT [PK_T1_Constraint]
    drop table dbo.Table1
    END
    create
    Table dbo.Table1
    T1_PK        int
    NOT NULL
    Identity(1, 1)
    CONSTRAINT [PK_T1_Constraint]
    PRIMARY KEY (T1_PK),
    T1_Field1    varchar
    NULL,
    T1_Field2    varchar
    NULL,
    create
    Table dbo.Table2
    T2_PK        int
    NOT NULL
    Identity(1, 1)
    CONSTRAINT [PK_T2_Constraint]
    PRIMARY KEY (T2_PK),
    T2_Field1    varchar
    NULL,
    T2_Field2    varchar
    NULL,
    T2_FK        int
    NOT NULL
    CONSTRAINT [FK_T2_T1]
    FOREIGN KEY (T2_FK)
    REFERENCES dbo.Table1
    (T1_PK)
    create
    Table dbo.Table3
    T3_PK        int
    NOT NULL
    Identity(1, 1)
    CONSTRAINT [PK_T3_Constraint]
    PRIMARY KEY (T3_PK),
    T3_Field1    varchar
    NULL,
    T3_Field2    varchar
    NULL,
    T3_FK        int
    NOT NULL
    CONSTRAINT [FK_T3_T2]
    FOREIGN KEY (T3_FK)
    REFERENCES dbo.Table2
    (T2_PK)
    create
    Table dbo.Table4
    T4_PK        int
    NOT NULL
    Identity(1, 1)
    CONSTRAINT [PK_T4_Constraint]
    PRIMARY KEY (T4_PK),
    T4_Field1    varchar
    NULL,
    T4_Field2    varchar
    NULL,
    T4_FK        int
    NOT NULL
    CONSTRAINT [FK_T4_T3]
    FOREIGN KEY (T4_FK)
    REFERENCES dbo.Table3
    (T3_PK)
    GO
    --Create a basic view to select some data
    CREATE
    VIEW dbo.AliasView1
    AS
    select
    t2.T2_FK as Table2_ForeignKey,
    t1.T1_Field1 as Table1_FieldOne,
    t2.T2_Field1 as Table2_FieldOne
    FROM Table1 t1
    Left outer
    join Table2 t2 on t2.T2_FK
    = t1.T1_PK;
    GO
    --Create another view that select basic data, and also selecting data from view 1
    CREATE
    VIEW dbo.AliasView2
    AS
    select
    v1.Table1_FieldOne
    as Table1_FieldOne,     
    v1.Table2_FieldOne
    as Table2_FieldOne,  
    t3.T3_Field1 as Table3_FieldOne,
    t3.T3_Field2 
    FROM Table3 t3
    Left outer
    join AliasView1 v1 on v1.Table2_ForeignKey
    = t3.T3_PK;
    GO
    --My attempt to get the desired output, but no luck
    SELECT 
    col.COLUMN_NAME as AliasColumnName, col.DATA_TYPE, col.CHARACTER_MAXIMUM_LENGTH
    as max_length, colu.*
    FROM
    information_schema.COLUMNS col
    left
    outer join
    (SELECT 
    VIEW_SCHEMA, VIEW_NAME, COLUMN_NAME,
    min(TABLE_NAME)
    as TABLE_NAME
    FROM information_schema.VIEW_COLUMN_USAGE colu
    WHERE VIEW_NAME =
    'AliasView2'
    Group by VIEW_SCHEMA, VIEW_NAME, COLUMN_NAME
    ) COLU ON colU.VIEW_NAME
    = col.TABLE_NAME
    and colu.COLUMN_NAME
    = col.COLUMN_NAME
    left
    outer join
    (select a.name
    as TableName, c.name
    as FieldName
    from sys.foreign_key_columns fk
    join sys.all_objects a
    on a.object_id
    = fk.parent_object_id
    join sys.all_columns c
    on c.object_id
    = a.object_id
    and c.column_id
    = fk.parent_column_id
    join sys.all_objects ar
    on ar.object_id
    = fk.referenced_object_id
    join sys.all_columns cr
    on cr.object_id
    = ar.object_id
    and cr.column_id
    = fk.referenced_column_id
    join sys.schemas scr
    on scr.schema_id
    = ar.schema_id
    ) fks on fks.TableName
    = colu.TABLE_NAME
    and fks.FieldName
    = colu.COLUMN_NAME
    WHERE COL.TABLE_NAME
    = 'AliasView2'
    order
    by col.ORDINAL_POSITION
    This is the results being returned: (That is not 100% what I am looking for)
    AliasColumnName
    DATA_TYPE
    max_length
    VIEW_SCHEMA
    VIEW_NAME
    COLUMN_NAME
    TABLE_NAME
    Table1_FieldOne
    varchar
    1
    dbo
    AliasView2
    Table1_FieldOne
    AliasView1
    Table2_FieldOne
    varchar
    1
    dbo
    AliasView2
    Table2_FieldOne
    AliasView1
    Table3_FieldOne
    varchar
    1
    NULL
    NULL
    NULL
    NULL
    T3_Field2
    varchar
    1
    dbo
    AliasView2
    T3_Field2
    Table3
    The desired results must be like the following:
    AliasColumnName
    DATA_TYPE
    max_length
    VIEW_SCHEMA
    VIEW_NAME
    COLUMN_NAME
    TABLE_NAME
    Table1_FieldOne
    varchar
    1
    dbo
    AliasView2
    T1_Field1
    Table1
    Table2_FieldOne
    varchar
    1
    dbo
    AliasView2
    T2_Field1
    Table2
    Table3_FieldOne
    varchar
    1
    dbo
    AliasView2
    T3_Field1
    Table3
    T3_Field2
    varchar
    1
    dbo
    AliasView2
    T3_Field2
    Table3
    NOTE:  the COLUMN_NAME and TABLE_NAME must the REAL field of the TABLE it belongs to and not only ONE LEVEL Higher’s ALIAS View Name

    Now we have a lot of views which select data from the tables, but I need to get the "Table Column Name" that is linked in the view.
    If you are using SQL Server 2012/2014, then you can use
    sys.dm_exec_describe_first_result_set (Transact-SQL) to gte the informations.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Need help on getting the column names of Tabletype

    I have a table Mapping with the following values: This Mapping table contains the table names (in Tabname) and the column names(colname) of various tables and values(ValuesTobeFilled) for the columns.
    I have to insert into the tables present in the Tabname field with the values present in the ValuesTobeFilled in the columns present in the Colname field.
    Note: The Mapping table need not contain all the columns of the base table. The columns that are not present can be filled with null. And this mapping table is not fixed i.e. rows can be inserted/deleted frequently.
    Sample values in mapping table:
    Tabname                        Colname        ValuesTobeFilled
    sample_items     Eno     Corresponding Expression to get the values from XML input
    sample_items     Ename     Corresponding Expression to get the values from XML input
    XXX     YYY     Corresponding Expression to get the values from XML input
    Before filling in the actual tables, I have to store the entire data temporarily and I have used a tabletype declared as follows:
    TYPE T_sample_items IS TABLE OF sample_items%ROWTYPE INDEX BY BINARY_INTEGER;
    l_sample_items T_sample_items;
    Where the table sample_items have the following columns:
    •     Eno
    •     Ename
    •     Eaddress
    •     Eemail
    So, the tabletype should be filled as:
    Eno     Ename     Eaddress     EEmail
    1     XXX     -     -
    I have declared a cursor to select the values from mapping table and I need to fill in the ValuesTobeFilled values to the corresponding table.
    CURSOR c_xpath (c_tname mapping.TABNAME%type)
    IS
    select * from mapping where tabname = c_tname;
    CURSOR c_tables
    IS
    SELECT DISTINCT TABNAME FROM mapping;
    FOR crsr IN c_tables
    LOOP
    p_tname := CRSR.TABNAME;
    FOR csr IN c_xpath(p_tname)
    LOOP
    IF l_xml_doc.EXISTSNODE(CSR.XPATH_EXP) = 1
    THEN
    l_node_value := l_xml_doc.extract(CSR.XPATH_EXP).getStringVal(); -- This is the value to be stored in the corresponding column
    ELSE
         l_node_value := NULL;
    END IF;
    IF CSR.COLUMN_NAME = ‘eno’
    THEN
         l_sample_items(1).eno := l_node_value;
    ELSIF CSR.COLUMN_NAME = ‘ename’
    THEN
         l_sample_items(1).name := l_node_value;
    END IF;
    END LOOP;
    END LOOP;      
    And I need to eliminate hard coding while comparing the column names (in the following piece of code) as the Mapping table values are subject to insertion/deletion:
    IF CSR.COLUMN_NAME = ‘eno’
    THEN
         l_sample_items(1).eno := l_node_value;
    ELSIF CSR.COLUMN_NAME = ‘ename’
    THEN
         l_sample_items(1).ename := l_node_value;
    END IF;
    I need to insert the values directly into the tabletype without this hardcoding. Please suggest me ways to compare the mapping table values with the field (column) names of the tabletype. If it is not possible using tabletype, please suggest any other ways of fixing the problem.
    Many thanks,
    Gopi

    I take it this isn't going to be a serious production system at the end of the day?
    Storing metadata in tables for extraction and insertion of data is just wrong in so many ways. It smells heavily of Entity Attribute Value modelling, which is the most wrong way to use a relational database and is known to have major performance implications and be liable to bugs and issues. The idea that EAV modelling allows for 'generic' databases where new data items can be added flexibly later on without having to change code is usually justified with an excuse of "it means we don't have to update all our tables when we want a new column" which is easily countered with "if you're adding a single column a good relational design wouldn't require you to add it to more than one table anyway in most cases".
    Just what exactly are you trying to do and why? There has to be a better way.

  • Creating DOMDocument when column names are not known

    I want to make a DOMDocument from a table of which I do not know the column names.
    I already got pretty far: I could generate XML elements having the name of each of the columns.
    I still have a problem when trying to retrieve the cell values from the table.
    The code is below.
    The problem I have is situated after the line:
    /* QUESTION : HOW DO I REPLACE get_rows.label BY something dynamic, i.e. I want to use the value o col_name as the column name */
    I do not know how to retrieve the value from the table but by hardcoding the column name (i.e. get_rows.label where label is a column name). What I want to use is the VALUE of the variable col_name as the column name.
    Many thanks in advance.
    The code:
    set serveroutput on
    DECLARE
    doc xmldom.DOMDocument;
    main_node xmldom.DOMNode;
    root_node xmldom.DOMNode;
    row_node xmldom.DOMNode;
    user_node xmldom.DOMNode;
    item_node xmldom.DOMNode;
    root_elmt xmldom.DOMElement;
    row_elmt xmldom.DOMElement;
    item_elmt xmldom.DOMElement;
    item_text xmldom.DOMText;
    CURSOR DF_ROWS IS SELECT * FROM DF_COUNTRY;
    /* get the column names */
    CURSOR DF_COLUMNS IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'DF_COUNTRY';
    col_name varchar(20);
    cell_value varchar(40);
    BEGIN
    /* OPEN DF_COLUMNS; */
    /* create a DOM document and append a root element */
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode(doc);
    root_elmt := xmldom.createElement(doc, 'ROOT');
    root_node := xmldom.appendChild(main_node, xmldom.makeNode(root_elmt));
    /* loop over the records */
    FOR get_rows IN DF_ROWS LOOP
    row_elmt := xmldom.createElement(doc, 'ROW');
    /* xmldom.setAttribute(item_elmt, 'num', get_users_rec.rownum); */
    row_node := xmldom.appendChild(root_node, xmldom.makeNode(row_elmt));
    /* Now loop over all the columns (cells) and create an element for each of them */
    FOR get_columns IN DF_COLUMNS LOOP
    col_name := get_columns.COLUMN_NAME;
    DBMS_OUTPUT.PUT_LINE(col_name);
    item_elmt := xmldom.createElement(doc, get_columns.COLUMN_NAME);
    item_node := xmldom.appendChild(row_node, xmldom.makeNode(item_elmt));
    /* QUESTION : HOW DO I REPLACE get_rows.label BY something dynamic, i.e. I want to use the value o col_name as the column name */
    item_text := xmldom.createTextNode(doc, get_rows.label);
    item_node := xmldom.appendChild(item_node, xmldom.makeNode(item_text));
    END LOOP;
    END LOOP;
    xmldom.writeToFile(doc, 'C:\ClinCapt\Output\test.xml');
    xmldom.freeDocument(doc);
    END;

    I needed to manipulate the XML afterwoods (i.e. combine it with queries to other tables in a single large XML document).Did you try to combine all these subsequent queries into one single query and pass it to the XML packages to generate the XML all at once (instead of doing it in stages).
    SQL> select dbms_xmlquery.getxml('select dname,
      2                              cursor(select empno, ename
      3                                     from scott.emp
      4                                     where rownum < 3) employees
      5                              from scott.dept where rownum < 3') from dual ;
    DBMS_XMLQUERY.GETXML('SELECTDNAME,CURSOR(SELECTEMPNO,ENAMEFROMSCOTT.EMPWHEREROWN
    <?xml version = '1.0'?>
    <ROWSET>
       <ROW num="1">
          <DNAME>ACCOUNTING</DNAME>
          <EMPLOYEES>
             <EMPLOYEES_ROW num="1">
                <EMPNO>7369</EMPNO>
                <ENAME>SMITH</ENAME>
             </EMPLOYEES_ROW>
             <EMPLOYEES_ROW num="2">
                <EMPNO>7499</EMPNO>
                <ENAME>ALLEN</ENAME>
             </EMPLOYEES_ROW>
          </EMPLOYEES>
       </ROW>
       <ROW num="2">
          <DNAME>RESEARCH</DNAME>
          <EMPLOYEES>
             <EMPLOYEES_ROW num="1">
                <EMPNO>7369</EMPNO>
                <ENAME>SMITH</ENAME>
             </EMPLOYEES_ROW>
             <EMPLOYEES_ROW num="2">
                <EMPNO>7499</EMPNO>
                <ENAME>ALLEN</ENAME>
             </EMPLOYEES_ROW>
          </EMPLOYEES>
       </ROW>
    </ROWSET>
    SQL>                                                      

  • Criteria for choosing to create index on column?

    Hello,
    This maybe is a trivial question. I have been reading on performance tuning of SQL queries. What criteria is used to determine which column needs to have an index?
    If a query is as follows:
    Select * from table where column1=<value> and column2=<value> and column3=<value>;What is the criteria for choosing a particular column to be indexed?. Is it the column containing the higher number of unique rows so that index selectivity is high?
    Thanks

    For that particular query, an index on all three columns would be best. However, that's probably not the only query on that table, and you have to take them into account as well.
    What's the main use of your table? What functionality is used most or is most important? Design your index scheme to assist those queries if possible.
    If you have a book, would you use the index? If it's a technical reference book, or an encyclopedia, yes. If it's a novel you read from start to finish, probably not. And if you are reading the Oracle Concepts Manual and you want to search for the paragraphs containing the word "database", would you use an index? And if you search for the logwriter process (LGWR)? It's just about common sense in general: you'll want an index to be selective.
    Another side of the story is that indexes slow down inserts, deletes and updates, so you'll have to make a trade-off: is this penalty worth the speedup of a few queries?
    Regards,
    Rob.

  • Need suggestion on indexes

    I want to create some indexes on following table in Oracle 10G database.
    Table --> RegionalOrders
    Columns -->
    TenorderID -- PrimaryKey
    custid number(6) -- ForegionKey
    Empid number(6)-- ForegionKey
    Region (char(4)) -- ForegionKey
    Tencon varchar(20),
    Tensell varchar(20),
    Tendate date
    Following are some of heavy activties on this table :
    1) Ofter joins
    2) Joins mostly based on primary key and foreigh key
    I have following queries regarding indexes on this table.
    a) can you please suggest what columns I can index.
    b) There is not need to create index on TenorderID ( as its primary key)
    c) Can we create any indexes for table joins.

    I guess that will be not a very good approach to create indexes like this. If you have queries with you that you are going to write over this table and other table(s) ,looking at explain plan of them , it wil be more accurate to tell which column(s) should be indexed. Remeber , index based on a single query's performance are not of much use and will lead to more issues than benefits.
    You are correct in saying that PK column is not required to be indexed.Table join indexes or anything like that is not there,you can create indexes on underlying colums.
    HTH
    Aman....

  • Need To Create a Calculation

    Hi
    I am developing a discoverer report, I'm working with Oracle Discoverer 3.1 - User Edition, Version 3.1.26.01 (dce.dll 3.1.83) Oracle End User Layer 3.1.13.0.0.0
    I got a column (Open Time) with date and time "DD-Mon-YY HH:MI AM", and I need to create a New Column (Closed Time) as a calculation. The first Closed Time is one minute less than the second Open Time.
    And continue with the same procedure, Second Closed Time is one minute less than the third Open Time.
    The Queue Job Num. "90" is when the job is completed.
    Here is an example of the table:
    Id Num ----     Country ----- Tel Num ---------- Open Time ---------------- Closed Time ---------- Queue Job Num ---- Time In Queue Job
    ----1 ------------ PR ------ 7870502397 ---- 10/22/20074:56 PM ------------ ???? ------------------------- 56 ----------- (Open Time) - (Closed Time)
    ----1 ------------ PR ------ 7870502397 ---- 10/23/2007 8:50 AM ----------- ???? ------------------------- 26 ----------- (Open Time) - (Closed Time)
    ----1 ------------ PR ------     7870502397 ---- 10/24/2007 10:40 AM --------- ???? --------------------------76 ------------ (Open Time) - (Closed Time)
    ----1------------- PR ------     7870502397 ---- 10/26/2007 2:24 PM ----------- ???? ------------------------- 46 ----------- (Open Time) - (Closed Time)      
    ----1 ------------ PR ------     7870502397 ---- 10/26/2007 4:15 PM -----10/26/2007 4:15 PM ---------- 90
    I tried make a calculation,but I failed..
    Pls, help me out.
    Regards
    NVega54

    Thank you Nilesh, to try to help me.
    I don't have access to the database. I'm working with Oracle Discoverer 3.1 - User Edition, Version 3.1.26.01 (dce.dll 3.1.83) Oracle End User Layer 3.1.13.0.0.0. Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production.
    The only information that I have is the Open Time of each Queue Job Num. And I need to create a calculation to get the Closed Time of each Queue Job.
    The Closed Time in the first row is one minute less than the open time of the second row.
    Id Num ---------- Open Time ---------------- Closed Time ---------- Queue Job Num ---- Time In Queue Job
    ----1 -------- 10/22/20074:56 PM --------------- ???? ------------------------- 56 ----------- (Open Time) - (Closed Time)
    ----1 -------- 10/23/2007 8:50 AM -------------- ???? ------------------------- 26 ----------- (Open Time) - (Closed Time)
    ----1 -------- 10/24/2007 10:40 AM ------------ ???? --------------------------76 ------------ (Open Time) - (Closed Time)
    ----1--------- 10/26/2007 2:24 PM -------------- ???? ------------------------- 46 ----------- (Open Time) - (Closed Time)
    ----1 -------- 10/26/2007 4:15 PM ------10/26/2007 4:15 PM ------------ 90
    Thanks anyway for your help.
    NVega54

  • Create a derived column based on a value within the file name

    I am importing a CSV file which is easy enough, but I have an issue where I need to manufacture a couple of column values based on the filename of the input.  So this same process will import different types of records to the same table in sql server.
     I need to pull out the record code from the file name.  
    For instance, say I can use the same package to input two different CSV files.  One is named Input_M02_Data.csv and one named Input_B15_Data.csv.  I need to create a derrived column and store the record code there (i.e.:  M02 or B15) based
    on which file it came out of.  
    fyi-
    I also need to create a second column for Dept based off of the file name as well.  M02 is dept 45 and B15 is dept 99  which I also need to insert into this table when I import the data from the .csv file.  
    Any help is greatly appreciated!

    Hi Jason,
    According to your description, you want to add two derived columns based on the file name to also insert into table. One stores the value between two “_” within file name, another stores the department based on that column.
    If in this scenario, we can add a variable FileName that stores the filename, then add the two variables as derived columns like below in the Derived Column Transformation:
    Name:
    SUBSTRING(@[User::FileName],FINDSTRING(@[User::FileName],"_",1)+1,FINDSTRING(@[User::FileName],"_",2)-(FINDSTRING(@[User::FileName],"_",1)+1))
    Dept:
    @[User::Name] =="M02"?"dept 45":@[User::Name] =="B15"?"dept 99":"dept 00"
    The following screenshot is for your reference:
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    If you have any feedback on our support, please click
    here.
    Katherine Xiong
    TechNet Community Support

  • Tuning report by creating index.

    Hi...all,
    I try to tuning discoverer reports for getting better performance by creating index on columns that used to join
    between tables, but when I set join type to one to one relationship and outer join on detail in Discoverer Admin.,I found that index I created was not used in query (explain plan show full scan table).
    Anyone know how to solve this problem?
    Thank you,
    Vilas

    Hi,
    According to the documentation you will get this error when:
    Cause: The select clause referenced UID, USER, ROWNUM, SYSDATE, CURRENT_TIMESTAMP, MAXVALUE, a sequence number, a bind variable, correlation variable, a set result,a trigger return variable, a parallel table queue column, collection iterator, etc.
    Action: Remove the offending expression or disable the REWRITE option on the materialized view.
    You will probably find you have one of these expressions in your custom business area/folder.
    Rod West

  • How to select even the column names of a table?

    Hello All,
    Is there a way to select even the column names of a table in the select statement?
    My select from a table (say X) is in a SQL* Plus script that gets invoked by application tier and displays data in the application tier window. User's can then copy the data into a spreadsheet and do their processing. However, I need to give them the column names too along with the data.
    Thanks,
    Chiru

    If there is a middle tier that is selecting and
    displaying the data, and that's what the users are
    copying from, the middle tier would have to address
    its presentation of the data to allow users to
    include column names. If this is a common task, the
    application should probably be modified to give users
    the option of downloading the data in a spreadsheet
    directly rather than forcing them to copy and paste
    data.Thanks for the reply.
    The users don't have to copy paste. The application tier has an options in the "Tools" menu item which allows them to copy the entire output to a file (in my case a txt file which is a pipe delimited). Then they have to do text to columns to get the data into each column of the spreadsheet. I could have directly called the stored procedures from the application tier and created ".csv" files and FTP'd them to the user's folders. However, I am having to go this round about because, I am not getting enough support from the LAN team in FTP'ing etc.
    OK I'll think of another workaround.
    Thanks,
    Chiru

  • Please help me I am not seeing Database table column names in field explorer view

    Hi,
    I am developing a crystal report using eclipse and sql server. After creating connection, when i drag and drop tables, The table name and its columns should apper in field explorer view. Then we drag the columns onto crystal report. Unfortunately I am just  seeing only table names but not column names in field explorer view. Could anyone help me?
    After downloading eclipse I have plugged in the crystal report using the following instructions
    1. Click on the Help menu, and then Software Updates > Find and Install... to open the Install/Update wizard.
    2. Select Search for new features to install and click Next.
    3. Click the New Remote Site button. This will launch the New Update Site wizard
    4. Type the Business Objects Updsate Site for the Name field and the following for the URL: http://www.businessobjects.com/products/dev_zone/eclipse/
    5. Click OK to complete the wizard.
    6. Enable the newly created Business Objects Update Site checkbox as well as the Callisto Discovery Site (which should appear by default with Eclipse 3.2) and click Finish.
    Expand the Business Objects Update Site node and enable the Crystal Reports for Eclipse 1.0.0v555 checkbox.
    8. Expand the Callisto Discovery Site and click the button "Select Required". This will automatically select the required Eclipse features necessary to successfully install Crystal Reports for Eclipse.
    Thank You
    Rajavardhan Sarkapally

    Now we have a lot of views which select data from the tables, but I need to get the "Table Column Name" that is linked in the view.
    If you are using SQL Server 2012/2014, then you can use
    sys.dm_exec_describe_first_result_set (Transact-SQL) to gte the informations.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Dynamically Pass the Column Name cursor. || Dynamic Column Name

    Hi,
    I need to dynamically pass the column name based on a Mapping table in a loop ( Right now i have hardcoded stuff )just like using Execute immediate.... Inside the procedure, I have commented as where i hit the problem.
    Thanks for all of your time...
    Thanks
    Muthu
    CREATE OR REPLACE PROCEDURE xml_testing_clob AS
    doc xmldom.DOMDocument;
    main_node xmldom.DOMNode;
    root_node xmldom.DOMNode;
    user_node xmldom.DOMNode; item_node xmldom.DOMNode;
    root_elmt xmldom.DOMElement;
    item_elmt xmldom.DOMElement;
    item_text xmldom.DOMText;
    item_test xmldom.DOMText;
    nodelist xmldom.DOMNodeList;
    sub_variable varchar2(4000);
    x varchar2(200);
    y varchar2(200);
    sub_var varchar2(4000);
    CURSOR get_users IS
    SELECT FIRST_NAME,LAST_NAME,ROWNUM FROM USER_INFO_TBL WHERE WEIN_NUMBER = '1234' ;
    CURSOR get_cdisc_name IS
    select CTS_COL_NAME,CDISC_NAME from CTS2CDISC_DICTIONARY where CTS_TABLE_NAME = 'USER_INFO_TBL';
    BEGIN
    -- get document
    doc := xmldom.newDOMDocument;
    doc := xmldom.NewDomDocument;
    xmldom.setVersion(doc, '1.0');
    xmldom.setStandalone(doc, 'no');
    xmldom.setCharSet(doc, 'ISO-8859-1');
    -- create root element main_node := xmldom.makeNode(doc);
    root_elmt := xmldom.createElement(doc,'AdminData');
    root_node := xmldom.appendChild(main_node,xmldom.makeNode(root_elmt));
    FOR get_users_rec IN get_users LOOP
    item_elmt := xmldom.createElement(doc,'User');
    xmldom.setAttribute(item_elmt,'OID' , get_users_rec.rownum);
    user_node := xmldom.appendChild(root_node,xmldom.makeNode(item_elmt));
    FOR cv_get_cdisc_name IN get_cdisc_name LOOP
    EXIT WHEN get_cdisc_name%NOTFOUND;
    sub_var := cv_get_cdisc_name.cts_col_name;
    sub_variable := 'get_users_rec.';
    sub_variable := 'get_users_rec.'||cv_get_cdisc_name.cts_col_name;
    x := sub_variable;
    dbms_output.put_line(x); -------------- Here i just see the literal string
    y := get_users_rec.FIRST_NAME;
    dbms_output.put_line(y); -------------- Here i just see actual value ( data )
    item_elmt := xmldom.createElement(doc,cv_get_cdisc_name.cdisc_name);
    item_node := xmldom.appendChild(user_node,xmldom.makeNode(item_elmt));
    item_text := xmldom.createTextNode(doc,x ); ---- This is the place i am hitting with an error .
    If i use variable X then i am able to see only the literal
    string in the output. BUT if i put cursor name.coulmname,
    then the resumt (XML) is fine.I wanted acheive this
    dynamically just like execute Immediate
    item_node := xmldom.appendChild( item_node , xmldom.makeNode(item_text));
    END LOOP;
    END LOOP;
    -- write document to file using default character set from database
    xmldom.WRITETOCLOB(doc,);
    xmldom.writeToFile(doc, 'c:\ash\testing_out.xml');
    -- free resources
    xmldom.freeDocument(doc);
    END;
    +++++++++++++++++++++++++++++++++++ XML OUTPUT +++++++++++++++++++++++++++++++++++++++++
    <?xml version="1.0" ?>
    - <AdminData>
    - <User OID="1">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName> </User>
    - <User OID="2">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="3">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="4">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    - <User OID="5">
    <FirstName>get_users_rec.FIRST_NAME</FirstName>
    <LastName>get_users_rec.LAST_NAME</LastName>
    </User>
    ++++++++++++++++++++++++++++++++++++++++++++++++++++ MAPPING TABLE DETAILS +++++++++++++++++
    CTS_COL_NAME     CDISC_NAME     CTS_TABLE_NAME     XML_TAG     -----------> Column Name
    FIRST_NAME     FirstName     USER_INFO_TBL     Element     -----------> Records
    LAST_NAME     LastName     USER_INFO_TBL     Element     -----------> Records

    My scenario is little different, let me explain:
    My columns will remain same but values changes (based on column formula) according to the selected prompt value
    If I select 'Oct' from prompt then
    Curr will contain data for 'Oct' only
    Next1 will contain data for 'Nov' only
    Next2 will contain data for 'Dec' only
    Next3 will contain data for 'Jan' of next year only.
    Later if I select 'Jul' from prompt then
    Curr will contain data for 'Jul' only
    Next1 will contain data for 'Aug' only
    Next2 will contain data for 'Sep' only
    Next3 will contain data for 'Oct' only.
    I don't have different columns for each months but the columns are capable to reflect data for any month.
    So, how can I reflect the column name as month name for which that contains data.
    Regards,
    S Anand

  • Stored procedure to identify column names from a lookup table

    I have a working PL/SQL stored proc as below:
    CREATE OR REPLACE PROCEDURE PROC_TEST IS
    CURSOR GET_TEST_VALUES IS
    SELECT
    MF_master.comp_service_b,MF_master.normal_form_amount_b, MF_master.plan_id_b, MF_master.plan_percentage_b, MF_master.plan_service_b,MF_master.autoid,     ORA_master.comp_service_v, ORA_master.normal_form_amount_v,
    ORA_master.plan_id_v, ORA_master.plan_percentage_v,
    ORA_master.plan_service_v, ORA_master.autoid,     ORA_master.test_var     FROM MF_master, ORA_master
    WHERE ((MF_master.autoid = ORA_master.autoid));
    BEGIN
    FOR REC IN GET_TEST_VALUES LOOP
    begin
    if rec.test_var='SVC' then
    if (to_number(rec.plan_service_b) = to_number(rec.plan_service_v) ) and
    (to_number(rec.comp_service_b) = to_number(rec.comp_service_v) ) then
    update ORA_master set status_v = 'COMPLETE',last_updt_user_v = 'PROCEDURE',last_updt_date_v = SYSTIMESTAMP where autoid = rec.autoid;
    else
    update ORA_master set status_v = 'INCOMPLETE',last_updt_user_v = 'PROCEDURE',last_updt_date_v = SYSTIMESTAMP where autoid = rec.autoid;
    end if;
    end if;
    if rec.test_var = 'TERM' then
    if (to_number(rec.plan_percentage_b) = to_number(rec.plan_percentage_v) ) and
    (to_number(rec.normal_form_amount_b) = to_number(rec.normal_form_amount_v) )
    then
    update ORA_master set status_v = 'COMPLETE',last_updt_user_v = 'PROCEDURE',last_updt_date_v = SYSTIMESTAMP where autoid = rec.autoid;
    else
    update ORA_master set status_v = 'INCOMPLETE',last_updt_user_v = 'PROCEDURE',last_updt_date_v = SYSTIMESTAMP where autoid = rec.autoid;
    end if;
    end if;
         end;
         END LOOP;
         COMMIT;
    END;
    What I am doing here is, if test_var = 'SVC', I am comparing 2 columns, plan_service_b and comp_service_b(with plan_service_v and
    comp_service_v)
    Similarly, for test_var = 'TERM', it is plan_percentage_b and normal_form_amount_b(with plan_percentage_v and normal_form_amount_v)
    The above works fine as of now, but I am looking for a way to make this design more dynamic. In other words, these comparison columns may change from time
    to time and each time something changes, I will have to change this code. Rather, I am looking for a way to have the comparison columns in a
    lookup table that I can query to get what needs to be compared.
    My thought is :
    CREATE TABLE COMPARISON_COL_LOOKUP
    (test_var VARCHAR2(10),
    MF_column VARCHAR2(30),
    ORA_column VARCHAR2(30) );
    And then, insert
    INSERT INTO COMPARISON_COL_LOOKUP ('SVC','PLAN_SERVICE_B','PLAN_SERVICE_V');
    INSERT INTO COMPARISON_COL_LOOKUP ('SVC','COMP_SERVICE_B','COMP_SERVICE_V');
    INSERT INTO COMPARISON_COL_LOOKUP ('TERM','PLAN_PERCENTAGE_B','PLAN_PERCENTAGE_V');
    INSERT INTO COMPARISON_COL_LOOKUP ('TERM','NORMAL_FORM_AMOUNT_B','NORMAL_FORM_AMOUNT_V');
    commit;
    In this way, when tomorrow, when something changes - like new columns need to be compared for SVC or TERM, OR, if any comparisons need to
    be removed, all I need to do is to change the data in this lookup table !
    Now here's my question --- If I have this lookup table, how best can I update my above stored procedure to use this lookup table so that I don't need to
    hard-code the column names for comparison ?
    Any thoughts/suggestions are appreciated.

    While it is certainly technically possible to use dynamic SQL here, I would suggest that you make absolutely certain that you're not making things unnecessarily complicated...
    Dynamic SQL is generally substantially harder to write, debug, and maintain than equivalent static SQL. In addition, it takes a lot more work to ensure that dynamic SQL performs as well as static SQL (i.e. you now have to explicitly use bind variables) and that you're not introducing security holes via SQL injection.
    If your comparisons are likely to change infrequently, and particularly as those changes would imply changes to the underlying requirements, I would tend to be biased toward keeping the working procedure and just planning on making code changes periodically.
    Of course, not knowing your particular requirements, I certainly can't be certain that dynamic SQL would be inappropriate here, but I have seen lots of folks unnecessarily complicate their systems by building overly flexible systems that were painful to support and extend.
    Justin

  • How to get the column name and table name with value

    Hi All
    I have one difficult requirement
    I have some column values and they have given some alias column names but i need to find the correct column name and table name from the database.
    For example value is "SRI" and i dont know the table and exact column name so is there any possibilities to find the column name and table name for the given value
    Thanks & Regards
    Srikkanth.M

    Searching all the database for a word...
    Courtesy of michaels...
    michaels>  var val varchar2(5)
    michaels>  exec :val := 'as'
    PL/SQL procedure successfully completed.
    michaels>  select distinct substr (:val, 1, 11) "Searchword",
                    substr (table_name, 1, 14) "Table",
                    substr (t.column_value.getstringval (), 1, 50) "Column/Value"
               from cols,
                    table
                       (xmlsequence
                           (dbms_xmlgen.getxmltype ('select ' || column_name
                                                    || ' from ' || table_name
                                                    || ' where upper('
                                                    || column_name
                                                    || ') like upper(''%' || :val
                                                    || '%'')'
                                                   ).extract ('ROWSET/ROW/*')
                       ) t
    --        where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
           order by "Table"or
    11g upwards
    SQL> select table_name,
           column_name,
           :search_string search_string,
           result
      from (select column_name,
                   table_name,
                   'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
              from cols
             where table_name in ('EMP', 'DEPT')),
           xmltable (str columns result varchar2(10) path '.')
    TABLE_NAME                     COLUMN_NAME                    SEARCH_STRING                    RESULT   
    DEPT                           DNAME                          es                               RESEARCH 
    EMP                            ENAME                          es                               JAMES    
    EMP                            JOB                            es                               SALESMAN 
    EMP                            JOB                            es                               SALESMAN 
    4 rows selected.

Maybe you are looking for