Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65

    Question Unanswered: How can I know if a field exists in a table ?

    I want to create a new field in a table but I want to test if the field already exists.
    How can I do that in an SQL query ?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Look in ALL_TAB_COLUMNS or USER_TAB_COLUMNS.

  3. #3
    Join Date
    Jan 2004
    Location
    Cergy
    Posts
    65
    and in a full PL/SQL procedu

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Quote Originally Posted by nanou9999
    and in a full PL/SQL procedu
    Is that a follow-up question? I don't understand it.

  5. #5
    Join Date
    Apr 2003
    Location
    NY
    Posts
    208

    user_source

    If you want to search your database for the existence of a string (ie a column_name) you can query the User_Source or All_Source data dictionary views

    Code:
    select *
    from all_source -- or user_source 
    where upper(text) like '%TABLE.COLUMN_NAME%'

  6. #6
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    He first say *in an SQL query* then later ask for *in a full PL/SQL procedu*, I dont know what to think.. did you mean a procedure that use an sql query to determine wether or not a given column exists in a table ?

  7. #7
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Maybe he wanted Tony to write a query for him; I mean, what kind of an answer was this in post #2? "Look in" ... it isn't that easy; requires a little bit of typing abilities along with clear visibility between the eyes and the screen, energy comparable with feeding your mouth with 7 soup spoons, dragon's breath, bat's nail and snail's scent. And - voila! The query is ready to use!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •