Querying all_tab_columns

Hi all,
This is a "my query takes too long" question but it relates to the ALL_TAB_COLUMNS view.
I'm trying to generate some basic DML scripts from a large number of tables (insert/update) the cheating way by selecting columns from all_tab_columns
e.g.
select 'insert into '||table_name||' ('
  from all_tables
where table_name = 'TABLE_NAME_HERE'
union all
select column_name||','
  from all_tab_columns
where table_name = 'TABLE_NAME_HERE'
--etc.however, I want the column names all on one line.
so I have the following, which I imagine should create the column_name's on one line but it "runs for ages"
select sys_connect_by_path(column_name,', ') c
  from all_tab_columns
where owner = 'WHITEHAT'
   and table_name = 'FOO'
   and connect_by_isleaf = 1
   start with column_id = 1
   connect by column_id = prior column_id + 1I am using 10gR2 so unfortunately I can't use recursive subquery factoring just yet, although that equivalent runs quickly as expected on our 11g environment:
with t (column_name, column_id)
             as (select cast(column_name as varchar2(4000)), column_id
                   from all_tab_columns
                  where owner = 'WHITEHAT'
                    and table_name = 'FOO'
                    and column_id = 1
                  UNION ALL
                  SELECT cast(t.column_name||', '||atc.column_name as varchar2(4000))
                        ,atc.column_id
                    from t
                        ,all_tab_columns atc
                   where owner = 'WHITEHAT'
                    and table_name = 'FOO'
                    and atc.column_id = t.column_id + 1
select column_name
  from (
         select column_name, column_id, max(column_id) over () max_col_id
         from t          
where column_id = max_col_idwhat am I doing wrong?

Hi,
WhiteHat wrote:
... so I have the following, which I imagine should create the column_name's on one line but it "runs for ages"
select sys_connect_by_path(column_name,', ') c
from all_tab_columns
where owner = 'WHITEHAT'
and table_name = 'FOO'
and connect_by_isleaf = 1
start with column_id = 1
connect by column_id = prior column_id + 1... what am I doing wrong?The WHERE clause is applied after the START WITH and CONNECT BY clauses are complete.
So you're starting with one row from every table. Let's say you have a small database, with 1000 tables. On LEVEL=1 you have 1000 rows. Then you're connecting every column with column_id=2 to each of those those 1000 rows. Almost every table will have a column with column_id=2, so you'll have 1,000,000 rows on LEVEL=2. I think you can see where this is going.
Don't use a WHERE clause to get the right table. Put the conditions you now have in the WHERE clause (or equivalent conditions, except for "connect_by_isleaf = 1") in the START WITH and CONNECT BY clauses, instead, or apply the WHERE clause in a sub-query, first, like this:
WITH     universe     AS
     SELECT     column_name
     ,     column_id
     FROM     all_tab_columns
     WHERE     owner          = 'WHITEHAT'
     AND     table_name     = 'FOO'
SELECT     SYS_CONNECT_BY_PATH (column_name, ',')     AS c
FROM     universe
WHERE     CONNECT_BY_ISLEAF     = 1
START WITH     column_id     = 1
CONNECT BY     column_id     = 1 + PRIOR column_id
;

Similar Messages

  • Getting all_tab_columns.data_default in a ddl trigger

    Under 10.1.0.3 I'm working on an AFTER CREATE or ALTER on DATABASE system trigger, and I'm querying all_tab_columns in the trigger body. It seems that if the trigger fires in response to DDL that modifies a column's default value, then all_tab_columns.data_default is giving me the column's old default. I want to get the current default value. If I create the table or add a column, then, in the resulting fire of the system trigger, all_tab_columns.data_default seems to be correct.
    Is this documented behavior? Should I be looking somewhere (or somewhen) else for the column default?

    Thanks.
    I tried working around this by putting my code into a procedure, and then using the DDL trigger to create a job that runs the code. My idea was to defer the all_tab_columns query until after the DDL trigger was done, and thus get a clean look at the data dictionary.
    I put what looks like the appropriate dbms_scheduler calls into the trigger, but when I then execute DDL to fire the trigger I get "ORA-04092: cannot in a trigger"
    The doc for this error number says that I am trying to commit or rollback in a trigger, but I'm not explicitly doing that. Also, the error message is supposed to have either the word "commit" or the word "rollback" in the message to tell me what I am doing. Instead, though, the error message just has a space there.
    Maybe I'll start a TAR and see if 10.1.0.3 can get appended to the growing list of versions tied to this bug.

  • All_tab_columns says NULLABLE = 'Y' while there is a NOT NULL constraint

    Hi all,
    I created a table MANT (here is the script) :
    CREATE TABLE DMI.MANT
      MANT     NUMBER(7)                            NOT NULL,
      SPER     NUMBER(7)                            NOT NULL,
      RANT     VARCHAR2(10 BYTE)                    NOT NULL,
      ANT      VARCHAR2(200 BYTE),
      CMT      VARCHAR2(800 BYTE),
      PERIODE  VARCHAR2(200 BYTE),
      DU       DATE,
      USR      VARCHAR2(10 BYTE),
      DTE      DATE
    )Then I added a column called RSMF :
    ALTER TABLE DMI.MANT
    ADD (RSMF VARCHAR2(100 BYTE));and added a check constraint :
    ALTER TABLE DMI.MANT ADD
    CONSTRAINT RSMF_NOT_NULL
    CHECK (RSMF IS NOT NULL)
    ENABLE
    NOVALIDATEI had to add NOVALIDATE clause because all the records had a null value. So to validate the constraint I simply executed the following update
    update dmi.mant set rsmf = 'yy';and then validate the contraint with :
    ALTER TABLE DMI.MANT
    MODIFY CONSTRAINT RSMF_NOT_NULL
    VALIDATE;The problem comes when I query ALL_TAB_COLUMNS table...
    Select OWNER,TABLE_NAME,COLUMN_NAME,DATA_TYPE,DATA_LENGTH,NULLABLE
    from all_tab_columns
    where table_name = 'MANT'
       and owner = 'DMI'
       and COLUMN_NAME = 'RSMF';Why does the ALL_TAB_COLUMNS table gives for RSMF column a NULLABLE value equals to 'Y' while there is a validated check NOT NULL constraint on it ?
    It's annoying because I want to get all the NOT NULL columns in a given table and here the SRMF column is not returned...
    Here is the result :
    OWNER  |TABLE_NAME |COLUMN_NAME  |DATA_TYPE  |DATA_LENGTH  |NULLABLE
    DMI    |MANT       |RSMF         |VARCHAR2   |100          |YThks for your replies...

    NULLABLE would be true if you created the table like this:
    create table x (a not null)
    but not if you add a check constraint after the fact.

  • How to dynamically get default value from a table column

    Hi all,
    Here's my problem: Our front end application sends insert and update queries to a pl/sql package. I've got a procedure that gets a PL/SQL table with all the column names an values, a table-name and a primary key name and value. That procedure creates an insert or update statement. So far, so good.
    Now the problem: our front end doesn't know what the default value for a column is. So when a number field doesn't get a value in the front-end, it's inserted with a value '0' though is should ben NULL. My sollution for this is to know the default value of a column: when there's a default of '0', then the value that will be inserted is '0'. When there's no default value and the column can ben NULL, it'll be inserted as NULL. if the column has a not null constraint, a '0' will be inserted.
    Ofcourse I can get the default value from the system-views all_tab_columns or user_tab_columns, but our application is installed at some 100 clients, and has various database installations. Most of the times, the tables are in the same schema as our procedure that performs the insert or update, but sometimes some of the tables are in another schema (in the same database) and also sometimes some tables are stored in another database. In all these situations, a synonym for that table exists in the schema.
    Is there a api function or procedure that I can call to get the default value of a column? I looked at dbms_sql and dbms_metadata, but those packages don't give me that perticular information. if not, I'll stuck with the 'does table exists in schema' yes->use table, no query user_synonyms to look for the owner of the table (and database link) and query all_tab_columns to get the default value. Only this seems a bit overkill to me.
    I hope I'm clear enough? And please don't reply with "don't do inserts this way"! I know, this is not the most optimal sollution, but it does gives us a couple of advantages in our application...

    there is no way that I can think of, apart from what you have already discovered (i.e. views), where you can determine if a column has a defuault value defined against it.
    The other option is triggers, but I guess doing that across 600 tables would not be an option, and besides I stay clear of triggers.
    A different approach therefore, if you cannot pre-determine the data, is to consider a post problem handler, hence I suggested the use of an exception handler.
    The exception handler works regardless of whether the statement is dynamic or not.
    SQL> truncate table abc;
    Table truncated.
    SQL>
    SQL> declare
      2    NULLVAL exception;
      3    pragma exception_init(NULLVAL, -01400);
      4 
      5  begin
      6 
      7    begin
      8 
      9      execute immediate 'insert into abc (y) values (1)';
    10 
    11      exception
    12        when NULLVAL then
    13          -- handle the error
    14          execute immediate 'insert into abc (x,y) values (0,1)';
    15 
    16    end;
    17 
    18    commit;
    19   
    20  end;
    21  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from abc;
             X          Y
             0          1

  • Bug in ALL_TABL_COLUMNS ?

    It seems like ALL_TAB_COLUMNS doesn't tell column data types properly... (Oracle 9i Lite 502)
    I create ANY table that have a DATE column. Ok.
    Create table LEO (id number, my_date date);
    When I query ALL_TAB_COLUMNS, the column "my_date" from table "LEO" is datatype "TIMESTAMP".
    BUT... if I desc this table, the data type is shown correctly. Since I need this information in a client program, I'm getting the wrong information.
    Can anyone confirm if this is really a bug, or I'm misunderstanding something... Is there a more accurate way to retrieve tables structure in response to a query?
    Thanks!
    LZ

    Thank you for the correction.
    Been a while since i did a proper install of Reader. Mostly just do silent push install on our clients.
    Still don't think it is correct of the bug/update to create a desktop shortcut though...
    If someone want the desktop shortcut, they most likely will have it on the desktop allready, and those who doesn't have it on the desktop, are those who have removed it, and thus most likely doesn't want it back.
    So not adding the desktop shortcut would actually shrink the size of the update. Not by much, but that is irrelevant.
    It's a useless thing, that doesn't need to be there.

  • Need help on DATA_REMAP procedure.

    Hi All,
    I am using data pump APIs to perform export and import. But “data_remap” procedure is throwing exceptions.
    SQL*Plus: Release 11.1.0.7.0 - Production on Wed Apr 10 04:29:09 2013
    Copyright (c) 1982, 2008, Oracle.  All rights reserved.+
    Connected to:+
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production+
    We have a set of tables, whose data needs to be exported. We have following constraints to perform export:
    1) Only the tables that contains a column (lets say test_id) needs to be exported. We are fetching these tables by querying "all_tab_columns" view as {select table_name from all_tab_columns where column_name = 'test_id' and owner = user} This query fetches around 40 tables.
    2) From this set of tables we need only the data which satisfy the condition {select * from <tablename> where test_id = 10}.
    3) Now we need to replace test_id value 10 with -1.
    Create or replace package body TESTPACKAGE as
    function SetTestID(p_TestId number) return number is
    v_TestId number := -1;
    begin
    return v_TestId;
    end;
    procedure exportData is
    h1 number; -- Data Pump job handle
    begin
    h1 := dbms_datapump.open('EXPORT',
    'TABLE',
    null,
    'EXAMPLE1',
    'LATEST');
    dbms_datapump.add_file(h1,
    'example1.dmp',
    'EXPORT');
    dbms_datapump.metadata_filter(handle => h1,
    name => 'NAME_EXPR',
    value => 'IN (select TABLE_NAME from ALL_TAB_COLUMNS A where A.COLUMN_NAME = TEST_ID'' and owner = user and not (A.TABLE_NAME like ''PV%'') and not (A.TABLE_NAME like ''IV%'') and not (A.TABLE_NAME like ''IMV%'') and not (A.TABLE_NAME like ''BIN$%''))',
    object_type => 'TABLE');
    dbms_datapump.data_filter(handle => h1,
    name => 'SUBQUERY',
    value => 'WHERE TEST_ID = 10',
    table_name => null,
    schema_name => null);
    dbms_datapump.data_remap(handle => h1,
    name => 'COLUMN_FUNCTION',
    table_name => 'TABLE1',
    column => 'TEST_ID',
    function => 'TESTPACKAGE.SETTESTID(10)',
    schema => 'ATOM606');
    dbms_datapump.start_job(h1);
    end;
    end;
    But here data_remap procedure is giving below error
    +"ORA-39232: invalid remap function: TESTPACKAGE.SETTESTID(10)"+
    Can anyone help how to use this data_remap procedure and how to pass the value to the function parameter? And also how to specify the whole table list?
    Any help is highly appreciated.Thanks in advance :)

    I think there is some limit on the length of this parameter. It was not accepting the whole string <SchemaName>.<TableName>.Test_Id.
    So i tried with
    dbms_datapump.data_remap(handle => h1,
    name => 'COLUMN_FUNCTION',
    table_name => 'TABLE1',
    column => 'TABLE1.TEST_ID',
    function => 'ATOM606.TESTPACKAGE.SETTESTID',
    schema => 'ATOM606');
    But it doesn't make any difference, still getting the same error.
    I also tried by passing the column name as input argument to the SETTESTID function, hoping for some miracle, but even that doesn't make any difference.

  • Undefined Data type

    When describe a view, datatype of few column shown as UNDEFINED and rest of columns are ok.
    Also, on querying ALL_TAB_COLUMNS, Data_type is UNDEFINED and Data_length is 0. But we are able to query that view and it is showing correct data.
    Please help.
    Thanks in advance
    Regards,
    Sundeep
    Edited by: 995336 on Mar 22, 2013 9:00 AM

    Hi,
    Thanks for replying and looking into the issue. Please find details required.
    1.Database : Oracle 10g release 10.2
    2.Java ver. : 1.6.0_41
    3. Dont know how to check
    4. Query : DESC schema.view_name;
    Output :
    Name Type Nullable Default Comments
    XXXXX1      VARCHAR2(360)
    XXXXX2      VARCHAR2(15)
    XXXXX3      UNDEFINED Y
    XXXXX4 UNDEFINED Y
    XXXXX5 UNDEFINED Y
    XXXXX6 UNDEFINED     Y
    XXXXX7 UNDEFINED Y
    XXXXX8 UNDEFINED Y
    XXXXX9 UNDEFINED Y
    XXXXX10 UNDEFINED Y
    XXXXX11 UNDEFINED Y
    XXXXX12 UNDEFINED Y
    XXXXX13 UNDEFINED Y
    XXXXX14 UNDEFINED Y
    XXXXX15 UNDEFINED Y
    XXXXX16          UNDEFINED Y
    5. Query : SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = view_name;
    Output :
    COLUMN_NAME     DATA_TYPE     DATA_LENGTH
    XXXX1     VARCHAR2     360
    XXXX2     VARCHAR2     15
    XXXX3     UNDEFINED     0
    XXXX4     UNDEFINED     0
    XXXX5     UNDEFINED     0
    XXXX6     UNDEFINED     0
    XXXX7     UNDEFINED     0
    XXXX8     UNDEFINED     0
    XXXX9     UNDEFINED     0
    XXXX10     UNDEFINED     0
    XXXX11     UNDEFINED     0
    XXXX12     UNDEFINED     0
    XXXX13     UNDEFINED     0
    XXXX14     UNDEFINED     0
    XXXX15     UNDEFINED     0
    XXXX16     UNDEFINED     0
    6. SELECT * FROM schema.view_name;
    7. Not able to query.
    Status of View is valid when query in all_objects.
    Due to security reasons schema,view name and column names are replaced.
    Hope these details will help.

  • Use dataguard with applications built with  APEX

    Hi all,
    I have questions about APEX with Dataguard. Can I develop an application with APEX and then use Dataguard? Can the application switch to Standby Database automatically when there is a failover event?
    If it is possible, Can you explain me?
    Thank in advance
    Vincenzo

    APEX should work fine in a Physical Standby as it's an exact copy of your database. Logical Standby should work too, but you need to make sure the FLOWS_ schemas are being replicated and there is no transformation done to them. Also not sure if there are any datatypes in APEX that would not work in a Logical Standby, but you should be able to look those up in the Data Guard Docs then query all_tab_columns where table_owner like 'FLOWS_%' to verify. Physical Standby would be a safer bet.
    You want to make sure you install your HTTP server on a different server so it doesn't go down with your database in the event the OS shuts down. Then in the TNS entry for your database you can add [url ="http://download.oracle.com/docs/cd/B19306_01/network.102/b14213/tnsnames.htm#sthref676"]failover=on and the additional IP address(es). This will automatically failover when your primary database is no longer accessible. Personally I would have a second HTTP Server installed at your backup site and handle the failover at the network level. If a sprinkler head pops or your air conditioner fails at your primary site, everything is going to stop there. You can easily have 2 HTTP servers accessing the same APEX install (on one database) at the same time, so it's easy to test / verify the state of the 2nd http server. You'll probably want to mirror the /i/ directory and any image directories you have for your applications from your primary site to your failover.
    "Automatically"? Yes, all of this can be configured to happen automatically, but most people (Tom Kyte included) recommend that you only failover manually as it's best to investigate the underlying issues with your primary site before failing over. You should be able to tell within the first 5 minutes whether the problem was a simple network outage or unintentional OS reboot, or a more serious problem such as a corrupt block, Air Conditioning failure, hardware issues, etc. Keep in mind to do automatic failover you need a 3rd site as an observer of your 2 sites to decide which site is "still alive".
    Varad, I believe TAF is only a RAC concept, not Data Guard. Furthermore, I'm pretty sure that TAF is not built into APEX. So, in an APEX / RAC installation, if you're running a page that takes say 4 seconds (long running report) and 2 seconds in the database node on which you are running fails, the end user is likely going to see a "404 not found" or some other error, then when they refresh the page it will hit another RAC note and return the results. I'm pretty sure the TAF logic is not built into APEX or mod_plsql to migrate the database session to a new surviving node when it detects a failure. Again, I could be wrong, but I'm pretty sure I'm not in this particular case (someone please prove me wrong).
    Thanks,
    Tyler

  • Query from all_tab_columns

    I'm looking for a query from ALL_TAB_COLUMNS which should give me all table names containing both the columns below:
    'TIME_PERD_ID' and 'CTRL_PERD'
    Help?
    Thanks,
    Bhagat

    You can try the below:
    [email protected]> create table t1(c1 int, TIME_PERD_ID int, CTRL_PERD int);
    Table created.
    [email protected]> create table t2(c2 int, TIME_PERD_ID int, CTRL_PERD int);
    Table created.
    [email protected]> create table t3(c2 int, TIME_PERD_ID int);
    Table created.
    [email protected]> select a1.table_name
    2 from all_tab_columns a1, all_tab_columns a2
    3 where a1.table_name = a2.table_name and a1.column_name = 'TIME_PERD_ID'
    4 and a2.column_name = 'CTRL_PERD'
    5 /
    TABLE_NAME
    T1
    T2
    Best regards
    Krystian Zieja / mob

  • QUERY HELP!!! trying to create a query

    i'm creating a summary report
    i have a table with sale dates
    for example i have a table tab_1 and column saleDate as
    saleDat
    1923
    1936
    1945
    2003
    2005
    saleDate contains years and there are some missing years where no sale
    was made
    My report has to display years starting from earliest year
    so i have to create a query that starts with 1923
    but the problem is that I have to have years that are not in table.
    for example i have to display years 1924 which is not in table
    so the part of report has to look like
    1923 blah blah summary.........
    1924 "
    1925
    1926
    2005
    2006
    upto current year (2006 may not be in the table, but i have to display)
    i just need to know the query that can query all the years starting from
    the ealiest saleDate to current year
    thanks in advance

    Please write the query in the following form:
    SELECT a.year, --- place other columns from your table.
    FROM (SELECT (:start_num + rownum) year
    FROM all_tab_columns
    WHERE :start_num + rownum <= :end_num) a,
    tab_1 b
    WHERE a.year = b.saleDat(+);
    Note:
    1) if your start year and end year are 1923 and 2006. Then input as below:
    :start_num = 1922
    :end_num = 2006
    2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
    3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
    Hope this helps.
    - Saumen.

  • 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

  • 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

  • Query to list tables with a particular column name in a schema!!

    Is there any way to know?
    Thanks in advance.

    You can query the data dictionary views to get this information.
    For example
    untested
    select table_name
    from user_tab_columns
    where column_name = 'my particular column name';There is also all_tab_columns and dba_tab_columns. Both of which would include the schema name.
    Edited by: Sven W. on Sep 9, 2011 2:24 PM

Maybe you are looking for

  • Mview Fast Refresh Problem

    Hello, We run a fast refresh for a particular mview. I have the mview log created on the primary db (base table) and the mview created on another reporting database. The fast refresh seems to be fine throughout the day but at the end of a day it fail

  • Error when starting JAVA when installing ECC6

    hi Did anyone faced this problem.Iam installing EEC6 and when its running job 39 of 48 it comes up with this error: ERROR 2007-10-04 17:13:21 CJS-30150  Java processes of instance VT2/DVEBMGS00 [ABAP: ACTIVE, Java: UNKNOWN ] did not reach state PARTR

  • Download Adobe Photoshop Elements 11 for new purchase computer, old computer no longer used

    Purchased Adobe Photoshop Elements 11, I have serial number.  Having problems finding location on site to download.

  • Problem in opening Video Camera

    I'm using Sony Xperia Z1.. When start my video camera in my mobile, it shows an error message: "ERROR! Camera not available". Can any1 of u sugget me how to rectify this prob?

  • CATS activity connections

    Hi, We are using CATS for our registration of the working hours. The problem is that we need to connect the employeeu2019s with their activities at forehand. But there are people with no standard activities, in the morning they get a schedule for tha