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.

Similar Messages

  • Difference between user_tab_columns and all_tab_columns

    Hi,
    Can anybody please let me know what are the differeneces between user_tab_columns and all_tab_columns.
    Thank you.

    Hi,
    In addition to sybrand_b information
    ALL_TAB_COLUMNS is a view that has an entry for every column of every table of every users schema, describes the columns of the tables, views, and clusters accessible to the current user
    USER_TAB_COLUMNS is a view that has an entry for every column of every table in a certain user's schema. When you use desc on a table to show the columns of that table the order of the columns shown is determined by the position that you can see when you look at the column_id in all_tab_columns and/or user_tab_columns. The DBA may change the order of these columns. It is very important not to assume that the columns are in a certain order and will stay that way, describes the columns of the tables, views, and clusters owned by the current user. Its columns (except for OWNER) are the same as those in "ALL_TAB_COLUMNS
    :)

  • Dba_tab_columns and all_tab_columns

    HI
    AIX 5.3
    oracle 10.2.0.3
    which view should be accessible to developers dba_tab_columns or all_tab_columns? and why?
    also dba_* and all_*
    Thanks,
    vishal

    ALL_* - displays all the information accessible to the current user, including information from the current user's schema as well as information from objects in other schemas, if the current user has access to those objects by way of grants of privileges or roles.
    DBA_ view displays all relevant information in the entire database. DBA_ views are intended only for administrators. They can be accessed only by users with the SELECT_ANY_TABLE privilege. (This privilege is assigned to the DBA role when the system is initially installed.)
    USER_ view displays all the information from the schema of the current user. No special privileges are required to query these views
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1001.htm#i1572007
    http://download-uk.oracle.com/docs/cd/A97630_01/server.920/a96536/ch2.htm
    HTH
    -Anantha

  • ISQL help

    how can I search a table name in iSQL plus. I have a column name and want to know from which table it is. What wil b the Query

    look at the user_tab_columns and all_tab_columns data dictionary views

  • All_tab_columns and all_tab_cols

    Hey guys,
    I've come across this problem, what can I do? I know what all_tab_cols and all_tab_columns are supposed to have information about all the tables in the database and that they're very useful.
    The problem is, all_tab_cols will show that a certain tables exists, or that a certain column belongs to a table. When I try to query that table directly I get a message saying the table or column don't exist.
    For example,
    If I execute the following:
    select table_name, column_name from all_tab_cols
    where owner='ME' and table_name = 'THE_TABLE_I_WANT'
    then I get this response:
    table_name - column_name
    THE_TABLE_I_WANT - first_column
    THE_TABLE_I_WANT - second_column
    THE_TABLE_I_WANT - third_column
    Then suppose I do the following:
    select first_column from THE_TABLE_I_WANT
    An error shows up saying that the column doesn't exist.
    This happens with whole tables as well, where the table will show up in the all_tab_columns table but can't be queried directly with a select *.
    What can cause this and how can I get accurate information from all_tab_columns/all_tab_cols??

    user11764599 wrote:
    Hey guys,
    I've come across this problem, what can I do? I know what all_tab_cols and all_tab_columns are supposed to have information about all the tables in the database and that they're very useful.
    The problem is, all_tab_cols will show that a certain tables exists, or that a certain column belongs to a table. When I try to query that table directly I get a message saying the table or column don't exist.
    For example,
    If I execute the following:
    select table_name, column_name from all_tab_cols
    where owner='ME' and table_name = 'THE_TABLE_I_WANT'
    then I get this response:
    table_name - column_name
    THE_TABLE_I_WANT - first_column
    THE_TABLE_I_WANT - second_column
    THE_TABLE_I_WANT - third_column
    Then suppose I do the following:
    select first_column from THE_TABLE_I_WANT
    An error shows up saying that the column doesn't exist.
    This happens with whole tables as well, where the table will show up in the all_tab_columns table but can't be queried directly with a select *.
    What can cause this and how can I get accurate information from all_tab_columns/all_tab_cols??Do you have SELECT privileges against THE_TABLE_I_WANT?

  • How do I obtain column names and types?

    I am using Visual Studio C++ to connect and query an Oracle database using SQL commands. My code works, but I don't fully understand it because I'm new to Oracle and it is modified example code.
    I need to obtain column names and types for a known table. The "Describe" SQL command fails when I call ->Execute, claiming this is an invalid SQL statement, although the same statement works when sent directly via sqlplus.
    I need column names and types, but they don't have to come through Describe.

    Hi,
    Desc isn't really a SQL command. Rather its a command specific to Oracle. Thats why it will work in SQLPlus and not anywhere else. If you want the column information for a table you can user either the user_tab_columns or all_tab_columns, depending on which schema the table is in. The query would look like:
    select * from all_tab_columns where table_name = 'BONUS'
    Sanjay

  • Finding column count with dynamic columns and dynamic tables

    I've done some PL/SQL for awhile now but was trying to devise a solution for the following problem:
    I wish to find the number of times a specific value for a column exists in all the tables that contain the field and I have access to see with the current user. The column name and value will be passed in via parameters.
    I was hoping to use something like
    select table_name from all_tab_columns where column_name = <variable table name>;
    then use the results from this to create a select statment based off the tables from the select above. I know the difference between dba_tab_columns and all_tab_columns - I want to make sure that I only retrieve the values i have access to.
    Can anyone point me to some guide / website / reference material I can read to catch up on the idea of creating this statment?
    Thank you.

    Hi,
    it's a test version.
    You can naturally tune it, but it seemed to work:
    declare
    pi_column VARCHAR2(30) := 'DEPTNO';
    pi_value VARCHAR2(4000) := '20';
    v_count NUMBER := 0;
    v_count_tab NUMBER;
    BEGIN
    FOR I IN (select owner, table_name from dba_tab_columns
              where column_name = pi_column
    LOOP
        EXECUTE IMMEDIATE 'SELECT count(*) FROM '||i.owner||'.'||i.table_name||
                          ' WHERE '||pi_column||' = :pi_value'  INTO v_count_tab USING pi_value; 
        v_count := v_count + v_count_tab;
    END LOOP;                   
    dbms_output.put_line(v_count);
    END;Regards

  • Find table name and constraint type based on field name

    I have a field or column name with me...I want to find the table name for which it is a primary key...Any query to do this job so that the execution costs are low...
    Currently i have to mix dba_constraints and ALL_TAB_COLUMNS to get this...any way to fetch the data from a single table/anyother cost effective process is appreciated

    Why are you using dynamic SQL? Just place it as static SQL in your PL/SQL code. Simply like this
    select table_name
       into ..
      from (
              select cc.column_name
                   , cc.table_name
                   , count(cc.column_name) over(partition by c.constraint_name) column_count
                from user_constraints c
                join user_cons_columns cc
                  on c.constraint_name = cc.constraint_name
               where constraint_type = 'P'
    where column_count = 1
       and column_name  = p_name;
    And in some case (Not this one) if you have to use dynamic SQL you need to pass your variables are bind variables to your SQL. You should not be appending it in the string. That's a very bad thing to do. Your code will be going for hard parse, your code will be exposed to SQL Injection. With your SQL this is how you use bind variable.
    execute immediate
    q'[
        select table_name 
          from (
                  select cc.column_name
                       , cc.table_name
                       , count(cc.column_name) over(partition by c.constraint_name) column_count
                    from user_constraints c
                    join user_cons_columns cc
                      on c.constraint_name = cc.constraint_name 
                   where constraint_type = 'P'
         where column_count = 1
           and column_name  = :1
    using p_name
    into <your_variable>;
    And finally to exactly tell why your code is failing, You have not use sing quotes to enclose your p_name that you are appending to your code. Following would fix the error.
    DO NOT USE IT IN ANY CASE. ITS WRONG ALWAYS!!
    'select table_name  from '||' (
              select  cc.column_name,cc.table_name, count(cc.column_name) over(partition by c.constraint_name) column_count
                from user_constraints c join user_cons_columns cc
                  on c.constraint_name = cc.constraint_name  where constraint_type = ''P'') '||
    ' where column_count = 1 and column_name = '''|| p_name || '''';
    AGAIN NEVER WRITE A CODE AS SHOWN ABOVE.

  • Using PL/SQL to retrieve column names and column values

    If I have a table as follows
    Table A(
    meal varchar2(32),
    beverage varchar2(32),
    desert varchar2(32));
    and the table contains a row
    meal beverage desert
    pork chops iced tea apple crisp
    Is there a way in pl/sql to retrieve the column names along with the values. I have an object type
    DATA_DEFINITION_T AS OBJECT (
              "FIELD_NAME"          VARCHAR2(32),
              "FIELD_VALUE" VARCHAR2(32)
    I need to store the column name in field_name and the column value in field_value.
    So the result would be:
    FIELD_NAME = meal
    FIELD_VALUE = pork_chops
    FIELD_NAME = beverage
    FIELD_VALUE = iced tea
    FIELD_NAME = desert
    FIELD_VALUE = apple crisp
    Thanks in advance.

    Hi,
    try this procedure ....just create it and give the table name..the object M_DATA_TAB has the required data
    procedure l_fill_data_dict(p_table_name varchar2) is
    connection_id EXEC_SQL.CONNTYPE;
    bIsConnected BOOLEAN;
    cursorID EXEC_SQL.CURSTYPE;
    nIgn PLS_INTEGER;
    m_val VARCHAR2(40);
    m_col_name varchar2(40);
    m_col_val varchar2(240);
    m_cnt number;
    m_id number := 0;
    m_incr number := 0;
    p_sqlstr varchar2(4000);
    p_sql_cnt varchar2(4000) ;
    p_org_sql varchar2(4000);
    TYPE DATA_DEFINITION_TABS IS RECORD (
    FIELD_NAME VARCHAR2(32),
    FIELD_VALUE VARCHAR2(240));
    TYPE DATA_DEFINITION_TAB IS TABLE OF DATA_DEFINITION_TABS;
    M_DATA_TAB DATA_DEFINITION_TAB := DATA_DEFINITION_TAB();
    --m_file text_io.file_type;
    Begin
    --     m_file := text_io.fopen('c:\eg.txt','w');
         --Set default connection
    connection_id := EXEC_SQL.DEFAULT_CONNECTION;
    bIsConnected := EXEC_SQL.IS_CONNECTED;
    IF bIsConnected = FALSE THEN
         message('Connection Failed');
    RETURN;
    END IF;
    --Find the total no.of columns in the given table
    p_sql_cnt := 'Select COUNT(column_name) from user_tab_columns where table_name='''||p_table_name||''' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sql_cnt, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_val,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_val);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --EXEC_SQL.CLOSE_CONNECTION;
    m_cnt := m_val;---column count
    ---get the column names from the user_Tab_columns and fetch the values from the given table for that column...
    For i in 1..m_cnt loop
         m_id := m_id+1;
    p_sqlstr := 'Select column_name from user_tab_columns where table_name='''||p_table_name||''' and column_id ='||m_id||' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sqlstr, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_name,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_col_name);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --fetch the column value from the given table
         p_org_sql := 'select DISTINCT '||m_col_name||' from '||p_table_name;
         cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_org_sql, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_val,240);
         nIgn := EXEC_SQL.EXECUTE(cursorID);
         Loop      
         nIgn := EXEC_SQL.FETCH_ROWS(cursorID);
              IF (nIgn > 0) THEN
                   EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, m_col_val);
    M_DATA_TAB.extend();
                   M_DATA_TAB(M_DATA_TAB.last).field_name := m_col_name;
                   M_DATA_TAB(M_DATA_TAB.last).FIELD_VALUE := m_col_val;
                   m_incr := m_incr+1;
                   -- text_io.put_line(m_file,m_col_name||'##'||m_col_val);
              else
                   exit;
              End if;
         End loop;--loop of records in the table for the given column
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    End loop; ---loop of columns in the table
    --text_io.fclose(m_file);
    message('Total no. of items in the object='||m_incr);
    EXEC_SQL.CLOSE_CONNECTION;
    EXCEPTION
    When EXEC_SQL.Invalid_Connection then
         message('invalid connection');
         when EXEC_SQL.Package_Error     then
         message('pkg err');
         when EXEC_SQL.Invalid_Column_Number          then
         message('invalid col num defined');
         when others then
              MESSAGE(SQLERRM);
    End;
    Regards
    Dora
    Edited by: Dora on Sep 27, 2009 3:13 PM

  • Finding a column name from all tables

    i have 85 tables in my user, i forget a column name and its table name. how to find that particular column amongst all tables i have.

    hi
    You can use User_tab_columns or All_tab_columns
    SQL>Select Table_Name,Column_Name From user_tab_columns
    where lower(table_name) like '%emp%' or
    lower(column_name) like '%dept%'
    Khurram Siddiqui
    [email protected]
    Message was edited by:
    pcbyte12

  • How to identify fields which are fast approaching the size limits

    Hi All,
    Is there an easy (or any) way of identifying Database fields whose field sizes are close to the limits.
    Example: I have field called SEQ_NUM, size of the field is 3 and currently latest value in the filed is 995, soon it will be a 1000.
    Thanks
    Raghu

    Hi, Raghu,
    Assuming your statistics are up to date, you can start with the information in the data dictionary view user_tab_columns (or all_tab_columns, or dba_tab_columns).
    The column high_value is a RAW representing the highest value. There's a conversion function in the supplied package utl_raw.
    The column data_precision is the maximum number of digits, and data_scale is the number of them to the right of the decimal point
    SELECT     table_name
    ,     column_name
    ,     utl_raw.cast_to_number (high_value)     AS actual_high
    ,     POWER (10, data_precision - data_scale)     AS possible_high
    FROM     user_tab_columns
    WHERE     data_type     = 'NUMBER'
    AND      ( utl_raw.cast_to_number (high_value)          -- actual_high
          / POWER (10, data_precision - data_scale)     -- possible_high
          ) > .95      -- or whatever
    ;I'm sure there are lots of special cases (large negative numbers, for example) that this will not catch.

  • Date columns

    Hi Gurus,
    I am working on Oracle 7.3.4 on Unix. I am having around 500 tables in my database and all of them are having different date formats i.e differnt column name as date format. I want to grab only the date column from the tables. Is ther any sql or pl/sql query through which I can only grab date column in the table.

    Look in user_tab_columns (or all_tab_columns) for the table names and column names where the type is a date.

  • Script or query to generate a report of null or not null columns

    I need a script/query it should pick up all the tables from user_tab_columns and produce a report for all the tables which are the columns are null and not null.

    As long as the columns were defined as NOT NULL on table create, or ALTERed NOT NULL, you can do this:
    SQL> CREATE TABLE t (id NUMBER NOT NULL, descr VARCHAR2(10));
    Table created.
    SQL> SELECT column_name, table_name, nullable
      2  FROM user_tab_columns
      3  WHERE table_name = 'T';
    COLUMN_NAME                    TABLE_NAME                     N
    ID                             T                              N
    DESCR                          T                              Y
    SQL> ALTER TABLE t modify (descr NOT NULL);
    Table altered.
    SQL> SELECT column_name, table_name, nullable
      2  FROM user_tab_columns
      3  WHERE table_name = 'T';
    COLUMN_NAME                    TABLE_NAME                     N
    ID                             T                              N
    DESCR                          T                              NNote that if you do:
    ALTER TABLE t ADD CONSTRAINT id_nn CHECK (id IS NOT NULL);then the nullable column in xxx_tab_columns will remain as Y.
    HTH
    John

  • How to fill a sparse table with zero

    Hi All
    I have a sparse table, most of the cells is null, but and few of the cells is "1"
    I would like to fill the null with zero.
    This table is from pivoting a transactional table into a table that will describe the attributes and later on for data mining
    I am thinking of
    1) do a user_tab_columns and copy and paste make a script that use NVL
    for e.g.
    select 'NVL('||column_name||',0,'||column_name||'),' from user_tab_columns
    where lower(table_name) = 'claims_t1'
    but I run into an issue
    e.g.
    create or replace view claims_t2x
    as
    select
    NVL('Diagnostic Imaging'_SPEC_SUM,0,'Diagnostic Imaging'_SPEC_SUM) 'Diagnostic Imaging'_SPEC_SUM
    from
    claims_t1
    I keep getting error of ORA-00911: invalid character
    as the column name got "'" in it.
    or
    2)Use PL/SQL
    I just do a select and loop through the whole thing
    For 2), I am not sure how I can get all the column attribute.
    As the attribute in the transaction table is not fix so the number of column after pivoting is not fix
    any idea?
    -Thanks so much for your input.
    Edited by: xwo0owx on Apr 27, 2011 11:08 AM

    >
    pivoting A transactional TABLE INTO A TABLE that will describe THE ATTRIBUTES AND later ON FOR DATA mining
    >
    You should have created all the columns with DEFAULT 0 NOT NULL;
    Why doing all this every time. Why not generate the table itself like that?
    what do you mean by a fill? you want to update them?
    then loop through and update like this,
    DECLARE
       p_tab_name   VARCHAR2 (100) := 'your_table_name';
       l_sql        VARCHAR2 (1000);
    BEGIN
       FOR i IN (SELECT *
                   FROM user_tab_columns
                  WHERE table_name = p_tab_name
                    AND datatype IN ('VARCHAR2', 'NUMBER', 'CHAR'))
       LOOP
          l_sql :=
                'update '
             || p_tab_name
             || ' set '
             || i.column_name
             || '=0 where '
             || i.column_name
             || ' is null';
          EXECUTE IMMEDIATE l_sql;
       END LOOP;
    END;G.

  • Another attempt to create "on the fly" condition in PL/SQL

    Here is the code:
    ---BEGIN ----
    declare
    my_var_list VARCHAR2(4000);
    cursor my_curr is select aa.column_name as my_col_name from user_tab_columns aa, user_tab_columns bb
    where aa.column_name = bb.column_name
    and aa.table_name = 'MY_SUBSET_TABLE' and bb.table_name = 'MY_SUPERSET_TABLE';
    begin
    for my_ind in my_curr loop
    my_var_list := my_var_list || my_i.my_col_name || ', ';
    end loop;
    insert into MY_SUPERSET_TABLE (my_var_list) select my_var_list from MY_SUBSET_TABLE;
    end;
    run;
    ---END---
    I plan to extract column name from user_tab_column, and concat it into a variable "my_var_list".
    The question now is, given the my_var_list contain column names (separate by comma), how can I use it in the select statement below?
    insert into MY_SUPERSET_TABLE (my_var_list) select my_var_list from MY_SUBSET_TABLE;
    Any idea on how to improve this script? I am running on Oracle9i ... using SQL Dev.
    Thanks much...

    It's a terrible idea, but it can be done. It could leave you open for sql injection hacks:
    declare
    my_sql VARCHAR2(4000);
    column_list varchar2(4000);
    v_iteration number := 0;
    begin
    for i in ( select column_name from user_tab_columns where table_name = 'T1') loop
    if v_iteration = 0 then
    column_list := i.column_name;
    else
    column_list := column_list||','||i.column_name;
    end if;
    v_iteration := v_iteration + 1;
    end loop;
    execute immediate 'insert into t2('||column_list||') select '||column_list||' from t1';
    end;
    /

Maybe you are looking for

  • How to implement Force password change during authentication

    Description of problem Our client requires web applications to support its internal security policy beyond normal authentication. This includes: - force password change periodically. This should be performed at logon time. - maintain password history

  • Can anyone save my PS and AI?

    Adobe CC updated my programs this morning and I haven't been able to open Photoshop or Illustrator since. They were working fine and now after the update... nothing. They just crash immediately upon opening. Running OS X Yosemite 10.10.2 Was on the p

  • Webserver access

    I know I've been through this before but for the life of me cannot remember how to remedy the situation. This time I'll definitely write it down and put it in a safe place if anyone can help. HD>Library>webserver>documents will not come up for me sin

  • I Forgot password Apple ID and can't to do anything.

    I wanna reset my password by email i try maybe 100 times . but i didn't get email from apple yet. can u sent link to reset password to ******** @hotmail.com please. <Email Edited by Host>

  • If I buy an iPhone 5 in the U.S. will it work in South Africa or not?

    I wanted to buy a iPhone in the U.S. and i wanted to know if it would work in South Africa? Another question is does Apple sell unlocked iPhones?