Finding same column name from multiple database tables

I am needing to find all tables in a database that contain the same column. ie: which tables in database A have col_a in it.
Is it possible to do a sql code to qry all of this?
Thanks

No, Ignacio did not, at least, not really. ;)
The usage of ALL_TAB_COLUMNS only has info for tables which the actual user has access to.
If you need to be sure that you search each and every table, you have to use DBA_TAB_COLUMNS (or the connected user must be a super hero...).
Just wanted to point that out.
Regards,
Guido

Similar Messages

  • How to Select data using same column name from 3 remote database

    Hi,
    Can anyone help me on how to get data with same column names from 3 remote database and a single alias.
    Ex.
    SELECT *
    a.name, b.status, SUM(b.qty) qantity, MAX(b.date) date_as_of
    FROM
    *((table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3)a,*
    *(table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3)b)*
    WHERE b.dept = 'finance'
    AND a.position = 'admin'
    AND a.latest = 'Y' AND (b.status <> 'TRM') AND b.qty > 0;
    GROUP BY a.name, b.status ;
    NOTE: the bold statements is just an example of what I want to do but I always gets an error beacause of ambiguous columns.
    Thanks in advnce. :)
    Edited by: user12994685 on Jan 4, 2011 9:42 PM

    user12994685 wrote:
    Can anyone help me on how to get data with same column names from 3 remote database and a single alias.Invalid. This does not make sense and breaks all scope resolution rules. And whether this is in a single database, or uses tables across databases, is irrelevant.
    Each object must be uniquely identified. So you cannot do this:
    select * from (table1@remotedatabase1, table1@remotedatabase2, table1@remotedatabase3) a3 objects cannot share the same alias. Example:
    SQL> select * from (dual, dual) d;
    select * from (dual, dual) d
    ERROR at line 1:
    ORA-00907: missing right parenthesisYou need to combine the objects - using a join or union or similar. So it will need to be done as follows:
    SQL> select * from (select * from dual d1, dual d2) d;
    select * from (select * from dual d1, dual d2) d
    ERROR at line 1:
    ORA-00918: column ambiguously definedHowever, we need to have unique column names in a SQL projection - so the join of the tables need to project a unique set of columns. Thus:
    SQL> select * from (select d1.dummy as dummy1, d2.dummy as dummy2 from dual d1, dual d2) d;
    DUM DUM
    X   X
    SQL> I suggest that you look closely at what scope is and how it applies in the SQL language - and ignore whether the objects referenced are local or remote as it has no impact to fundamentals of scope resolution.

  • How to display Column Names of a Database Table in JSP

    Dear All,
    I want to display all the attribute names(column names) of a database table on JSP.
    [ ex:  mytable contains : ( EmpId,EmpName,Dept ). This should be display as  EmpId--text box                    
    EmpName--text box
    Dept----textbox
    please note , i don't want to display values,but only column names

    Yeah make use of methods like
    ResultSet DatabaseMetaData.getColumns(String catalog, String schemaPattern, String tableName, String columnNamePattern)
    else use
    String ResultMetaData.getColumnName(int column_index)
    search google i'm sure u wud get thousands of example on it... :)

  • To fetch Data from multiple database tables!

    How to fetch Data from fields of multiple database tables!
    Give me one example!

    use <b>join....</b>
    c the SAPHELP docs...
    FROM tabref1 [INNER] JOIN tabref2 ON cond
    Effect
    The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
    In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
    Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Inner Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID AND
                  FCONNID = PCONNID
        WHERE P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.

  • Query the column names from Public database links

    Greetings,
    I would like to retrieve the list of all the column names from a public database link. A regular ALL_TAB_COLUMNS doesn't seem to be working.
    Thanks
    John9569

    Hi,
    I think your DBA needed to create a synonym for you to have access of that remote database view.
    CREATE SYNONYM synonym_name
    FOR view_name@db_link;Then you can find the column names by
    DESC   synonym_nameGuru's , please correct me If I am wrong.
    Thanks
    Edited by: user10679113 on Mar 12, 2009 12:28 PM
    Edited by: user10679113 on Mar 12, 2009 12:33 PM

  • Same column name from different table

    i have a sql query as like this : "SELECT * FROM TABLE1,TABLE2". i use oracle. both TABLE1 and TABLE2 have the same column named 'COLUMN1'. while i get rows how i know the value of COLUMN1 from which table (TABLE1 or TABLE2).
    sample code snippet is above. do u help me!
    while (rs.next())
    value1 = rs.getString("COLUMN1");
    // is value1's value from table1 or table2. how do i know this?
    // i try value1 = rs.getString("TABLE1.COLUMN1"); but it doesn't work :(
    ....

    I case you don't know what an alias is, it would look something like this:
    SELECT a.COLUMN1 as FirstColumn1, b.COLUMN1 as SecondColumn1 FROM FirstTable a, SecondTable b
    Notice that in the FROM clause we've appended a short name for each table. You're not limited to one character, but I try to keep it simple. Now we can refer to the tables as a and b.
    Because I did that I have to refer to any ambiguous columns (although it's good practice to refer to ALL columns) using the table name prefix and a period. This tells the driver which "COLUMN1" I want. Then we include as AS clause which allows us to tell the driver what we want that column name to be when it's returned to us. This is specially usefule when I have two columns in two separate tables with the same name (as you have here) or if I'm calculating data (i.e. (a.QTY * b.PRICE) as UnitPrice) that doesn't have a column name, so here I can give it one.
    It's a little weird at first since you use the alias names in the select before you actually define them in the FROM clause, but you'll get use to it.
    Now you retrieve FirstColumn1 and SecondColumn1 from your ResultSet, not Column1.
    HTH.

  • 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 find same field name from all tables?

    Dear All,
    I want to find those tables that contain a field name, say COMPANY_CODE, from all user tables. How can I do that by writing SQL?
    Many thanks,
    Andrew

    SELECT table_name
      FROM user_tab_columns
    WHERE column_name = 'COMPANY_CODE'Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Sql Problems, Same Field Names In Multiple Mysql Tables?

    I have a keyword search that searches multiple DB tables for thumbnail images using UNION ALL. I have two pages, results.php, and view.php.  My goal is to able to click a thumbnail image on results.php and be directed to a larger version of that same image on view.php. The problem is each image in all my tables uses the field name "id" so when I click a thumbnail on results.php I get two different images with the same id from different tables.  I tried changing the id's to different names, but when it was time to pass url parameters I can only choose 1 value. (if you can choose more than 1 I don't know how).  So my question is why are my id's from different tables being grouped together, and how can I change this?
    Image Results Page (which works perfect):
    SELECT *
    FROM table1
    WHERE keyword LIKE %colname% OR id  LIKE %colname% 
    UNION ALL
    SELECT *
    FROM table2
    WHERE keyword LIKE %colname% OR id  LIKE %colname% 
    View Image Page (having problems here):
    SELECT *
    FROM table1
    WHERE id = colname
    UNION ALL
    FROM table2
    WHERE id = colname

    Yes, that is going to be a problem - and it's just the beginning of your problems when you do not normalize your data. Your data model is not correct. You should not be storing similar data in 15 tables - it's a really big mistake.
    To solve your current problem you would need to include a table identifier in the query results in the Image results page, and pass that to the view page and then use PHP to dynamically create the SQL with the correct table....ugh!

  • 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

  • Finding the column names from a table.

    I am on 10g
    I would like to find out the columns of a table where there are null columns in a table.....this table contains about 300 + columns where i do not want to put where condition for all the columns
    is there a way i can write a sql to find?
    for a given table or the results set that i need to get, i will have same results for all the rows, so it
    cant be like col1 is null on row1, but col2 is not null on row2 ...they are all identical....
    example table, but it has 300 + cols
    F_IND     H_IND     P_IND     DMA_IND
    N     N          
    N     N          
    N     N          
    N     N          Thanks

    select count(col1), count(col2), count(col3), ...
    from your table;
    The results with 0s are null throughout the table (or the table has no rows).

  • How to find out Column names from JDBC?

    Hello,
    How to get Oracle's Table Meta Data without firing a "SELECT" statement and using ResultSet meta data ?
    Thanks,
    -raj

    This works for most jdbc drivers:
    Connection con = ???;
    DatabaseMetaData dbmd = con.getMetaData();
    ResultSet rs = dbmd.getColumns( null, null, "TABLENAME", null );Read the API: http://java.sun.com/j2se/1.4.1/docs/api/java/sql/DatabaseMetaData.html#getColumns(java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String)

  • How To Create Table View With Same Column name But Different Table?

    Hi All,
    I have the problem to create a tableview with same column name but in different table.
    The Table that i have:-
    Table - PAC051MPROFORMA
    Column - mrn,visitid
    Table - PAC051TPROFORMA
    Column - mrn,visitid
    Table - PAC052MTRANSBILL
    Column - mrn,visitid
    Then i want to create a table view to view that table. This is my SQL
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
    As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
    where
    *(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
    and
    *(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
    That SQL Return this error = ORA-00957: duplicate column name
    Then I modify that SQL to
    CREATE VIEW pacviewproforma (mrn,visitid)
    As Select PAC051MPROFORMA.mrn,PAC051MPROFORMA.visitid,PAC051TPROFORMA.mrn,PAC051TPROFORMA.visitid,PAC052MTRANSBILL.mrn,PAC052MTRANSBILL.visitid
    where
    *(a.PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)*
    and
    *(a.PAC051TPROFORMA.mrn=PAC052TRANSBILL.mrn)*
    This time this error return = ORA-01730: invalid number of column names specified
    What should i do?
    Thanks...

    Hi,
    SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
    10  where
    11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
    12  and
    13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
    ERROR at line 1:
    ORA-00957: duplicate column namePlease give different names to each column.
    Something like this..
    SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
    _visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
    10  where
    11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
    12  and
    13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    View created.
    SQL> DESC  pacviewproforma;
    Name                                      Null?    Type
    MPROFORMA_MRN                                      NUMBER
    MPROFORMA_VISITID                                  NUMBER
    TPROFORMA_MRN                                      NUMBER
    TPROFORMA_VISITID                                  NUMBER
    MTRANSBILL_MRN                                     NUMBER
    MTRANSBILL_VISITID                                 NUMBER
    ORA-01730: invalid number of column names specifiedThe list of column nmae you specified during the CREATE VIEW should match with the SELECT list of the view.
    Twinkle

  • Getting column names for a particular Table from Connection object.

    Hi,
    Can any one suggests me a way to get column names from a particular table of a database from the java.sql.Connection object. ?
    Thanks in advance.

    Connection connection;
    DatabaseMetaData metadata = connection.getMetaData();
      String[] names = {"TABLE"};
      ResultSet tables = metadata.getTables(null,"%", "%", names);
      while (tables.next()) {
      String tableName = tables.getString("TABLE_NAME");
       ResultSet columns = metadata.getColumns(null, "%", tableName, "%");
    while (columns.next()) {
      String columnName = columns.getString("COLUMN_NAME");
        }

  • Deleting from multiple tables where few tables have same column name

    Hi,
    I am new to PL/SQL and need some help. I need to delete data older then X years from some 35 odd tables in my schema and out of those tables 25 tables have same column name on which i can have my "where" clause and rest 10 table have different table names. I am doing something like this :
    declare
    table_list UTL_FILE.FILE_TYPE;
    string_line VARCHAR2(1000);
    tables_count number:=0;
    table_name VARCHAR2(400);
    column_name VARCHAR2(400);
    BEGIN
    table_list := UTL_FILE.FOPEN('ORALOAD','test7.txt','R');
    DBMS_OUTPUT.PUT_LINE(table_list);
    LOOP
    UTL_FILE.GET_LINE(table_list,string_line);
    table_name := substr(string_line,1, instr(string_line,'|')-1);
    column_name := substr(string_line, instr(string_line,'|')+1);
    DBMS_OUTPUT.PUT_LINE(table_name);
    DBMS_OUTPUT.PUT_LINE(column_name);
    IF column_name = 'SUBMISSION_TIME' THEN
    delete from :table_name where to_date(:column_name)<(sysdate-(365*7));
    ELSE
    delete from || table_name || where ( || to_date(column_name) || ) <(sysdate-(365*7));
    END IF;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    UTL_FILE.FCLOSE(table_list);
    DBMS_OUTPUT.PUT_LINE('Number of Tables processed is : ' || tables_count);
    UTL_FILE.FCLOSE(table_list);
    END;
    WHERE the text file "text7.txt" contains list of table name and column names separated by a pipe line. But when I execute the above proc it gives error "invalid table name".
    Can something like this be done or is there any other way to execute this task of deletion from 35 tables.
    Thanks.

    Thanks for replies. I don't know what I am doing wrong but still not getting this damn thing work...This is the proc i am running now :
    declare
    table_list UTL_FILE.FILE_TYPE;
    string_line VARCHAR2(1000);
    tables_count number:=0;
    table_name VARCHAR2(4000);
    column_name VARCHAR2(4000);
    code_text VARCHAR2(2000);
    BEGIN
    table_list := UTL_FILE.FOPEN('ORALOAD','test7.txt','R');
    LOOP
    UTL_FILE.GET_LINE(table_list,string_line);
    table_name := substr(string_line,1, instr(string_line,'|')-1);
    column_name := substr(string_line, instr(string_line,'|')+1);
    IF column_name = 'SUBMISSION_TIME' THEN
    DBMS_OUTPUT.PUT_LINE('do nothing');
    ELSE
    code_text:= 'begin delete from'|| (table_name) ||'where to_date' || (column_name) || '<(sysdate-(365*7))';
    Execute Immediate code_text;
    END IF;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    UTL_FILE.FCLOSE(table_list);
    DBMS_OUTPUT.PUT_LINE('Number of Tables processed is : ' || tables_count);
    UTL_FILE.FCLOSE(table_list);
    END;
    But it gives following error :
    " ORA-06550: line 1, column 51:
    PL/SQL: ORA-00933: SQL command not properly ended
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 1, column 68:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
    ORA-06512: at line 22 "

Maybe you are looking for