Select ALL_TAB_COLUMNS

Hi all,
I got One Select Query as " SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = :tablename ".
But with this i am getting only ( OWNER, TABLE_NAME, COLUMN_NAME, DATATYPE).
But i want the following columns also:
(character maximum length, numeric scale, is nullable)
How to get this data also please ?
Thanks

try on TOAD like below
SELECT column_name,data_type,data_precision,data_length,nullable
FROM all_tab_columns
WHERE table_name = 'EMP'
i hope u may get wht u r expecting...

Similar Messages

  • Performace query on catalogues

    Hello,
    i've performance problems running the following query :
    SELECT ALL_TAB_COLUMNS.OWNER , ALL_TAB_COLUMNS.TABLE_NAME , SUBSTR(ALL_TAB_COLUMNS.COLUMN_NAME,1,30), DECODE(ALL_CONSTRAINTS.CONSTRAINT_TYPE,NULL,'N','P','Y','N') as PKEY FROM SYS.ALL_TAB_COLUMNS
    LEFT OUTER JOIN SYS.ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN SYS.ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME,
    SYS.ALL_TABLES
    WHERE ( ALL_TAB_COLUMNS.OWNER = ALL_TABLES.OWNER ) and ( ALL_TAB_COLUMNS.TABLE_NAME = ALL_TABLES.TABLE_NAME )
    AND ALL_TAB_COLUMNS.OWNER = 'MYOWNER'
    Can you help me?
    Thanks in advance
    Luigi

    I cutted ALL_TABLES that i can exclude from query (however ALL_TABLES was linked to ALL_TAB_COLUMNS)
    This is the resulting query :
    ====
    SELECT ALL_TAB_COLUMNS.OWNER, ALL_TAB_COLUMNS.TABLE_NAME , ALL_TAB_COLUMNS.COLUMN_NAME ,
    DATA_TYPE , DATA_LENGTH , DATA_PRECISION , DATA_SCALE , NULLABLE , DATA_DEFAULT, DECODE(ALL_CONSTRAINTS.CONSTRAINT_TYPE,NULL,'N','P','Y','N') as PKEY
    FROM ALL_TAB_COLUMNS
    LEFT OUTER JOIN ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONSTRAINTS.CONSTRAINT_TYPE = 'P' AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME
    WHERE ALL_TAB_COLUMNS.OWNER = 'USERNAME'
    =====
    I use this query to list all the accessible columns by USERNAME
    I need to know if column is a primary Key for the table
    ON the above mentioned query i still have performance problems !!!
    PS: I have tried to count records with the following query
    =====
    SELECT count(*)
    FROM ALL_TAB_COLUMNS
    LEFT OUTER JOIN ALL_CONS_COLUMNS ON
    ALL_TAB_COLUMNS.OWNER = ALL_CONS_COLUMNS.OWNER AND
    ALL_TAB_COLUMNS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND
    ALL_TAB_COLUMNS.COLUMN_NAME = ALL_CONS_COLUMNS.COLUMN_NAME
    LEFT OUTER JOIN ALL_CONSTRAINTS ON
    ALL_CONSTRAINTS.OWNER = ALL_CONS_COLUMNS.OWNER AND ALL_CONSTRAINTS.TABLE_NAME = ALL_CONS_COLUMNS.TABLE_NAME AND ALL_CONSTRAINTS.CONSTRAINT_TYPE = 'P' AND ALL_CONS_COLUMNS.CONSTRAINT_NAME = ALL_CONSTRAINTS.CONSTRAINT_NAME
    WHERE ALL_TAB_COLUMNS.OWNER = 'USERNAME'
    ======
    .... it needs more than 1 minutes !!!
    Best regards

  • NEED HELP IN USING ALL_TAB_COLUMNS FOR RETRIEVING DATA???

    A table say T1 contains column like Emp_id,Code.
    and there are several Code like C1,C2,C3.
    Another table say T2 contains column like
    Emp_id,C1,C2,C3.Here the value of the code field of the
    T1 table is now column of the T2 table.And the amount of
    each code of T1 table is equal to column value of T2
    table.
    Now I want to retrieve data from T2 table like
    C1 200
    C2 300
    C3 140
    I cannot retrieve data like this using all_tab_columns.
    I can only getting the column_name but cannot its value.
    PLEASE HELP ME...
    Edited by: user630863 on Apr 8, 2009 11:37 AM

    emp_id | code
    001 | C1
    001 | C2
    005 | C3
    005 | C1
    002 | C2
    002 | C3
    Table T1
    emp_id | C1 | C2 | C3
    001 | 10 | 15 |
    002 | | 7 | 12
    005 | 45 | | 94
    Table T2
    I have written a query
    select column_name from all_tab_columns a,T1 b
    where a.column_name=b.code
    and table_name='T2'
    OUTPUT:
    C1
    C2
    C3
    But I Need data for each employee like
    001 C1 10
    001 C2 15
    002 C2 7
    002 C3 12
    005 C1 45
    005 C3 94
    Edited by: user630863 on Apr 8, 2009 1:28 PM

  • Is it possible to view "all_tab_columns" entries in "user_tab_columns"?

    Good morning,
    I have here a SQL query that searches for entries in "user_tab_columns".
    Unfortunately the mentioned entries are not present there (but they are present in "all_tab_columns", but I also think that the query is correct.
    Therefore I wonder:
    is it possible to modify the database (using granting permissions, DB links or other) so that the mentioned entries in "all_tab_columns" also get visible in "user_tab_columns"?
    Thanks
    Dominique

    Hi, Dominique,
    You can create a private synonym called user_tab_columns that will stand for all_tab_columns
    CREATE SYNONYM user_tab_columns FOR sys.all_tab_columns;That means, whenever you say user_tab_columns, Oracle will understand you really want sys.all_tab_columns.
    If you need to reference the real user_tab_columns, then you can create another synonym like this:
    CREATE SYNONYM real_user_tab_columns FOR sys.user_tab_columns;This will affect only the user who creates the synonym. If you log in as DOMINIQUE, then anyone logged in as DOMINIQUE will be affected, but people who log in as SCOTT (for example) will not be. (Of course, SCOTT can also create a priovate synonym, which would only affect users logged in as SCOTT).
    Remember that sys.all_tab_columns and sys.user_table_columns are different. Something that was designed to work in user_tab_columns will not necessarily work in all_tab_columns. For example, a query that finds how many columns are in the emp table. If dominique.emp has 5 columns, then when dominique runs
    SELECT  COUNT (*)   AS total_columns
    FROM    user_tab_columns
    WHERE   table_name  = 'EMP';the answer will be 5, but if dominque has privileges on the scott.emp table, which has 8 columns, then the results of:
    SELECT  COUNT (*)   AS total_columns
    FROM    all_tab_columns
    WHERE   table_name  = 'EMP';will be 5 + 8 = 13, which is not the correct number of columns in either emp table.
    Edited by: Frank Kulash on Aug 11, 2011 12:46 PM
    Corrected typos

  • Accessing ALL_TAB_COLUMNS from a Procedure

    Hi,
    I want a help in Accessing ALL_TAB_COLUMNS from a procedure.
    I am an getting Error as Insufficient Privileges while Executing the Procedure.
    Any help will be Benefitial
    Thanks and Regards

    You should not really be using SYS.
    Is this a general issue with accessing "ALL_" views (i.e. information about other schemas than your own) within procedures? If so perhaps the account needs SELECT ANY DICTIONARY system privilege. although as with any system privilege you should consider the security implications.
    If it's specifically ALL_TAB_COLUMNS and not the rest of the dictionary views, then a grant on that view to the owner of the package will do it.

  • Getting error while executing this select statement

    Hi All,
    I am new to this community.
    I am getting error whie compiling the below code. Its telling 'Text' is invalid identifier. Also i want to know how can we obtain 'parseable' version of the below query?
    my basic intention is to create a trigger header through a select statement and show it the complete text as a single column..
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW'
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

    thanks prathamesh. it solved the problem. i have one more question.
    as of now it creates single create trigger statement for each column on a table.
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    however, i want to create trigger for all columns in a single statement. can you please help me how to do it?
    basically want to 'CREATE TRIGGER' for all columns in a table. i am finding difficult how to change my query to suit this!!
    i am pasting my original query again for your reference. pls advise...
    example:
    CREATE OR REPLACE TRIGGER ust_aud
    AFTER INSERT
    OR UPDATE
    OF cust_id,
    fixed_item_val,
    copy_item_val,
    rgn_id,
    txn_id,
    OR DELETE ON characteristic_t
    FOR EACH ROW
    ORIGINAL QUERY
    select text from
    (select 'CREATE OR REPLACE TRIGGER '||SUBSTR(column_name,2,4)||'aud
    AFTER INSERT
    OR UPDATE
    OF '||column_name||',
    OR DELETE ON '||table_name||'
    FOR EACH ROW' text
    FROM(SELECT lower(REPLACE(column_name,'O_','')) column_name , /*changing O to O_*/
    lower(replace(t.table_name,'_A_','_')) table_name,
    lower(t.table_name) table_name1,
    c.column_id
    FROM all_tab_columns c,
    (SELECT object_name table_name
    FROM all_objects
    WHERE object_name LIKE '%/_A/_%' ESCAPE '/') t
    WHERE c.table_name(+) = t.table_name
    AND SUBSTR(column_name(+),1,2) = 'O_'))

  • Form on a SQL Query - doesn't work with SELECT * - bug or feature ?

    When I do this,
    Create Page -> Page with Component -> Form -> Form on a SQL Query -> SELECT * FROM EMP
    I do not get any items displayed and it creates a simple HTML region / page. Do we have to necessarily specify the column names ?
    Iam looking at a way to see if any addition of columns in the table does not involve IT intervention in recreating the form.
    When we try to create with Form on a SQL Query, then shouldn't it be similar to the Report where the same thing works, if I give SELECT function_returning_columns() from DUAL even then the same thing happens where it creates an ITEM called functions_returning_columns() it creates HTML region
    I asked a related question with no answer :-( in
    Dynamic Creation of Items in Runtime through Application UI

    Hi Marc,
    Thanks. I just tried something like this. Taking the EMP table example, (it doesn't matter which table), I created a region based on a Pl/Sql function returning SQL query
    ( I selected the vertical report template including nulls to display it like a form ) :
    DECLARE
    v_sql VARCHAR2(3000) ;
    mn_idx NUMBER := 1 ;
    BEGIN
    v_sql := 'SELECT ' ;
    FOR recs IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMP' ORDER BY COLUMN_ID)
    LOOP
    v_sql := v_sql || 'HTMLDB_ITEM.TEXT(' || mn_idx || ',' ||
    recs.column_name || ') ' || recs.column_name || ', ' ;
    mn_idx := mn_idx + 1 ;
    END LOOP ;
    v_sql := SUBSTR(v_sql, 1, LENGTH(v_sql) -2) ;
    v_sql := v_sql || ' FROM EMP WHERE EMPNO = 7369 ORDER BY 1 ' ;
    RETURN v_sql ;
    END ;
    This allowed me to do my updates etc.., Then I created a button called 'Apply' and a process called 'update_changes' on button click and defined this:
    DECLARE
    v_sql varchar2(1000) ;
    mn_ctr NUMBER := 1 ;
    BEGIN
    v_sql := 'BEGIN UPDATE EMP SET ' ;
    FOR recs IN (select COLUMN_ID, COLUMN_NAME, DATA_TYPE
    from all_tab_columns where table_name = 'EMP'
    ORDER BY COLUMN_ID) loop
    -- Make changes here if required- this is assuming 9 columns --
    v_sql := v_sql || recs.column_name || ' = HTMLDB_APPLICATION.G_F0' || mn_ctr || '(1),' ;
    mn_ctr := mn_ctr + 1;
    end loop ;
    v_sql := substr(v_sql, 1, length(v_sql) - 1) ;
    v_sql := v_sql || ' WHERE EMPNO = 7369; END ;' ;
    execute immediate (v_sql) ;
    END ;
    Since this is for example, I didn't include code for Checksum and hardcoded empno = condition and have provision for 9 columns. I made some changes and tried saving it and I was able to do it.
    I altered the table to add a column / drop a column and when I relogin, Iam able to see the changes.
    Can you tell me if there could be any drawbacks in this approach ?.

  • Duplicates in all_tab_columns

    I have found duplicates in the all_tab_columns data dictionary view, where both rows have the same owner, table_name, and column_name, but have different column_id and one row shows the column as nullable and the other row shows the column as not nullable. However, only one such entry exists in the user_tab_columns data dictionary view. Is there any rational explanation for this or is corruption the only possibility?
    The database in question is used for development and testing and is periodically modified to match the production database. I know that one of the DBA's has been using TOAD to do this, but I don't know what the exact process has been and he is on vacation at the moment.
    This problem exists in multiple tables and multiple columns. In each case, the columns in question were formerly part of a primary key, but that has been changed so that the primary key now uses other columns.
    Below is just one small example that shows the duplicates in all_tab_columns, but not in user_tab_columns.
    Barbara Boehmer
    SQL*Plus: Release 8.0.6.0.0 - Production on Wed Mar 12 23:57:07 2003
    (c) Copyright 1999 Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.0.0 - Production
    SQL> SELECT      table_name, column_name, column_id, nullable
      2  FROM        all_tab_columns
      3  WHERE       user = USER
      4  AND         table_name = 'ADDRESSES'
      5  AND         column_name = 'ADDR__EVNT_SEQ'
      6  /
    TABLE_NAME                     COLUMN_NAME                    COLUMN_ID N
    ADDRESSES                      ADDR__EVNT_SEQ                        39 Y
    ADDRESSES                      ADDR__EVNT_SEQ                         4 N
    SQL> SELECT      table_name, column_name, column_id, nullable
      2  FROM        user_tab_columns
      3  WHERE       user = USER
      4  AND         table_name = 'ADDRESSES'
      5  AND         column_name = 'ADDR__EVNT_SEQ'
      6  /
    TABLE_NAME                     COLUMN_NAME                    COLUMN_ID N
    ADDRESSES                      ADDR__EVNT_SEQ                        39 Y

    Barbara, in your all_tab_columns query, you have put a condition 'user = USER'.
    I think you meant to say 'owner = USER'. If you add owner to the result set, the two rows should have different owners.
    barryt> create table addresses (addr__evnt_seq int not null);
    Table created.
    barryt> grant select on addresses to rms;
    Grant succeeded.
    barryt> @connect
    rms> create table addresses (dummy int not null, addr__evnt_seq int);
    Table created.
    rms> select table_name, column_name, column_id, nullable   
    2    from all_tab_columns   
    3   where user = USER  -- applies no filter 
    4     and table_name = 'ADDRESSES'   
    5     and column_name = 'ADDR__EVNT_SEQ';
    TABLE_NAME                     COLUMN_NAME                    COLUMN_ID N
    ADDRESSES                      ADDR__EVNT_SEQ                         2 Y
    ADDRESSES                      ADDR__EVNT_SEQ                         1 N
    2 rows selected.
    rms> select owner, table_name, column_name, column_id, nullable   
    2    from all_tab_columns   
    3   where table_name = 'ADDRESSES'   
    4     and column_name = 'ADDR__EVNT_SEQ';
    OWNER                          TABLE_NAME
    COLUMN_NAME                    COLUMN_ID N
    RMS                            ADDRESSES
    ADDR__EVNT_SEQ                         2 Y
    BARRYT                         ADDRESSES
    ADDR__EVNT_SEQ                         1 N
    2 rows selected.
    rms> select table_name, column_name, column_id, nullable   
    2    from all_tab_columns 
    3   where owner = USER 
    4     and table_name = 'ADDRESSES'   
    5     and column_name = 'ADDR__EVNT_SEQ';
    TABLE_NAME                     COLUMN_NAME                    COLUMN_ID N
    ADDRESSES                      ADDR__EVNT_SEQ                         2 Y
    1 row selected.
    rms> select table_name, column_name, column_id, nullable   
    2    from user_tab_columns 
    3   where table_name = 'ADDRESSES'   
    4     and column_name = 'ADDR__EVNT_SEQ';
    TABLE_NAME                     COLUMN_NAME                    COLUMN_ID N
    ADDRESSES                      ADDR__EVNT_SEQ                         2 Y

  • Using table name from user_tab_columns in a select

    Hi all,
    I need to generate a list of tables that contain rows in a certain condition. For the real situation there are hundreds of tables so I've been trying to use all_tab_columns in the query to generate the list of tables to search and then delimit by condition.
    e.g.
    create table adam1
    adamname char(10)
    create table adam2
    adamname char(10)
    insert into adam1 values ('ADAM');
    insert into adam1 values ('BOB');
    insert into adam2 values ('BOB');
    ...I'd like to see a list of tables that contain 'ADAM' in column 'adamname' so in this instance I'd only see table adam1 in the results.
    I've tried using a cursor loop but it doesn't like me using table_name ... do I have to bring this into a variable or some such?
    Thanks!
    Adam

    Try this:
    CREATE OR REPLACE
    FUNCTION ADAM_TABLES( I_COLNAME IN VARCHAR2, I_VALUE IN VARCHAR2 )
    RETURN str_table PIPELINED
    IS
      CURSOR L_CUR IS
          SELECT c.OWNER, c.TABLE_NAME, c.DATA_TYPE
          FROM ALL_TAB_COLUMNS C
          JOIN ALL_OBJECTS O
          ON (C.OWNER = O.OWNER AND c.table_name = o.object_name )
          WHERE COLUMN_NAME = I_COLNAME AND DATA_TYPE LIKE '%CHAR%'
                AND o.object_type = 'TABLE';
      L_owner     ALL_TAB_COLUMNS.owner%TYPE;
      L_TABLENAME ALL_TAB_COLUMNS.TABLE_NAME%TYPE;
      L_DATATYPE  ALL_TAB_COLUMNS.DATA_TYPE%TYPE;
      L_RET NUMBER := 0;
      l_sql varchar2(32000);
      TABLE_NOT_EXISTS EXCEPTION ;
      PRAGMA EXCEPTION_INIT( TABLE_NOT_EXISTS, -00942 );
    BEGIN
      OPEN l_cur;
      LOOP
          FETCH L_CUR INTO l_owner, l_tablename, l_datatype;
          EXIT WHEN L_CUR%NOTFOUND;
          L_SQL :=  q'{SELECT 1 FROM DUAL
                       WHERE EXISTS (
                            SELECT 1 FROM }';
          L_SQL := L_SQL || l_owner || '.' || l_tablename || ' WHERE ';
          -- for CHAR, NCHAR etc. we must trim spaces from column
          -- before compare it with VARCHAR2 in WHERE condition
          IF l_datatype LIKE '%CHAR'
          THEN
              l_sql := l_sql || ' trim( ' || i_colname || ' ) ';
          ELSE
              l_sql := l_sql || i_colname ;
          END IF;
          l_sql := l_sql || ' = :val ) ';
          BEGIN
              EXECUTE IMMEDIATE l_sql INTO L_RET USING I_VALUE ;
              -- found data
              PIPE ROW ( l_owner || '.' || l_tablename );
          EXCEPTION
             WHEN NO_DATA_FOUND THEN
                  NULL;
             WHEN  TABLE_NOT_EXISTS THEN
                 RAISE_APPLICATION_ERROR( -20100, 'Table ' || l_owner ||'.' || l_tablename ||
                          ' does not exist or you have not SELECT privilege on this table.' );
          END;
      END LOOP;
      CLOSE L_CUR;
      RETURN;
    EXCEPTION
      WHEN OTHERS THEN
          IF L_CUR%ISOPEN THEN
             CLOSE L_CUR;
          END IF;
          RAISE;
    END;
    select * from table ( adam_tables( 'ADAMNAME',  'ADAM' ) );
    COLUMN_VALUE                  
    TEST.ADAM1  
    select * from table ( adam_tables( 'FIRST_NAME',  'Donald' ) );
    COLUMN_VALUE                  
    HR.EMPLOYEES                  
    HR.EMPLOYEES2  

  • DATA_DEFAULT In ALL_TAB_COLUMNS...

    Hi all,
    I'm working in an existing codebase (VB.Net) that is using an Oracle Database. One of the things the application is doing is getting a copy of the default value for the different columns. It looks something like this:
    If Not String.IsNullOrEmpty(myRow(0).Item("Data_Default").ToString) Then
    myCol.DefaultValue=myRow(0).Item("Data_Default").ToString
    End If
    That Data_Default value is being populated from the ALL_TAB_COLUMNS table; using a DataAdapter.Fill statement.
    Currently, the system is using a stored procedure, and inside that stored proc we're converting the DATA_DEFAULT column (which is a LONG) into a VARCHAR2. If that conversion doesn't happen, and we simply include the DATA_DEFAULT column in our SELECT statement, the datatable that the adapter fills will have a value of 'NULL' for DATA_DEFAULT in each and every row.
    This conversion takes a long time. Doing the query without the conversion in PL/SQL takes .2 seconds. Doing the conversion takes *40* seconds. That's 200x as long!
    I'm certain that something is being done incorrectly here. Can someone let me know where I've gone wrong? I just feel like there has to be a better way to do this; but I'm not sure what.

    First - I want to apologize for asking such a silly question.
    Second - I'll respond in the hopes that someone else with my question will find this on google and save himself the embarassment.
    By default, when you perform a SELECT and pull back a LONG, you get the first 0 bytes of it. You get nothing. That's why, when I filled my datatable it was always null.
    What you want to do (instead of all this on the fly conversion crap I was doing) is simply tell Oracle to give you more than 0 bytes for each long.
    cdLookup = New Oracle.DataAccess.Client.OracleCommand
    cdLookup.InitialLONGFetchSize = 500
    Nice and simple; problem solved. Sorry again!

  • Raw Values in all_tab_columns (8i)

    I want to retreive Low_value and High_value from all_tab_columns. These fields use the raw datatype. How do I convert them to a decimal number. I am using Oracle 8i.
    Thanks,
    Les Smith

    Hi,
    Thanks everyone who replied to my question. I found the stats table created by the DBMS_STATS package would store the low_value and high_value in a decimal format. I used the DBMS_STATS.EXPORT_TABLE_STATS procedure to take the system statistics and place them in a user stats table.
    Here is the approach I took:
    DECLARE
    BEGIN
    --CREATE A USER TABLE TO HOLD THE STATISTICS
    DBMS_STATS.CREATE_STAT_TABLE (
    'ADW',
    'STATS_TAB');
    --RUN STATS TO POPULATE SYSTEM STAT TABLE
    SYS.DBMS_STATS.GATHER_TABLE_STATS (
    'ADW',
    'MSF');
    DBMS_STATS.EXPORT_TABLE_STATS (
    ownname => 'ADW',
    tabname => 'MSF',
    stattab => 'STATS_TAB');
    END;
    SELECT
    C4 AS COLUMN_NAME,
    N1 AS NUM_DISTINCT,
    N5 AS NUM_NULLS,
    N6 AS LOW_VALUE,
    N7 AS HIGH_VALUE,
    N8 AS AVG_COL_LENGTH
    FROM STATS_TAB
    WHERE TYPE ='C'

  • How to concatenage text to data_default col of all_tab_columns.

    Hi,
    i want to concatinate text to a columen like this but it is show error ,so i thought to convert it but could not get correct code.
    select 'dff' || data_default || 'df' from all_tab_columns
    yours sincerley

    Hi,
    data default is a LONG datatype. You cannot convert it straight away to VARCHAR2.
    I would suggest you to have a look at this: Ask Tom: Long to Varchar2 conversion.
    In the same page Tom has put an example about getting default value for columns:
    ops$tkyte%ORA11GR2> create or replace function get_col_default
      2  (
      3  p_owner in all_tab_cols.owner%type,
      4  p_table_name in all_tab_cols.table_name%type,
      5  p_column_name in all_tab_cols.column_name%type
      6  )
      7  return varchar2
      8  as
      9          l_data_default LONG;
    10  begin
    11          select data_default into l_data_default
    12            from all_tab_cols
    13           where owner = p_owner
    14             and table_name = p_table_name
    15             and column_name = p_column_name;
    16 
    17          return substr( l_data_default, 1, 4000 );
    18  end;
    19  /
    Function created.
    ops$tkyte%ORA11GR2>
    ops$tkyte%ORA11GR2> column d format a20
    ops$tkyte%ORA11GR2> select owner, table_name, column_name, get_col_default( owner, table_name,
    column_name ) d
      2    from all_tab_cols
      3   where get_col_default( owner, table_name, column_name ) is not null
      4     and rownum <= 5
      5  /
    OWNER                          TABLE_NAME                     COLUMN_NAME                    D
    SYS                            HS$_PARALLEL_METADATA          PARALLEL                       'Y'
    SYS                            HS$_PARALLEL_METADATA          PARALLEL_DEGREE                4
    SYS                            HS$_PARALLEL_METADATA          RANGE_PARTITIONED              'N'
    SYS                            HS$_PARALLEL_METADATA          SAMPLED                        'N'
    SYS                            HS$_PARALLEL_METADATA          HISTOGRAM                      'N'Regards.
    Al

  • Want to construct insert statement from all_tab_columns

    I am using Oracle 10GR2 and a new user for plsql
    I want to write a plsql block or SQL in order to insert some dummy data.
    I want to use the column list from all_tab_columns and want to construct insert statement
    EX: I am trying to construct SQL as below
    for i in (select column_name from all_tab_columns where table_name='EMP')
    loop
    v_sql := insert into emptest valuesi.column_name
    could you please let me know any pointer for the same ..?
    can I use any other technique for the same .. like collection, nested table etc

    Am not clear for this requirement, if possible could you please elaborate.
    Also specify the requirement, inputs and expected outputs with your query in code format...
    This will help..

  • AFTER ALTER ON SCHEMA TRIGGER + all_tab_columns

    Hi everybody,
    I'm trying to get the column name of any column added to the table "TEST", So I create a trigger to ensure that job.
    My problem is that the view "all_tab_columns" doesn't contain the column "column_test " yet when the trigger audit_ddl_trg is executed.
    Please Help me to resolve this problem
    CREATE TABLE TEST(id varchar2(10));
    -- add a column to the Table "TEST"
    alter table TEST add column_test varchar2(10);
    -- column_test not detected !!?
    CREATE OR REPLACE TRIGGER audit_ddl_trg AFTER ALTER ON SCHEMA
    DECLARE
    col_name varchar2(30);
    BEGIN
    IF (ORA_DICT_OBJ_TYPE = 'TABLE' AND ora_dict_obj_owner = 'OP' AND ORA_DICT_OBJ_NAME = 'TEST') THEN
    FOR col_name IN (SELECT column_name FROM all_tab_columns WHERE owner = 'OP') LOOP
    DBMS_OUTPUT.PUT_LINE('Column : ' || col_name);
    END LOOP;
    END IF;
    END;
    Thanks In Advance ;)
    Edited by: 909366 on Jan 26, 2012 1:22 AM
    Edited by: 909366 on Jan 26, 2012 1:57 AM

    True, you can declare PROC_REPLACE_TRIGGER as an autonomous transaction. That would allow you to commit. But then your autonomous transaction won't be able to see any of the changes being made in the triggering transaction, including the new column.
    As has been said before, you really only have one option. Your schema trigger needs to use DBMS_JOB to schedule a job. That job would call PROC_REPLACE_TRIGGER some time shortly after the triggering DDL transaction commits. You would not want to declare PROC_REPLACE_TRIGGER as an autonomous transaction in that approach.
    I still have reservations about the architecture that would require something like this. If you're doing DDL, presumably it's part of a build. The call to PROC_REPLACE_TRIGGER should be part of the build script (assuming it really makes sense to recreate triggers dynamically), not something that is called by a trigger.
    Justin

  • USER_TAB_COLUMNS and ALL_TAB_COLUMNS

    Dear Experts,
    I'm logged on a schema called Product with a user having the following rights:
    - Create Session
    - Select any sequence
    - Select any table
    If I perform a select on USER_TAB_COLUMNS I don't get any row returned but I do get results if I perform a select on ALL_TAB_COLUMNS. I can these two tables are SYS and select is granted to PUBLIC on both.
    So I don't undestand why I don't get a result from USER_TAB_COLUMNS. Any clue ?
    Thanks for any help.
    BR,
    Jerome.

    USER_TAB_COLUMNS will only show columns in tables owned by the current user - PRODUCT. Tables owned by SYS will not be visible to PRODUCT in the USER view, only in the ALL view.

Maybe you are looking for

  • MacBook won't load past the white startup screen.

    I'm going to start off by saying I'm a huge idiot. My MacBook was being sluggish last night, so I (impatiently) force-turned it off. Whenever I turn it back on, I get stuck at the white screen for about 10 minutes and the Apple logo never loads. I mu

  • Idoc numbers for a certain output in Sales Orders

    I have more than hundred Sales Order One EDI output was triggered (with a unique partner type) from each of these Sales Orders. How to find idoc numbers for all these Sales Order for this particular output? I tried WE09 giving Segment and field with

  • Help My Macbook Pro 13in keeps freezing!

    I brought it a week ago (30/07/12), moved all my music across via homeshare on itunes. Theres 14.37gb of music on here, and about 20 photos. I've also downloaded adblock, java and divx. I'll be on safari with itunes on in the background playing music

  • Aperture 2.0 doesn't show all of iPhoto library

    The first time I pulled up the iPhoto browser within Aperture, it didn't find any of my photos and then after a few minutes, it finally loaded in about half of my events. So not only is it showing an incomplete view of my iPhoto library, but I also c

  • How to start dataguard

    I want to learn data guard.Where should i start? Kindly suggest some good books with hands on exercise. oracle 11g